↓ Skip to main content
  1. Posts/

nixconf: My Declarative Multi-Host NixOS & Home Manager Setup

Virgola
Author
Virgola
AI & Cybersecurity MSc Student @ University of Udine X University of Klagenfurt.
Systems, NixOS & Go enthusiast | CTF player @ MadrHacks
Table of Contents

Keeping laptops, workstations, headless servers, VMs, and single-board computers in sync by hand always ends in configuration drift. To keep every machine reproducible and tracked in Git, I put together nixconf, a modular NixOS and Home Manager flake built with flake-parts and nixos-unstable.

Multi-host targets
#

One repository builds seven targets across x86_64-linux and aarch64-linux:

HostArchRoleDisk / Boot
laptopx86_64-linuxPrimary laptop (AMD + Nvidia PRIME, MangoWM, gaming, security)UEFI systemd-boot, LUKS + Btrfs (_disko.nix)
desktopx86_64-linuxWorkstation without laptop or Nvidia quirksUEFI systemd-boot, Btrfs via disko
vmx86_64-linuxGraphical QEMU/KVM VM (MangoWM, SPICE, VS Code Server)GRUB, qemu-guest, _disko.nix available
vm-minimalx86_64-linuxHeadless CLI-only VM for fast evaluation and testingGRUB + EFI, disko ext4
serverx86_64-linuxHeadless homelab server (Docker, Tailscale, hardened SSH)UEFI systemd-boot, disko Btrfs
raspberrypiaarch64-linuxRaspberry Pi 4 headless server (nixos-hardware + SD image)sd-image-aarch64 (nix build .#raspberrypi-sd)
isox86_64-linuxCustom live/rescue USB with disko, ninit, kssh, disk toolsBootable ISO (nix build .#iso)

Layout and auto-imported flake-parts
#

Instead of listing every module manually in flake.nix, the root flake uses lib.fileset to auto-import every .nix file outside templates/ and home/, skipping flake.nix and _-prefixed files like _disko.nix:

flowchart TD
  F["flake.nix (flake-parts)"] --> C["Core, Desktop and Headless Modules"]
  F --> H["Home Manager + wrapper-modules"]
  F --> P["Custom Packages (ninit, ssh-vault)"]
  C --> T["7 Targets (laptop, desktop, VMs, server, RPi4, ISO)"]
  H --> T
  P --> T
nixconf/
├── flake.nix                  # Flake inputs (nixpkgs, home-manager, disko, nixos-hardware)
├── bootstrap.sh               # Interactive installer and host provisioning script
├── lib/                       # Supported systems, formatter, lint checks, devShell, templates
├── home/                      # Home Manager modules (core CLI + desktop dotfiles)
├── wrappedPrograms/           # Standalone wrapped apps (myKitty, myMango, myNiri, myNoctalia)
├── packages/                  # Custom packages (ninit, keyhints, kssh, ssh-vault, mtp, tunnelmole)
├── templates/                 # 27 project templates for `ninit` / `nix flake init`
└── nixos/
    ├── settings.nix           # User identity, SSH keys, locale, and theme options
    ├── features/
    │   ├── core/              # Headless-safe base OS, Home Manager wiring, desktop base
    │   ├── system/            # Display sessions & hardware (mangowm, niri, noctalia, laptop, nvidia, wireguard)
    │   ├── services/          # Single-purpose services (tailscale, mullvad, ollama, docker, virtualisation)
    │   └── apps/              # desktopApps, dev (lean), security, gaming, vr, android, antigravity
    └── hosts/                 # Per-machine assemblies and _disko.nix layouts

Design choices
#

Hybrid Home Manager and wrapper-modules
#

Home Manager (nixosModules.home-manager) manages user dotfiles (zsh, git, ssh, direnv, gtk, dconf, zathura, and Kitty SSH profiles). Graphical tools like myKitty, myMango (MangoWM Wayland compositor), myNiri, and myNoctalia live in wrappedPrograms/ via nix-wrapper-modules as standalone binaries, which keeps their configuration out of Home Manager’s way.

Headless and graphical split
#

nixos/features/core/base.nix is headless-safe so servers, vm-minimal, and the Raspberry Pi 4 do not pull in audio or GUI dependencies. PipeWire, fonts, NetworkManager, Polkit, and desktop tools stay isolated in nixos/features/core/desktop.nix.

CUDA isolation and on-demand Ollama
#

nvidia.nix sets custom.enableCuda = true. Services and apps like ollama.nix and Blender check this flag so hosts without an Nvidia GPU never download CUDA packages. On the laptop, Ollama has CUDA enabled but stays stopped at boot (0 VRAM idle) and is started or stopped on demand with ollama-up, ollama-down, and ollama-stat.

Minimal global dev packages and ninit
#

Global tools in apps/dev.nix stay minimal (uv, python3, vscode, antigravity, docker, gcc, cmake). Language and domain toolchains (Rust, Go, LaTeX, Embedded, SDR, CTF) live in templates/ as 27 flake templates loaded per directory via direnv.

To speed up starting new projects, I wrote ninit (packages/ninit.nix), a Python CLI using rich and questionary. You can browse templates interactively or call an alias directly (ninit rust my-crate, ninit ctf-pwn challenge1). It runs nix flake init -t, initializes Git with a .gitignore that includes .direnv/, and runs direnv allow.

Security, CTF tooling, and ssh-vault
#

For Capture The Flag competitions and reverse engineering, nixos/features/apps/security.nix installs ghidra, pwndbg, pwninit, pwntools, ropper, ropgadget, one_gadget, seccomp-tools, imhex, rizin, radare2, non-root wireshark/dumpcap, burpsuite, sage, mtp, and tunnelmole.

To avoid storing unencrypted SSH private keys on disk across machines, packages/ssh-vault.nix provides ssh-vault-add, ssh-vault-load, and ssh-vault-list on top of rbw and bitwarden-cli (bw). Keys stay in Bitwarden or Vaultwarden and are piped straight into ssh-agent when needed.

Provisioning, remote deploys, and CI
#

  • bootstrap.sh works with per-host _disko.nix layouts to partition disks (LUKS + Btrfs with zstd subvolumes or ext4), generate hardware configs, and run nixos-install in one pass (./bootstrap.sh --host server --disko).
  • The flake exposes nix build .#iso for a custom rescue USB, nix build .#raspberrypi-sd for an aarch64 Pi 4 image, and nix run .#deploy -- server for remote deployments over SSH or Tailscale.
  • A pre-commit hook and GitHub Actions CI run alejandra (nix fmt), statix, deadnix, nix flake check, template evaluation checks, security scans, and image builds.

Repository links#

Related