An example NixOS configuration for a NAS that runs the nixos-homelab modules on a single-node k3s cluster: media, monitoring, finance and personal apps, with ZFS storage and WireGuard VPNs.
Every parameter is a placeholder (example.org, documentation IP ranges,
all-zero WireGuard keys, an SSH key nobody holds), so it evaluates and runs in
a VM, but it can't take over a real NAS until you replace them. Read it as a
starting point for your own configuration; the options are documented in each
repository.
nix/hosts/nas/: the NAS on real hardware, and in two VMs that stand in for it.nix/profiles/role/nas/: what the NAS runs, in all three. Storage, cluster, networking and apps each have a file.nix/profiles/target/: what differs between the hardware and the VMs.nix/profiles/installer/: the installer ISO and a VM to run it in.
The NAS in a VM, from a prebuilt disk image (log in as admin, password
test):
nix run .#nas-prebuiltAn unattended install of the NAS into a VM:
nix run .#nas-installer- Replace the placeholders: the host and cluster domains in
nix/hosts/nas/, the SSH key innix/profiles/base.nix, the addresses and keys innix/profiles/role/nas/networking.nix, the accounts innix/profiles/role/nas/workloads.nix,repoUrlinnix/profiles/installer/iso.nix. - Build the installer ISO with
nix build .#installer-isoand install from it. - Make the encrypted ZFS pools
clusterandmediaand their datasets, the waynix/hosts/nas/vm-prebuilt.nixdoes on the disks of the VM. - setup-secrets asks for the admin password, the pool keys, the WireGuard and DNS provider keys and the rest, and puts each where it belongs.
- Deploy changes from the devshell (
nix develop) withdeploy.
nix flake check validates the manifests the NAS sends to k3s against the
Kubernetes and CRD schemas, and that every image comes preloaded from Nix. It
also boots the prebuilt VM under the NixOS test driver
(nix/tests/nas-prebuilt.py) and checks storage, networking, k3s, the apps
and a reboot. It needs KVM.
To work on the tests, keep the VM running and send it scripts from the devshell:
vm-test start nas
vm-test exec nas <<<'nas.succeed("zpool status")'
vm-test stop nas