Deploy a NixOS Host
Use this when building, deploying, or rolling back a NixOS host from this repo. Host inventory lives in Fleet; architecture background lives in Architecture/NixOS.
Quick checks
Confirm the host exists in the flake:
nix eval --json .#nixosConfigurations --apply builtins.attrNamesBuild the system closure without deploying:
nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel --no-linkRun a harmless remote command through the host app:
nix run .#<hostname> -- date
Deploy safely
Prefer
bootfor remote or headless hosts. It builds and installs the new generation, but activation waits until the next reboot:nixos-rebuild boot --sudo --target-host <hostname> --flake .#<hostname>Use
switchwhen immediate activation is intended:nixos-rebuild switch --flake .#<hostname> --target-host <hostname> --sudoFor offsite or Tailscale-only paths, use the reachable target host name:
nixos-rebuild boot --sudo --target-host <hostname>.<tailnet-name> --flake .#<hostname>
After deploying
Verify the host answers:
nix run .#<hostname> -- hostname nix run .#<hostname> -- systemctl --failed --no-pagerIf the change touched a service, check that unit explicitly:
nix run .#<hostname> -- systemctl --no-pager --full status <unit>.service nix run .#<hostname> -- journalctl -u <unit>.service -n 80 --no-pager
Roll back
If the host is reachable and the current generation is bad:
nix run .#<hostname> -- sudo nixos-rebuild switch --rollbackIf remote access is risky, use the bootloader console or local access and select the previous generation.
Adding a host
Kubernetes nodes normally belong in
baseHostsSpecinflake.nix; the hostname is the attr name and cluster membership comes from tags.Standalone hosts with unique config get a file under
nix/hosts/<hostname>.nixand aflake.nixhost entry pointing at it.Validate after adding a host:
nix flake check nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel --no-link
Dotfiles
Dotfiles are chezmoi-managed from the in-repo
dotfiles/tree.nix/system/chezmoi.nixcarries that subtree into the system closure and runschezmoi apply --source <store-path>during activation. See ADR/0006 Dotfiles vendored in-repo with chezmoi.There is no dotfiles flake input and no home-manager integration.
Auto-upgrade caveat
Hosts auto-rebuild from GitHub
main. A config deployed from a branch can be reverted by the next auto-upgrade unless the branch merges promptly. Treat a branch deploy as a test unless it has merged.
Linked references 2
Runbooks/Deploy a NixOS Host — build, deploy, verify, and roll back NixOS hosts