This is an old revision of the document!
Table of Contents
NixOS
Install in-place
Infect system using nixos-infect
Ensure you're root when executing the commands (sudo -i)
touch /etc/ssh/ssh_host_placeholder_key curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-24.11 NO_REBOOT=1 bash -x
Apply configuration
Check-out your desired configuration into /etc/nixos and adjust it.
git clone <NIXOS-GIT-REPOSITORY> /etc/nixos /nix/var/nix/profiles/per-user/root/profile/bin/nix-shell \ -I nixpkgs=$(realpath $HOME/.nix-defexpr/channels/nixos) \ -p nixos-install-tools \ --run 'nixos-generate-config --show-hardware-config' \ > /etc/nixos/hardware-configuration.nix # If your configuration is flake-based /nix/var/nix/profiles/per-user/root/profile/bin/nix-shell \ -I nixpkgs=$(realpath $HOME/.nix-defexpr/channels/nixos) \ -p nixos-rebuild \ --run 'nixos-rebuild boot --flake /etc/nixos' # For legacy configurations /nix/var/nix/profiles/per-user/root/profile/bin/nix-shell \ -I nixpkgs=$(realpath $HOME/.nix-defexpr/channels/nixos) \ -p nixos-rebuild \ --run 'nixos-rebuild boot --file /etc/nixos'
Add directories and files you want to keep to /etc/NIXOS_LUSTRATE. This directories and files will not be moved into /old-root upon replacement.
Rescue
Should the system not boot you can use another NixOS system (e.g. from another partition or live CD) to adjust system configuration for example LUKS partitions.
When second NixOS system is booted mount your system into /mnt including additional partitions like boot partition (into their respective directories). Afterwards invoke nixos-enter to enter a shell simulating the future NixOS system.
mount /dev/disk/by-id/xxxx-part1 /mnt mount /dev/disk/by-id/xxxx-part2 /mnt/boot nixos-enter
Now adjust your configuration to add/support this system and its hardware. Also keep in mind that if you're using LUKS for your primary partition/disk you need to manually add it to the generated hardware configuration to support it.
# Adjust files in /etc/nixos to support this system nixos-generate-config > /etc/nixos/hardware-configuration.nix
Now activate the configuration on next boot.
nix-env --set \ -I nixpkgs=$(realpath $HOME/.nix-defexpr/channels/nixos) \ -f '<nixpkgs/nixos>' \ -p /nix/var/nix/profiles/system \ -A system /nix/var/nix/profiles/system/bin/switch-to-configuration boot # this might also work instead of the above commands # nixos-rebuild boot