Is there a way to do nixos-install on remote system?

As written in the title I’m looking for a way to push a Flake config to a server running the minimal ISO.
Is there an equivalent to --target-host for nixos-install?

1 Like

you can try GitHub - MatthewCroughan/nixinate: Another NixOS Deployment Tool - Nixinate your systems 🕶️

however it’s BETA! but it’s fun, it’s flake only and pure nix/bash , not a line of rust, python or anything else :-). You just need ssh access to a nixos system that has flakes enabled.

Hopefully it will do what you need, if it doesn’t, they will added it! (within reason).

Have fun!

Thank you for the input.
nixinate seems to be doing about the same things that I’m already doing just with rsync instead of git.
I currenly boot into the ISO, set an SSH password and then basically run the following commands

  1. nix-shell -p git --run "git clone https://git.2li.ch/Nebucatnetzer/nixos.git"
  2. cd nixos && nix-shell
  3. sudo python3 scripts/format-disk.py
  4. sudo nixos-install --no-root-passwd --root /mnt --impure --flake .#SYSTEMNAME

Afterwards I update the machines with nixos-rebuild --target-host but I was hoping that there is an inbuilt way to push the initial config.

2 Likes

Why not use something like https://github.com/cleverca22/nix-tests/blob/a9a316ad89bfd791df4953c1a8b4e8ed77995a18/kexec/justdoit.nix to brute-force install NixOS onto a given machine? All you need to do is generate an ISO which has this module in it, and justdoit.sh will be available to execute, which basically replaces your Python script with pure nix. This justdoit example requires ZFS and UEFI though, so it may not be suitable for you, but I have enjoyed using before. It should at least give you some ideas.

3 Likes

This inspired me to my current solution, since I actually want to run my Python script.
I add two small scripts to my repo.
One 1 which downloads the repo with curl so that I don’t have to use git and kicks off the actually install script 2 which then runs the disk setup script and installs the provided config.

Edit: Not 100% what I was looking for but good enough.

2 Likes

Maybe nixinate will get mainlined soon, so you be able just to nix inate a system, that does all this for you :-).

1 Like

The comment from @Majiir on https://github.com/NixOS/nixpkgs/issues/217891 provides a good solution as well, which does not involve building on the target device:

Run the following commands on the building device:

build$ nixos-rebuild build --flake <flake>
build$ nix-copy-closure --to <host> result

And on the target device:

host$ nixos-install --system <system-closure>

This is to me the best way to spread NixOS across computers, or to recover from a broken hard drive.

How does that work in terms of signatures? e.g. Nix store: copy vs sigs