This document covers the development workflow for working with this NixOS configuration.
# Enter development shell
nix develop
# Format code
nix fmt
# Check for issues
nix flake check
# Build a specific machine
nix build .#nixosConfigurations.<machine>.config.system.build.toplevelThe default development shell includes:
nixpkgs-fmt- Nix code formatterstatix- Nix linter (anti-pattern detection)deadnix- Find unused Nix code- Pre-commit hooks (auto-installed)
# Enter default shell
nix develop
# Enter specific shells
nix develop .#secrets # For managing encrypted secrets
nix develop .#rust # Rust development
nix develop .#hack # Security toolsThe development shell automatically installs git pre-commit hooks:
- treefmt - Auto-format Nix files
- deadnix - Detect unused code
Hooks run automatically on git commit. To skip (not recommended):
git commit --no-verifyFormat all Nix files:
nix fmtThe formatter uses:
nixpkgs-fmtfor Nix formattingdeadnixfor removing unused codestatixfor linting
nix flake checkThis runs:
- Nix evaluation of all configurations
- NixVim configuration tests
- Builds all machine configurations (toplevel)
nix build .#nixosConfigurations.zen.config.system.build.toplevel --dry-run# Dry run (check if it builds)
nixos-rebuild build --flake .#<machine>
# Build and switch (local machine)
sudo nixos-rebuild switch --flake .#<machine># Build locally, deploy remotely
nixos-rebuild switch --flake .#<machine> --target-host root@<hostname>
# With SSH options
NIX_SSHOPTS="-t" nixos-rebuild boot --flake .#<machine> --target-host root@<hostname>nix build .#install-iso# Update all flake inputs
nix flake update
# Update specific input
nix flake lock --update-input nixpkgs
# Show what changed
nix flake metadata# Build and run VM for a machine
nixos-rebuild build-vm --flake .#<machine>
./result/bin/run-<machine>-vm
# Or use nixos-anywhere's VM test
nix run github:nix-community/nixos-anywhere -- --flake .#<machine> --vm-testNote: VM testing requires disabling disk encryption in the configuration.
Interactive exploration of the flake:
nix repl
:lf .
# Now you can explore:
# nixosConfigurations.zen.config.services
# etc.Or use the helper:
nix repl ./repl.nixThe repo uses direnv (.envrc) to automatically load the development shell:
# Allow direnv for this directory
direnv allow
# Shell loads automatically when entering directory
cd ~/Projects/nixos
# Development tools are now available- Edit
machines/<name>/configuration.nix - Add to
environment.systemPackagesor relevant option - Build and test:
nixos-rebuild build --flake .#<name>
- Create module in
modules/nixos/<name>/default.nix - Import in
modules/nixos/default.nix - Add to appropriate module group (common, linux, server, etc.)
See NEW-MACHINE.md
See secrets.md