User Tools

Site Tools


tech:cheatsheets:linux:nixos

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tech:cheatsheets:linux:nixos [2025/02/21 18:01] waldemartech:cheatsheets:linux:nixos [2025/05/07 04:55] (current) – [System is not lustrated] waldemar
Line 6: Line 6:
 ==== Infect system using nixos-infect ==== ==== Infect system using nixos-infect ====
 Ensure you're root when executing the commands (''sudo -i'') Ensure you're root when executing the commands (''sudo -i'')
 +
 +<note important>
 +If any profile is installed for root (re)move the existing profile at ''/nix/var/nix/profiles/per-user/root'' before infecting.
 +</note>
 +
 <code bash> <code bash>
 touch /etc/ssh/ssh_host_placeholder_key touch /etc/ssh/ssh_host_placeholder_key
Line 12: Line 17:
  
 ==== Apply configuration ==== ==== Apply configuration ====
-First check-out desired configuration into ''/etc/nixos''.+Check-out your desired configuration into ''/etc/nixos'' and adjust it.
 <code bash> <code bash>
-# Change owner to primary user if you want to edit it from the primary user 
-chown -R 1000:1000 /etc/nixos 
 git clone <NIXOS-GIT-REPOSITORY> /etc/nixos 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 -I nixpkgs=$(realpath $HOME/.nix-defexpr/channels/nixos) -I nixos-config=/etc/nixos/configuration.nix'
 </code> </code>
  
-Then restart system once so NixOS replaces the currently installed system+Add directories and files you want to keep to ''/etc/NIXOS_LUSTRATE''. These directories and files will not be moved into ''/old-root'' upon replacement
-Afterwards boot another NixOS system (e.g. from another partition or live CD) to adjust system configuration for example LUKS partitions.+ 
 +Also ensure that if your primary partition is an encrypted partition to add relevant configuration to your ''hardware-configuration.nix''
 + 
 +==== 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. 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.
Line 46: Line 70:
 # nixos-rebuild boot # nixos-rebuild boot
 </code> </code>
 +
 +===== Troubleshooting =====
 +==== System is not lustrated ====
 +For some reason a system is not lustrated (NOTE: system must boot via GRUB for lustrate to work aparently). If that happens a boot might fail due to systemd not finding ''default.target''.
 +If that happens a manual lustration might help (= move files manually from root into subfolder).
 +
 +Apparently systemd must also not be enabled in initrd for it work.
tech/cheatsheets/linux/nixos.1740160911.txt.gz · Last modified: by waldemar

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki