Build and test NixOS before deployment

I use nixos-rebuild build-vm, as @lovirent mentions, but that indeed does not work on non-NixOS systems.

If I wanted to support non-NixOS systems, I’d add an app to my flake that builds a generic qemu image using nixos-generators and then runs it with a simple script. Which is basically what nixos-rebuild build-vm does, except it doesn’t rely on the host having a nix store.

Or just switch to NixOS for development, build-vm is incredibly useful. You can still write a custom script for convenient access via a nix flake, in this case I make some small changes (e.g. not including hardware-configuration.nix) to the VM target so that I can test the software without having underlying hardware/networking quirks get in the way.


If you want to run tests, that’s an option too. There’s even a convenient helper library in the nixpkgs repo, though it’s not really designed to help test a system configuration. Still, I’ve written an integration test or two with that before.

You might also find deploy-rs with its auto-rollback and pre-deployment test features interesting.

1 Like