home / skills / plurigrid / asi / nix-acset-worlding

nix-acset-worlding skill

/skills/nix-acset-worlding

This skill analyzes Nix store topology as an attributed C-Set to verify dependencies, manage worlds, and visualize GC with Gay.jl coloring.

npx playbooks add skill plurigrid/asi --skill nix-acset-worlding

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.4 KB
---
name: nix-acset-worlding
description: Model Nix store as Attributed C-Set for dependency verification, GC analysis,
  and Flox world management with Gay.jl coloring.
metadata:
  trit: 0
  short-description: Nix store as ACSet
---

# Nix ACSet Worlding Skill

> **Trit**: -1 (MINUS) - Constraint verification of Nix store semantics

Model Nix store as Attributed C-Set for dependency verification and world management.

## Schema

```julia
@present SchNixStore(FreeSchema) begin
    (Path, Hash, Name, Type, World)::Ob
    
    path_hash::Hom(Path, Hash)
    path_name::Hom(Path, Name)  
    path_type::Hom(Path, Type)
    depends_on::Hom(Path, Path)
    belongs_to::Hom(Path, World)
    
    hash_value::Attr(Hash, String)      # 32-char base32
    name_value::Attr(Name, String)
    type_value::Attr(Type, Symbol)      # :drv, :out, :source, :patch
    world_name::Attr(World, String)
    size_bytes::Attr(Path, Int)
    is_dead::Attr(Path, Bool)
end
```

## Core Operations

### 1. GC Root Analysis

```julia
function live_roots(store::NixStoreACSet)
    filter(p -> !store[:is_dead][p], parts(store, :Path))
end

function dead_paths(store::NixStoreACSet)
    filter(p -> store[:is_dead][p], parts(store, :Path))
end
```

### 2. World Management

Flox environments as categorical worlds:
```
World := {name, dev_env, run_env, manifest}
```

Live worlds (2024-12-24):
- `music-topos` - Audio/visual synthesis
- `stellogen` - Stellar generators
- `bevy_fullscreen_app` - Rust game engine
- `cubical-agda` - HoTT proof assistant

### 3. Dependency Sheaf

Dependencies form a sheaf over the store graph:
```julia
function dependency_sheaf(store::NixStoreACSet)
    # Check transitive closure consistency
    for p in parts(store, :Path)
        deps = store[:depends_on][p]
        for d in deps
            @assert haspart(store, :Path, d)
        end
    end
end
```

## Integration with Gay.jl

### Hash → Color Mapping

```julia
function hash_to_color(hash::String)
    seed = parse(UInt64, hash[1:16], base=32)
    gay_color(seed ⊻ GAY_SEED)
end
```

### GC Statistics (2024-12-24 Snapshot)

| Metric | Value |
|--------|-------|
| Dead paths | 299 |
| Reclaimable | 3.9 GB |
| Live roots | 17 |
| Worlds pruned | 5 |

## Triadic Composition

```
nix-acset-worlding (-1) ⊗ flox-envs (0) ⊗ world-hopping (+1) = 0 ✓
nix-acset-worlding (-1) ⊗ structured-decomp (0) ⊗ gay-mcp (+1) = 0 ✓
```

## Commands

```bash
# Snapshot current store
nix-store --gc --print-roots > roots.txt
nix-store --gc --print-dead > dead.txt

# Build ACSet from snapshot
julia -e 'using NixACSet; build_from_snapshot("dead.txt")'

# Verify dependency sheaf
julia -e 'using NixACSet; verify_sheaf(load_store())'
```

## Categorical Semantics

### Nix Store as Topos

- **Objects**: Store paths
- **Morphisms**: Dependencies (derivation → output)
- **Subobject classifier**: Ω = {live, dead, gc-protected}

### Pullback for Conflict Detection

```
     P ──────→ A
     │         │
     ↓         ↓
     B ──────→ C
```

When two derivations depend on conflicting versions:
- P = empty → conflict detected
- P ≠ empty → shared dependency

## References

1. **Dolstra** - Nix: A Safe and Policy-Free System for Software Deployment
2. **Eelco** - The Purely Functional Software Deployment Model
3. **ACSets.jl** - Attributed C-Sets for algebraic databases
4. **Gay.jl** - Deterministic coloring for store visualization

Overview

This skill models a Nix store as an Attributed C-Set to verify dependency semantics, analyze garbage-collectable state, and manage categorical “worlds” for Flox environments. It combines dependency sheaf checks, GC-root analysis, and deterministic coloring via Gay.jl to make store structure auditable and visualizable. The tool exposes commands to snapshot the store, build an ACSet, and run integrity checks for transitive dependency consistency.

How this skill works

The skill represents store Paths, Hashes, Names, Types, and Worlds as ACSet objects with homomorphisms and attributes such as size and liveness. It inspects live roots and dead paths, computes dependency transitive closures, and asserts that every dependency refers to an existing Path. Hash values map deterministically to colors through Gay.jl to aid visualization and grouping. Worlds are treated as categorical entities (name, dev_env, run_env, manifest) and used to group and prune store subsets for environment management.

When to use it

  • Audit store health before large GC operations
  • Validate transitive dependencies after builds or channel updates
  • Visualize store structure and clustering by hash-based coloring
  • Manage and prune Flox environments or project-specific worlds
  • Detect conflicting derivations or shared dependencies via pullback checks

Best practices

  • Snapshot GC roots and dead paths before making irreversible changes
  • Run dependency sheaf verification after each bulk build or channel migration
  • Keep world manifests explicit to avoid accidental cross-world dependency drift
  • Use deterministic hash→color mapping to maintain consistent visual groupings across snapshots
  • Automate periodic GC-statistics collection to track reclaimable size and pruning impact

Example use cases

  • Identify reclaimable bytes and dead paths before orchestrated garbage collection
  • Detect conflicting derivations by computing pullbacks across dependency morphisms
  • Group store paths into project worlds (music-topos, stellogen, etc.) and prune unused worlds safely
  • Visualize dependency clusters using Gay.jl coloring to spot hotspots and shared resources
  • Verify that newly built outputs reference only declared inputs by running the dependency sheaf check

FAQ

How does world grouping prevent accidental package deletion?

World grouping associates paths with explicit world manifests; GC root analysis treats belongs_to relations so pruning can be scoped to worlds and avoid removing paths still referenced by active worlds.

What happens if a dependency points to a missing path?

The dependency sheaf verification asserts that every dependency must be a known Path; missing targets signal integrity errors and should be investigated before GC or deployment.

Can I generate consistent visuals across different snapshots?

Yes. Hash-to-color uses deterministic seed derivation with a shared GAY_SEED so identical hashes map to the same colors across snapshots for stable visual comparisons.