Deploy existing configuration.nix

Hi, how do I deploy my configuration.nix as quickly as possible by running a command from the live USB?
Also I’d like to include default partitioning to /dev/sda or /dev/nvme01 or whatever’s the internal SSD.

Essentially, essentially everything the installer already does, but with the help of my configuration.nix file.

No idea about the best, but shouldn’t be too hard to write a script:

  • Partition, e.g. sudo parted --script "${DISK}" -- mklabel gpt mkpart esp fat32 1MiB 1GiB mkpart primary ext4 1GiB 100% set 1 boot on
  • Mount the two partitions
  • Configure Networking (ethernet should work out of the box)
  • Add channels if you need them
  • Copy your config to the mount point (/mnt/etc/nixos/) and adjust it for hardware/filesystem
  • nixos-install

Here is an old, unnecessary convoluted script of mine, that you probably could use for inspiration.

There’s also more sophisticated methods, like creating a custom install image for the USB*, building once on another host and copying over the relevant nix store parts or something. Don’t know what the state of the art really is. Or you can use something like nixops, where I don’t know what the recommended initial, bare-metal provisioning method is to initialize the machine before you push the actual config.

*In a recent talk, I heard someone say that was an anti-pattern and there’s better ways, but he didn’t say what they are.

1 Like

I’d be quite curious to hear why that is, seems like the most sensible method to me. Writing a script and pre-installing it to a custom installer ISO, with pre-cached packages that you know you’ll install. Would be cool to have a community-maintained flake or something with helpers to let people do that kind of thing.

nixos-generators is a good place to start with these kinds of setups.