# 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 ```text 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 ```bash # 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` / `test` - `systemctl [start|stop|restart|reload]` - `udevadm *` - `mount` / `umount` - `reboot` / `shutdown` - `nix-store --delete` or 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 status` to 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/` (with `apps.nix` as the default central application module). - **Host-Specific User Tools**: Place in `hosts//home.nix` (e.g., Hyprland screen recording utilities on desktop). - **System-Wide Packages**: Place in `modules/system/base.nix` *only* 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`) under `hosts/desktop/`. Never import them into `hosts/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.nix` files are generated by `nixos-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/` or `config.sops.secrets..path`. ### 8. Flake Dependencies - Do not introduce a new flake input if standard `nixpkgs` provides the required package or module. - Do not update unrelated flake inputs or regenerate `flake.lock` for 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: ```text 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 check`
`nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link`
`nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link` | | `modules/user/*` or `home.nix` | `desktop`, `laptop` | `nix flake check`
`nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link`
`nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link` | | `hosts/desktop/*` | `desktop` only | `nix flake check`
`nix build .#nixosConfigurations.desktop.config.system.build.toplevel --no-link` | | `hosts/laptop/*` | `laptop` only | `nix flake check`
`nix 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: 1. **Pre-Existing Changes Detected**: [Yes / No (with details if preserved)] 2. **Files Modified by Agent**: List of exact files changed. 3. **Architectural Assessment**: Verification that invariants were respected and boundaries maintained. 4. **Validation Executed**: Output of `nix flake check` and `nix build ... --no-link`. 5. **Pending Manual Actions**: Any user-required steps (e.g. running `sudo nixos-rebuild switch` or committing changes).