7.8 KiB
Repository Guidelines
Project Structure & Module Organization
This repository is a Den-based NixOS flake. flake.nix evaluates ./modules through import-tree, so normal .nix files under modules/ are auto-imported.
modules/den.niximports the Den flake module and theluxnamespace.modules/defaults.nixsets repo-wide Den defaults, enablesden._.mutual-provider, and configuresden.ctx.hm-host.modules/schema.nixdefines the custom Den host and user schema used by this repo.modules/infra.nixdefinesden.hosts.x86_64-linux.<name>, each host entity'susersattrset, and the host/user data attached to those entities.modules/bundles.nixdefines bundle aspects that group other aspects. A bundle aspect may exist only to composeincludes;local-sessionis an example.modules/hosts/contains host-specific composition and hardware data fororion,polaris, andzenith.modules/features/contains reusable aspects. In this repo, "feature" is only a directory label, not a Den primitive.modules/users/defines per-user aspects.modules/secrets/wiressops-nixand stores the encryptedsecrets.yaml..agents/den/is a local checkout of Den with source, docs, and examples.
Keep host files thin. Shared behavior belongs in modules/features/ or modules/bundles.nix.
When Den behavior is unclear, read .agents/den/modules/ and .agents/den/nix/lib/ first. Use .agents/den/templates/ci/ as example code. Use .agents/den/docs/ only for design rationale, terminology, and usage guidance.
Do not infer Den behavior from surface symptoms or from where an aspect is included; reason from the actual context pipeline.
Den Mental Model
Den is aspect-first and context-driven.
- Host, user, and home are entity kinds in Den. This repo defines host and user entities; it does not define standalone home entities under
modules/. - An aspect is the unit of behavior. A single aspect may define
nixos,homeManager,darwin,user, or other class fragments for one concern. - A context stage applies a resolved aspect to a context; Den then follows
into.*andprovides.*. homeManageris a forwarding class.
In practice:
- Including an aspect does not by itself create a forwarding path.
- Parametric matching does not by itself create a forwarding path.
- A class fragment reaches its final option path only if a context stage or forwarding class actually puts it there.
- If you cannot name the context stage and forwarding path, treat the claim as unverified.
Den Context Stages And Forwarding Mechanisms
These are the mechanisms most relevant to the context pipeline in this repo.
den.ctx.host: host context stage; appliesfixedTo { host; } host.aspectden.ctx.user: user context stage fromden.ctx.host.into.user; appliesfixedTo { host; user; } user.aspectden._.mutual-provider: battery included onden.ctx.userin this repo; routes host-to-user and user-to-host throughprovides.<name>, host-to-all-users throughprovides.to-users, user-to-hosts throughprovides.to-hosts, and user-to-other-users on the same host through the same user context pipeline. In Den generally it also has standalone-home behavior, but this repo does not use standaloneden.homesden.ctx.hm-host/den.ctx.hm-user: derived home-env context stagesden._.define-user: battery included byden.defaultin this repo; defines base OS user fields and basehomeManager.home.username/home.homeDirectoryfieldshomeManager: forwarding class intohome-manager.users.<name>den._.os-user: framework battery forwarding theuserclass intousers.users.<name>; useful in Den generally, but not used in this repo todayden._.forward: battery for custom class/path forwarding
Den Helper Functions
These are the Den helpers that matter most in this repo.
den.lib.perHost: exact{ host }wrapperden.lib.perUser: exact{ host, user }wrapperden.lib.perHome: exact{ home }wrapper; not used by this flake todayden.lib.parametric: explicit parametric wrapper; default matching isatLeastden.lib.parametric.exactly: explicit exact-match wrapper
Den Forwarding Proof Obligation
When making or reviewing any Den forwarding change, do not infer behavior from where code is declared or included.
You must identify all four of these explicitly:
- Source: which aspect actually owns the class fragment?
- Context stage: which
den.ctx.*stage applies it? - Destination: which final evaluated option path should contain the result?
- Mechanism: which
into.*transition reaches the context stage, and which class application,provides.*, forwarding class, orden._.forwardstep places it at the destination?
If any of those answers are missing, unclear, or based on analogy, treat the claim as unverified.
Before presenting a forwarding claim as a recommendation or review finding, verify it at the evaluated destination with nix eval.
Minimum checks:
- host-selected
homeManagerbehavior: inspectnixosConfigurations.<host>.config.home-manager.users.<user> - OS user forwarding via
userclass: inspectnixosConfigurations.<host>.config.users.users.<user> - mutual host/user forwarding through
provides.<name>,provides.to-users, orprovides.to-hosts: inspect the final destination option, not the declaration site - custom forwarding through
den._.forward: inspect the exact target path created by the forwarder
Validation And Development Commands
Run commands from the repository root.
nix build --no-link --show-trace .#nixosConfigurations.<host>.config.system.build.toplevel: baseline validation for one host without activation and without creating aresultsymlink.nix build --no-link --show-trace .#nixosConfigurations.orion.config.system.build.toplevel .#nixosConfigurations.polaris.config.system.build.toplevel .#nixosConfigurations.zenith.config.system.build.toplevel: validate all currently defined hosts in one invocation.nixos-rebuild build --flake .#<host>: use the standard rebuild path without activation when you specifically wantnixos-rebuildsemantics.nix fmt: format Nix files using the flake-providednixfmtformatter.nix eval .#nixosConfigurations.<host>.config.<option>: inspect a single option while iterating.
This repo does not define a checks output or a first-party test suite. Treat evaluation and build-only checks as the baseline. nix flake check is therefore not the baseline validation command here. nixos-rebuild dry-activate is not a baseline validation command either: it is activation-oriented, applies to the target system being rebuilt, and its own help text says the reported change set is not guaranteed to be complete.
For Den context-stage or forwarding changes, use the destination checks above.
Coding Style & Naming Conventions
Use two-space indentation and standard Nix attrset formatting. Prefer small let bindings, lowerCamelCase local names, and lowercase file names such as sops-password.nix. Match the surrounding module style instead of reformatting unrelated code.
Prefer Den composition through includes; avoid host-specific duplication when a reusable aspect or bundle aspect is clearer.
Keep the configuration aspect-first. When a class fragment must cross context boundaries, express that through an explicit forwarding mechanism instead of relying on implicit host/user propagation.
Commit
Follow the history style: short imperative subjects, optionally with a conventional prefix, for example refactor: restructure openssh config. Keep each commit focused on one concern.
Security & Configuration Tips
Never commit plaintext secrets. Add or update secrets through modules/secrets/secrets.yaml and reference them via config.sops.secrets.<name>.path. Be explicit about firewall, SSH, disk, boot, or firmware changes; those are the highest-risk edits here.