AGENTS.md #
Guidance for humans and agents working in this repository.
What this is #
This flake manages the full configuration for all of my machines: NixOS system configuration plus home-manager user configuration, generated from one flake. Currently there are two hosts:
prospero— laptop. Niri (Wayland compositor) with Noctalia providing the desktop shell, Emacs running as a systemd user daemon (package set managed with twist).uruk— the other machine (ZFS, enabled via theprofiles.zfsprofile).
The primary user is joshua (hardcoded in flake.nix when generating home
configurations).
Day-to-day commands #
just apply—nixos-rebuild switch --flake . --sudo, thenhome-manager switch --flake .just apply-boot— rebuild with boot activation instead of switchjust hm— home-manager switch only
A devshell (alejandra, just, nil) is provided via .envrc +
use flake (nix-direnv). Format Nix code with alejandra.
Source control #
This repo uses jj, colocated with a git repo (.jj and .git both
present). Do not use git commands; use jj.
Always run jj util snapshot --quiet before running any nix command.
Nix flakes only read git-tracked files from the working tree; without a
snapshot, nix may silently evaluate against stale file contents (you will
see "warning: Git tree ... is dirty" — that is normal and expected here).
Repo layout #
flake.nix inputs, overlays, nixConfig, flake-parts outputs
lib/default.nix host auto-discovery (see below)
hosts/<name>/ one directory per machine
modules/nixos/ NixOS modules (exposed as nixosModules.default)
modules/home/ home-manager modules (exposed as homeModules.default)
Host discovery (lib/default.nix) #
Every subdirectory of hosts/ containing a default.nix becomes a NixOS
configuration named after the directory. The default.nix looks like:
{...}: {
system = "x86_64-linux";
modules = [./configuration.nix]; # NixOS-level modules
home.modules = [./home.nix]; # home-manager-level modules
}
- If the host attrset has a
homeattribute, ahomeConfigurations.<user>@<host>entry is also generated (that is whatjust hmbuilds). hostnameis set automatically from the directory name.- To add a machine: create
hosts/<name>/withdefault.nix,configuration.nix,hardware-configuration.nix(fromnixos-generate-config) and optionallyhome.nix. Nothing else needs registering.
The profile pattern #
Shared configuration lives in modules/nixos/profiles/ and
modules/home/profiles/. Every profile:
- declares an option like
profiles.<name>.enable(usuallymkEnableOption), - gates its
configwithlib.mkIf cfg.enable, - is imported (and thus option-declared) by the corresponding
default.nix.
Hosts opt in via profiles = { foo.enable = true; }; in
configuration.nix / home.nix. Shared defaults inside profiles use
lib.mkDefault so hosts can override without conflict. Note some profiles
are nested (e.g. profiles.desktop.niri.enable — the desktop profile
imports and declares the niri sub-profile).
Both module trees are imported into every host (as nixosModules.default
/ homeModules.default in flake.nix), so profile options are always
declared — enabling is what activates behavior.
When adding a new profile, add it to the imports in the corresponding
default.nix, and remember the NixOS/home split: system-level services and
kernel/hardware settings go under modules/nixos/, user-level programs and
home.file under modules/home/.
The Emacs subsystem (modules/home/profiles/emacs/) #
This is the most special-cased part of the repo. Emacs and its package set are managed with twist.nix via a nested flake inside the profile directory.
Layout #
flake.nix— nested flake. All of its inputs usefollowspointing at the parent flake, so registry snapshots (melpa, gnu-elpa, nongnu, epkgs) are pinned in the repo-rootflake.lock, not here.nix/emacs.nix— the twist environment (twist.lib.makeEnv): emacs package, init files, lock dir, and the registry list. Thecustomregistry (recipes/) is listed first, so it takes precedence over melpa/gnu-elpa.recipes/— melpa-style recipe files, one line each, for packages not taken verbatim from an archive (custom forks, fast-moving packages).nix/input-overrides.nix,nix/package-overrides.nix— build-time fixes for individual elisp packages (native-comp patches, dependency overrides).init.el,early-init.el,etc/— the actual Emacs configuration, deployed to~/.config/emacs/viahome.file.var/is runtime state (custom.el lives there; it is not in the repo).lock/— a subflake holding the package pins:flake.nix— auto-generated, one input per package, no revsflake.lock— the actual git rev pins for every packagearchive.lock— archive-version data; empty ({}) in this setup because every package here is git-sourced
justfile—just lock,just update,just test(try the config with--init-directory .without deploying).
Testing Emacs #
Changes should not be tested by running just hm and restarting the emacs
daemon. Instead, test changes by running just test in the emacs directory
to test whether a change seems to approximately work correctly. If possible,
attempt to test the change by running emacs in batch mode. Running emacs in
interactive mode is acceptable for testing but should be avoided when
possible.
It is acceptable to build test infrastructure to make further and better
testing feasible. If you wish to write unit tests, use the buttercup
library for emacs as the test framework and put the testing code outside
of init.el. Putting code that is only needed when testing into init.el
makes emacs run slower and init.el more distracting to edit, to make
sure to try extra hard to keep anything complex out of there.
Updating Emacs packages — IMPORTANT PITFALL #
just update and just lock do not and cannot bump package versions:
just updateonly rewriteslock/archive.lock, which is legitimately empty for this all-git setup. It is a no-op here.just lockregenerateslock/flake.nix(only changes if the package set changes) and runsnix flake lock, which only fills in missing pins. Existing revs are never moved.
To actually update package versions, run nix flake update inside the
lock directory:
cd modules/home/profiles/emacs/lock
nix flake update # everything
nix flake update <package> # one package (input name == package name)
The outer registry inputs (melpa, gnu-elpa, nongnu, epkgs, twist) are
updated separately at the repo root (nix flake update ...); they control
which recipes/repos packages resolve from, not the pinned revs.
The twist lock writer shells out to git (it requires the lock dir to be
inside a git working tree and git adds new files), which works here
because of the jj/git colocated setup.
Emacs runs as a daemon #
services.emacs (systemd user unit, startWithUserSession = "graphical"),
started by the niri session. The build is the X/Lucid variant of Emacs 31,
not pgtk — graphical frames go through Xwayland via
xwayland-satellite, which niri spawns via its built-in integration
(xwayland-satellite.enable = true in the home niri profile).
Known issue: suspend/resume kills the daemon's X connection while a
zombie terminal survives, after which emacsclient -c silently fails to
open graphical frames (only emacsclient -t works) until the daemon is
restarted (systemctl --user restart emacs). If graphical emacs frames
misbehave after a suspend, restart the daemon before debugging anything
else.
Nix conventions and settings #
- Primary nixpkgs input is
nixos-unstable(plus anixpkgs-stableinput that is currently unused downstream).allowUnfreeis on globally. - Extra substituters and keys are declared in both
flake.nixnixConfig(for flake consumers) andmodules/nixos/nix.nix(for the system); keep them in sync when adding one. - Generation retention is handled by
services.angrr(seenix.nix), not by aggressive GC — old generations are kept 14 days / 10 system gens. stateVersionvalues (25.05in both trees) are pinned; do not bump them. They mean "initial install generation", not current version.- Coupling to be aware of:
virtualisation.docker.storageDriveris chosen aszfsiff theprofiles.zfsprofile is enabled (modules/nixos/default.nix).
Theming #
Stylix is applied at both the NixOS and home-manager level (modules passed
in flake.nix), and targets (niri, fuzzel, gtk, ...) are enabled in the
individual profiles. Colors should come from
config.lib.stylix.colors.withHashtag rather than hardcoded values.
Desktop stack (prospero) #
- NixOS side (
modules/nixos/profiles/desktop/): PipeWire audio, plasma login manager for the niri session, kernel defaults. - Home side (
modules/home/profiles/desktop/niri.nix): niri (pinned toniri-unstablefrom the niri flake), fuzzel launcher, foot terminal, cliphist, Noctalia (from its own flake input), xwayland-satellite. - Keybindings are generated with a small combinator (
bindsat the top of the home niri profile) that expands prefix/suffix key maps — add bindings to theprefixes/suffixesattrsets rather than hand-writing pairs.