- Add `AGENTS.md` to define agent safety guardrails, risk tiers, and validation protocols. - Add `CLAUDE.md` to point agents to authoritative documentation. - Add `architecture.md` to document layer responsibilities, file placement rules, and architectural invariants.
9.1 KiB
AGENTS.md
Mission & Purpose
This repository manages the declarative NixOS and Home Manager configurations for desktop and laptop hosts.
AI agents working in this repository must maintain architectural integrity, avoid configuration sprawl, respect pre-existing work, and adhere strictly to the invariants defined in architecture.md.
The Golden Rule: Build, Never Switch
Caution
Agents are strictly forbidden from executing
sudo nixos-rebuild switch,boot,test, or mutating the running host system. An agent may modify the declaration of the system and verify compilation. It must never autonomously alter the running state of the host machine.
Security Boundary Model
Repository
│
├── Agent may READ
├── Agent may MODIFY
└── Agent may VALIDATE
│
▼
Nix Derivation (Dry Build)
│
═══════╪══════════════════════════════════════ [STRICT BARRIER]
▼
Running Host System
(Mutations strictly prohibited without explicit user instruction)
Permitted Verification Commands
# Validate flake metadata, inputs, and derivations
nix flake check
# Build desktop host dryly (evaluates configuration without switching)
nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link
# Build laptop host dryly
nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link
Prohibited Live-System Commands (Unless Explicitly Requested)
nixos-rebuild switch/boot/testsystemctl [start|stop|restart|reload]udevadm *mount/umountreboot/shutdownnix-store --deleteor manual modifications to/nix/var/nix/profiles/
Operating Rules & Constraints
1. Request Interpretation
- Narrow Interpretation: Interpret the user's request as narrowly as reasonably possible.
- No Inferred Authorization: Do not infer permission for unrelated cleanup, dependency upgrades, directory reorganization, or live-system mutations.
2. Preserve Pre-Existing Uncommitted Work
- Inspect First: Before making any edits, check
git statusto identify pre-existing uncommitted changes. - Never Overwrite: Never overwrite, discard, reset, stash (
git checkout .,git reset,git stash), or manipulate user changes that existed prior to your task. - Distinguish Attribution: Clearly separate pre-existing modifications from agent modifications in the completion report.
3. Do Not Expand Scope & Minimal Change Principle
- No Spontaneous Refactoring: An agent must not turn a feature request into a refactoring project.
- Report Architectural Issues Separately: If a requested change exposes an architectural smell or problem, report it to the user rather than silently attempting to refactor surrounding code (unless strictly required for correctness).
- Smallest Viable Change: Make the minimal change that satisfies the request. Do not introduce single-use abstractions, single-option wrapper modules, or arbitrary file reorganizations.
4. Package Placement Rules
- Shared User Applications: Place in
modules/user/(withapps.nixas the default central application module). - Host-Specific User Tools: Place in
hosts/<host>/home.nix(e.g., Hyprland screen recording utilities on desktop). - System-Wide Packages: Place in
modules/system/base.nixonly if required for root maintenance, core networking, or systemd daemons.
5. Host Isolation & Desktop Specialisation
- Keep machine-specific homelab infrastructure (
homeserver.nix,traefik-deployments.nix,dynu.nix) underhosts/desktop/. Never import them intohosts/laptop/. - Protect the desktop
specialisation.server. Any changes to graphical or audio stacks must preserve the headless server boot profile.
6. Hardware Configurations
hardware-configuration.nixfiles are generated bynixos-generate-config. Do not manually restructure, clean up, or refactor them. Hardware additions (e.g., kernel parameters, disk mounts) require explicit justification.
7. Secrets & Key Safety (SOPS)
- Never write or commit plaintext secrets into
.nix,.yaml, or temporary files. - Never decrypt secrets into tracked or persistent working-tree files.
- Never add, modify, or rotate SOPS/age keys unless explicitly commanded by the user.
- Never expose decrypted secret material through
git diff, logs, or terminal outputs. - Reference secrets only via
/run/secrets/<name>orconfig.sops.secrets.<name>.path.
8. Flake Dependencies
- Do not introduce a new flake input if standard
nixpkgsprovides the required package or module. - Do not update unrelated flake inputs or regenerate
flake.lockfor feature changes. - Pin
inputs.nixpkgs.follows = "nixpkgs"on new flake inputs whenever applicable.
Risk Classification Framework
| Tier | Category | Examples | Required Action & Workflow |
|---|---|---|---|
| LOW | User Configuration | User packages in apps.nix, shell aliases, Neovim lua config, Tmux settings, docs. |
Autonomous: Agent plans, edits, and validates via nix flake check + affected host build. |
| MEDIUM | Shared System & Desktop | modules/system/*, greetd/display manager, firewall rules, user groups, new flake inputs. |
Autonomous: Agent plans, edits, and validates via nix flake check + builds both desktop and laptop. |
| HIGH | Core & Infrastructure | Bootloader, filesystems, SOPS keys/secrets setup, specialisation.server, Traefik, Docker networking. |
Stop & Wait: Agent must present the plan and wait for user approval before editing. |
| PROHIBITED | Live System Mutators | nixos-rebuild switch, destructive disk ops, editing /etc outside Nix, rotating age keys, plaintext secrets. |
Blocked: Cannot execute unless explicitly commanded by the user in the current prompt. |
Change Protocol
Every modification by an agent must follow this lifecycle:
REQUEST
│
▼
1. UNDERSTAND
├── Identify affected host(s) and trace consumer import chain
├── Check `git status` to identify pre-existing uncommitted work
└── Read architectural boundaries in architecture.md
│
▼
2. PLAN
├── Formulate minimal viable change
├── Verify no architectural invariants are violated
└── IF HIGH RISK: Stop and present plan for user approval before proceeding
│
▼
3. EDIT
├── Make targeted modifications only
└── Respect package and secret placement boundaries
│
▼
4. VALIDATE
├── Run `nix flake check`
└── Build all downstream affected hosts (`--no-link`)
│
▼
5. REVIEW
├── Inspect `git diff` for unintended changes or exposed secrets
└── Ensure no pre-existing user work was disturbed
│
▼
6. REPORT
└── Provide completion report with pre-existing work status and build outputs
Host-Aware Validation Matrix
Note
The matrix below is a default heuristic. When the import graph indicates additional downstream consumers, validate those configurations as well.
| Modified Path | Affected Consumers | Required Build Validation |
|---|---|---|
modules/system/* |
desktop, laptop |
nix flake checknix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-linknix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link |
modules/user/* or home.nix |
desktop, laptop |
nix flake checknix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-linknix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link |
hosts/desktop/* |
desktop only |
nix flake checknix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link |
hosts/laptop/* |
laptop only |
nix flake checknix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link |
flake.nix / flake.lock |
desktop, laptop |
nix flake check + build both hosts |
Documentation Hygiene
Maintain clear ownership of documentation:
README.md: High-level repository overview and quick start.architecture.md: Structural topology, layer boundaries, and architectural invariants.AGENTS.md: Agent constitution, change policies, risk matrix, and validation rules.docs/*.md: Step-by-step procedural guides for humans (maintenance, secrets, Antigravity, Dynu).
Rule: Do not duplicate architectural descriptions into procedural docs or README.
Completion Report Format
When reporting back after a task, summarize:
- Pre-Existing Changes Detected: [Yes / No (with details if preserved)]
- Files Modified by Agent: List of exact files changed.
- Architectural Assessment: Verification that invariants were respected and boundaries maintained.
- Validation Executed: Output of
nix flake checkandnix build ... --no-link. - Pending Manual Actions: Any user-required steps (e.g. running
sudo nixos-rebuild switchor committing changes).