-
Create a ssh keypair for the target machine
# use a ramfs to not store the key in the disk mkdir -p /tmp/pki/ram && sudo mount -t tmpfs -o size=10M tmpfs /tmp/pki/ram mkdir -p /tmp/pki/ram/etc/ssh && cd /tmp/pki/ram/etc/ssh ssh-keygen -t ed25519 -C <some comment> -f ssh_host_ed25519_key ssh-keygen -t rsa -C <some comment> -f ssh_host_rsa_key
-
Generate an age recipient using the above public key (using the ssh-to-age tool)
ssh-to-age -i ssh_host_ed25519_key.pub -o ssh_host_ed25519_key.pub.age ssh-to-age -private-key -i ssh_host_ed25519_key -o ssh_host_ed25519_key.age
-
Update the .sops.yaml configuration file adding the age recipient.
-
Generate secrets for this machine using both the root and your key recipients. Example for the OS user:
# copy the following command output openssl passwd -6 # Add or edit the secrets.yaml file sops system/<machine-name>/secrets.yaml
-
Based on an existent configuration, create a new one under the system, e.g.,
./system/<machine-name>/default.nix
. Pay attention to the Disko configuration file to avoid any hard-to-recover mistakes. -
Same as above but with home-manager configurations, under users, e.g.,
./users/<user-name>/<machine-name>.nix
-
Boot the new machine using nixos-anywhere. Eventually, you would need to install rsync,
nix-env -iA nixos.rsync
in the target machine. -
Run nixos-anywhere in the host machine, including the SSH keys generated as preconditions.
tree /tmp/pki/ram /tmp/pki/ram └── etc └── ssh ├── ssh_host_ed25519_key ├── ssh_host_ed25519_key.age.pub └── ssh_host_ed25519_key.pub # copy the pub keys as part of the new machine's configuration cp /tmp/pki/ram/etc/ssh/*pub ./system/<machine-name> nix run github:nix-community/nixos-anywhere -- \ --flake .#<machine-name> \ --extra-files /tmp/pki/ram root@<new-machine-ip>
-
Once finished, login in to the new machine, clone the repo and run home-manager
ssh <user-name>@<new-machine-ip> git clone https://github.com/szaffarano/nix-dotfiles .dotfiles cd .dotfiles home-manager switch --flake .
-
Build RPI image
nix build '.#nixosConfigurations.<name>.config.system.build.sdImage'
-
Flash the image
unzstd result/sd-image/nixos-sd-image-....img.zst -c > nixos-sd-image.img dd if=nixos-sd-image.img | pv | sudo dd of=/dev/mmcblk0 bs=64k
-
After booting, update the ssh keys
# mount the NIXOS_SD partition sudo cp /tmp/pki/ram/ssh/... /nixos/partition/etc/ssh/...
-
Remote deploy
nixos-rebuild switch --flake .#<name> --target-host sebas@<ip> --use-remote-sudo