Skip to article frontmatterSkip to article content

NixOS Flakes❄️

automatisierte VM Installation mittels NixOS Flakes

NixOS Installation

Für die Installation via NixOS Flakes muss ein Git-Repo mit den entsprechenden Dateien erstellt werden. Das Repo wird dann in die laufende ISO geclont und die Nix Installation gestartet. Damit die Installation noch einfacher abläuft, wurde das install.sh script erstellt um die Installation automatisiert ablaufen zu lassen. Ohne das Script muss die Partitionierung von Hand erfolgen und auch die mount-Pfade müssen erstellt werden.

Das Script installiert NixOS automatisch auf vdb, sollte eure Festplatte anders heißen, muss dies im install.sh angepasst werden.

manuele Schritte

1. Festplatte formatieren und mounten

parted /dev/vdb -- mklabel gpt
parted /dev/vdb -- mkpart ESP fat32 1MiB 513MiB
parted /dev/vdb -- set 1 esp on
parted /dev/vdb -- mkpart primary 513MiB 100%
mkfs.vfat -F32 -n EFI /dev/vdb1
mkfs.ext4 -L nixos /dev/vdb2
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/EFI /mnt/boot

2. nixos Hardware Konfiguration erstellen

nixos-generate-config --root /mnt --show-hardware-config > /mnt/etc/nixos/hosts/nix-host1/hardware-configuration.nix

3. git clone

git clone --config core.sshCommand="ssh -i ~/.ssh/key -p 222" ssh://git@git.DEINREPO/nixos-flakes.git /mnt/etc/nixos

4. Installation starten

nixos-install --flake /mnt/etc/nixos#nix-host1

Git Repo Struktur

nixos-flakes
├─ flake.nix
├─ nixos-setup.sh
├─ .gitignore
├─ README.md
└─ hosts/
   └─ nix-host1/
      ├─ configuration.nix
      └─ hardware-configuration.nix

Dateien

flake.nix Konfig

install.sh Script

Host Konfig