Nix development
Run host integration tests
Every host directory under config/nix/hosts/ with a default.nix is
automatically registered as a flake check named host-<host>-test (see the
Declarative Integration Testing specification).
Run one host's test locally from the repository root with:
nix build ./config/nix#checks.x86_64-linux.host-<host>-test --no-link -L
Keep these points in mind:
- Nix flakes evaluate only Git-tracked files:
git addnewly created files (for example a new role directory) before building, or evaluation fails with a "not tracked by Git" error. - Pass
--no-linkso the build does not clobber the repository's singleresultsymlink, which the220-proxmox-workloadsTerraform stack reads for staged image artifacts. - When writing test script assertions, remember that
machine.succeedruns commands underpipefail: an early-exiting pipe consumer such asgrep -qcloses the pipe while the producer is still writing large output, failing the pipeline with the producer's write error. Use a consumer that reads the full stream (for examplegrep <pattern> > /dev/null).
Open a Python shell in a test virtual machine
-
Start the interactive test driver:
nix run .#checks.x86_64-linux.<machine-name>-test.driverInteractiveTo exit the test driver, use the
CTRL-dkey combination. -
Start all machines:
start_all() -
Open a Linux shell:
machine.shell_interact()
Nix GitOps
Nix machines run comin to implement GitOps.
Pushing commits to branches named testing-<host-name> makes comin pull
changes, apply them, but not update the bootloader to boot from the newly
generated configuration. Comin updates the bootloader when commits are pushed to
the default branch. For more info, see
Comin how-tos.
If the default branch changes, update config/nix/roles/comin/default.nix
accordingly.
Nix commands
nix flake metadata <path>: show flake metadatanix flake show <path>: show information about the flakenix fmt . -- --clear-cache: format the Nix codebasenix build .#checks.x86_64-linux.lint-treefmt-nix --verbose: run linting and formatting checksnixos-rebuild switch --flake ".#<host>" --target-host "<ssh-user>@<host>" --sudo: apply changes to host when it's not running comin.nix flake check <path>: run all flake checksnix build <path>#checks.<check-name>: run a specific checknix build <path>#<package-name>: build specific packagenix build --rebuild <path>#<package-name>: rebuild a packagenix build --print-build-logs <path>#<package-name>: print build log
nix-store --gc: clean the Nix store