repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
nix.mdMarkdown276 lines17.8 KiBsource raw download

nix — rebuilding this machine from ~/NixDaemon#

NixOS and home-manager are one flake: ~/NixDaemon (NH_FLAKE points at it). home-manager runs as a NixOS module, so one rebuild does both; there is no separate home-manager switch here. Terminal card: nix-cheat — sections layout rebuild remote nh home search update rollback clean inspect add desktop dotfiles secrets repo shell.

layout — what lives where#

Dendritic: flake.nix is flake-parts.lib.mkFlake … (import-tree ./modules); every *.nix under modules/ is a flake-parts module that declares what it owns, and modules name each other through self (never by path).

~/NixDaemon/flake.nix                 inputs only · outputs = import-tree ./modules
modules/parts.nix                     systems, the home-manager + wrapper-modules flake modules
modules/hosts/laptop/default.nix      flake.nixosConfigurations.nixos (modules = [ self.nixosModules.laptop ])
modules/hosts/laptop/configuration.nix  nixosModules.laptop: imports laptop-* + features by name; daemon.desktop.* switches
modules/hosts/laptop/*.nix            nixosModules.laptop-<name>: hardware, nvidia, ssd, nix-settings (nh), sops, toolbox, fan-*
modules/features/workstation.nix      nixosModules.workstation (Claude, Obsidian, gh, glab)
modules/features/home-manager.nix     nixosModules.home-manager: HM as a NixOS module → self.homeModules.daemonsec
modules/features/desktop/options.nix  daemon.desktop.hyprland.enable · daemon.desktop.niri.enable
modules/features/desktop/niri.nix     packages.niri (wrapped) + nixosModules.desktop-niri
modules/features/desktop/noctalia.nix packages.noctalia (wrapped, Rosé Pine)
modules/home/default.nix              homeModules.daemonsec: imports every homeModules.<name>
modules/home/tools.nix                packages: the toolbox closure and the general CLI tools  ← add packages here
modules/home/dotfiles.nix             every dotfile from dotfiles/ in this repo, as symlinks  ← add dotfile paths here
modules/home/hyprland.nix, hypr/*.lua Hyprland config + helpers (gated on daemon.desktop.hyprland)
modules/home/caelestia.nix            the Caelestia shell, its CLI, wallpaper dir (same gate)
modules/hosts/laptop/sops.nix         sops-nix (system) · modules/home/sops.nix (user) · secrets/secrets.yaml · .sops.yaml

rebuild — nixos-rebuild, the plain way#

cd ~/NixDaemon
sudo nixos-rebuild switch --flake .#nixos      # build, activate now, make it the boot default
sudo nixos-rebuild boot   --flake .#nixos      # build, activate on next boot only (kernel/driver changes)
sudo nixos-rebuild test   --flake .#nixos      # activate now, NOT the boot default (try something out)
nixos-rebuild build       --flake .#nixos      # just build → ./result, no sudo, nothing changes
sudo nixos-rebuild switch --flake ~/NixDaemon#nixos   # same, from any directory

remote — build straight from the GitLab repo#

The flake does not have to be checked out: any nix command takes a flake reference to the repo. The ssh form needs your key registered on GitLab (https works for the public repo); ?ref=main pins a branch, ?rev=<sha> a commit.

REPO='git+ssh://git@gitlab.com/DAEMON-404/NixDaemon.git'
sudo nixos-rebuild switch --flake "$REPO#nixos"                  # this machine, from the pushed main
sudo nixos-rebuild boot   --flake "$REPO?ref=main#nixos"
nh os switch "$REPO"                                             # nh takes the same reference
nix build "$REPO#nixosConfigurations.nixos.config.system.build.toplevel" --no-link --print-out-paths
nix flake show "$REPO"                                           # what the repo exports
nix flake metadata "$REPO"                                       # which commit nix resolved
# root (sudo) fetches with root's ssh: either run the fetch as you first (nix build …, cached), or give
# root the key via /root/.ssh/config, or use an https token in ~/.config/nix/netrc (machine gitlab.com …).

Fresh machine, from the live ISO (disk already partitioned and mounted at /mnt):

sudo nixos-generate-config --root /mnt --show-hardware-config > hardware-configuration.nix   # compare with modules/hosts/laptop/hardware.nix
git clone git@gitlab.com:DAEMON-404/NixDaemon.git ~/NixDaemon && cd ~/NixDaemon   # ssh key first (see *secrets*)
# paste its body into modules/hosts/laptop/hardware.nix (inside the laptop-hardware wrapper; a raw
# hardware-configuration.nix under modules/ would be loaded by import-tree as a flake-parts module), then:
sudo nixos-install --flake .#nixos

Afterwards (the dotfiles are in the repo, under dotfiles/): restore the age key to ~/.config/sops/age/keys.txt and /var/lib/sops-nix/key.txt (see secrets), and the toolbox to ~/.local/bin.

A remote reference is fetched fresh each time (nix caches it briefly, --refresh forces it); the local checkout at ~/NixDaemon (NH_FLAKE) is the default for day-to-day work.

nh — the same, with a diff and a progress tree#

nh wraps nixos-rebuild: builds with nix-output-monitor, shows an nvd diff of what changes, then asks for sudo.

nh os switch                 # = sudo nixos-rebuild switch --flake ~/NixDaemon (NH_FLAKE), config picked by hostname
nh os boot                   # build + boot default, activate on reboot
nh os test                   # activate now, not the boot default
nh os build                  # build only, no activation, no sudo
nh os switch --dry           # show what would happen, do nothing
nh os switch --ask           # show the diff, then confirm before activating
nh os switch -u              # `nix flake update` first, then switch (updates EVERY input — see *update*)
nh os info                   # list system generations
nh os rollback               # go back one generation (see *rollback*)
nh os switch -- --show-trace # anything after -- goes to nix build (debug an eval error)

home — home-manager in this setup#

search — finding packages and options#

ns                          # fuzzy search everything indexed: nixpkgs packages, NixOS and home-manager options
ns kitty                    # start with a query

Inside ns (fzf): type to filter, ↑↓ move, the right pane shows the description, version, homepage and the option's default. Enter prints the attribute name (paste it into home.packages in tools.nix), ctrl-y copies it, ctrl-o opens the homepage, ctrl-s the nixpkgs source, Esc quits. The index is built by nix-search-tv on first use (a few seconds) and refreshed by itself; by hand:

nix-search-tv print | head                 # the raw list   ·  nix-search-tv preview firefox   # one entry
nh search firefox                          # search.nixos.org from the terminal (needs network)
nix search nixpkgs firefox                 # nix's own search (slow first run: builds an eval cache)
nix eval ~/NixDaemon#nixosConfigurations.nixos.pkgs.firefox.version          # version THIS flake would install
nix shell nixpkgs#firefox                  # try it without installing  ·  nix run nixpkgs#cowsay -- hi

update — moving the inputs#

cd ~/NixDaemon
nix flake update                       # all inputs → flake.lock (nixpkgs, home-manager, hyprland, caelestia, llm-agents)
nix flake update nixpkgs home-manager  # only these inputs
nix flake update hyprland              # Hyprland alone (uses hyprland.cachix.org, so usually no compile)
nix flake lock                         # (re)write the lock without updating
nix flake metadata                     # which revisions are locked right now
nh os boot                             # then build it; boot = safest for kernel/driver bumps

Hyprland and Caelestia pin each other (flake.nix comments): update hyprland and caelestia-* together if the shell breaks.

rollback — when a generation misbehaves#

nh os rollback                          # previous generation, now
sudo nixos-rebuild switch --rollback    # the same, plain
nh os info                              # generation numbers
sudo nix-env --switch-generation 5 -p /nix/var/nix/profiles/system && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch

clean — store and generations#

nh clean all --keep 5 --keep-since 14d  # what the weekly timer runs (nix-settings.nix): drop old generations, GC
nh clean all --dry                      # show what it would remove
sudo nix-collect-garbage -d             # the blunt version: delete all old generations, then GC
nix store gc                            # GC only (nothing referenced by a generation is touched)
du -sh /nix/store                       # how big is it

inspect — see before you switch#

nh os build && nvd diff /run/current-system result     # what a switch would change
nix build ~/NixDaemon#nixosConfigurations.nixos.config.system.build.toplevel --no-link --print-out-paths
nix eval ~/NixDaemon#nixosConfigurations.nixos.pkgs.uv.version                 # version a package would get
nix eval ~/NixDaemon#nixosConfigurations.nixos.config.programs.zsh.enable      # read an option value
ns <query>                              # fuzzy search nixpkgs + NixOS/HM options, with descriptions (nix-search-tv)
nh search <package>                     # nixpkgs search (search.nixos.org)
nix search nixpkgs <package>            # local search (first run builds an index)
nix shell nixpkgs#<package>             # try a tool without installing it
nix run nixpkgs#<package> -- --help
nix flake check ~/NixDaemon             # evaluate every output
nix flake show ~/NixDaemon

add — packages, options, dotfiles, modules#

desktop — Hyprland + Caelestia or Niri + Noctalia#

Both are installed; tuigreet lists both sessions and remembers the last one, so switching is log out → pick the other.

nix run ~/NixDaemon#niri          # try Niri nested in the current desktop (Alt is the modifier); Noctalia starts inside it
nix run ~/NixDaemon#noctalia      # the bar alone
# modules/hosts/laptop/configuration.nix — set one to false and `nh os switch` to drop it entirely
daemon.desktop = { hyprland.enable = true; niri.enable = true; };

dotfiles — dotfiles/ in the repo is the source of truth#

secrets — sops-nix and secretspec#

Two tools, two jobs. sops-nix: secrets that belong in this repo, encrypted with age, decrypted at activation to /run/secrets/NAME (system) or ~/.config/sops-nix/secrets/NAME (user). secretspec: runtime secrets for a project, declared in its secretspec.toml, stored in the keyring.

# sops — the one key: ~/.config/sops/age/keys.txt (user) = /var/lib/sops-nix/key.txt (system, root copy)
sudo install -D -m 600 -o root -g root ~/.config/sops/age/keys.txt /var/lib/sops-nix/key.txt   # once per machine
age-keygen -y ~/.config/sops/age/keys.txt         # the public key (recipient) in .sops.yaml
sops secrets/secrets.yaml                          # edit: opens decrypted in $EDITOR, re-encrypts on save
sops set secrets/secrets.yaml '["wifi-psk"]' '"hunter2"'   # add/replace one value without the editor
sops -d secrets/secrets.yaml                       # print decrypted
sops -d --extract '["example"]' secrets/secrets.yaml
sops updatekeys secrets/secrets.yaml               # after editing the recipients in .sops.yaml

Then declare it and rebuild:

# modules/hosts/laptop/sops.nix (system)                     # modules/home/sops.nix (user)
sops.secrets.wifi-psk = { };                         sops.secrets.my-token = { };
sops.secrets."ssd.key".path = "/etc/secrets/ssd.key";   # e.g. the LUKS key instead of restoring it by hand

nh os switch → /run/secrets/wifi-psk (root, 0400; owner = "daemonsec"; to read it as the user). Check: sudo ls -l /run/secrets/, systemctl --user status sops-nix (user side), journalctl -b | grep sops.

# secretspec — in a project directory (config: ~/.config/secretspec/config.toml → keyring, profile default)
secretspec init                 # writes secretspec.toml (commit it; it holds names, never values)
secretspec add DATABASE_URL     # declare a secret (flags: --required/--default/--description)
secretspec check                # prompts for every missing value, stores it in the keyring
secretspec set NAME            # (re)store one value
secretspec run -- ./server      # run with the secrets in the environment
secretspec export               # print them for another tool (shell `eval`)
secretspec claude configure     # let Claude Code fetch its API credential through secretspec

repo — committing ~/NixDaemon#

The repo is jj, colocated with git (.jj + .git). Nix flakes only see files git knows about, and jj keeps git's index at @-, so a new file is invisible to nix until it is added:

cd ~/NixDaemon
git add modules/home/new.nix       # make nix see a new file (modified tracked files are seen as-is)
nh os build                        # or switch
jj status                          # jj snapshots the working copy
jj describe -m "what changed" && jj new      # seal it (the vault ritual) — or plain: git add -A && git commit
jjmsg -c                           # or let the message write itself from the diff (jjmsg: print · -d describe · -e edit · -c commit)
jj log                             # history

A dirty tree only prints warning: Git tree '/home/daemonsec/NixDaemon' is dirty; it still builds.

shell — after a switch#