This is the repository where I define all my hosts on my server.
Install nix on your system.
To jump into the devshell: nix develop
-
To encrypt and decrypt files you have to create a PGP Key. Edit the .sops.yaml accordingly.
-
Update the sops keys
sops updatekeys {path/to/any/secrets.yaml}We use opentofu as our IaC tool.
- To provision the VM for the host, find it within:
/infra
tofu init
tofu plan -target=module.minecraft
tofu apply -target=module.minecraft- Pregenerate hostkeys
Pregenerate hostkeys using the hostkeys.sh. These will be copied to the target-machine.
The script prints an age-key which is created from the public host key.
- Update sops keys using the age key
Add the age-key to the .sops.yaml and run
sops updatekeys {path/to/any/secrets.yaml}- Deploy the Nixos-anywhere configuration to the provisioned VM
Don't forget to copy the host keys from the tmp directory to the target.
Note
I am using nix run github:nix-community/nixos-anywhere here as there seem to be issues with the pkgs.nixos-anywhere version when using --extra-files
nix run github:nix-community/nixos-anywhere -- --flake .#whatever --extra-files tmp/extra-files/ user@ip- Rebuild if you make any changes to the .nix files
If you make changes to the nix configurations, don't forget to rebuild the system:
nixos-rebuild boot --flake .#nextcloud --target-host "user@ip" --sudo --ask-sudo-password- Run the script
./rotate-keys.sh hostkey <name> <user>@<host>- Rebuild
nixos-rebuild boot --flake .#<name> --target-host "user@ip" --sudo --ask-sudo-password- Reboot & Delete old Keys
SSH on the system, reboot it. Then Delete the old keys (.bak) from /etc/ssh
./rotate-keys.sh paul-pgpTODO