From c226044528da391bdd82f4a22b72947c38889468 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Wed, 22 Apr 2026 20:34:53 +0200 Subject: [PATCH] Daidalos --- README.md | 117 +++++++++++++---------- modules/flake/lib.nix | 6 +- modules/hosts/daidalos/configuration.nix | 80 ++++++++++++++++ modules/hosts/daidalos/default.nix | 20 ++++ modules/hosts/daidalos/disko.nix | 116 ++++++++++++++++++++++ modules/hosts/daidalos/hardware.nix | 20 ++++ modules/hosts/default.nix | 2 +- 7 files changed, 309 insertions(+), 52 deletions(-) create mode 100644 modules/hosts/daidalos/configuration.nix create mode 100644 modules/hosts/daidalos/default.nix create mode 100644 modules/hosts/daidalos/disko.nix create mode 100644 modules/hosts/daidalos/hardware.nix diff --git a/README.md b/README.md index e5a5f0f..28c7bed 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,127 @@ # NixOS-konfiguration -Det här förrådet innehåller en flake-baserad NixOS-konfiguration för mina -maskiner. +Det här förrådet innehåller flake-baserade NixOS-konfigurationer. -Just nu finns värden `kronos`. +## Värdar -Punktfiler förväntas att finns under `~/dotfiles`, och hanteras med home manager +- `daidalos`: Raspberry Pi 4, `aarch64-linux`, ZFS-root, `extlinux` +- `hermes`: x86_64-server +- `kronos`: x86_64-desktop -## Flakes +## Ny installation: `daidalos` -Vi lever i framtiden, därför används flakes exklusivt. +De här stegen utgår från en helt ren maskin. Du behöver inte installera Nix +innan du börjar. NixOS-installationsmediet innehåller redan `nix`, +`nixos-install` och `nixos-generate-config`. -## För att installera +### Krav -1. Kontrollera att rätt disk (`installDisk`) är vald i `hosts/kronos/default.nix` -2. Generera en `hardware-configuration.nix`. Tag dock bort all information om filsystem. Disko sköter redan det åt oss. -3. Kontrollera `networking.hostId`. Bör vara unikt för nätverket. +- En Raspberry Pi 4 +- Ett separat microSD-kort med NixOS generiska `aarch64` SD-image +- En separat måldisk för systemet, helst en USB-SSD eller NVMe-adapter som + syns under `/dev/disk/by-id` +- Nätverksanslutning under installationen +- All data på måldisken raderas under installationen -### Applicera konfiguration +`daidalos` använder ZFS och refererar diskar via `/dev/disk/by-id`. Installera +inte på samma medium som du har bootat installationsmiljön från. -Sedan: +### 1. Boota installationsmediet + +1. Ladda ned NixOS generiska `aarch64` SD-image. +2. Skriv den till ett microSD-kort. +3. Starta Raspberry Pi 4 från kortet. +4. Om nätverket inte kommer upp automatiskt, kör `nmtui`. + +### 2. Hämta förrådet och välj måldisk ```bash sudo -i export NIX_CONFIG='experimental-features = nix-command flakes' cd /tmp -git clone nixcfg -cd nixcfg +nix shell nixpkgs#git -c git clone nixcfg +cd /tmp/nixcfg +ls -l /dev/disk/by-id +nix shell nixpkgs#openssl -c openssl rand -hex 4 +nix shell nixpkgs#nvim -c nvim modules/hosts/daidalos/configuration.nix ``` -Applicera disk-layouten: +Ändra sedan i `modules/hosts/daidalos/configuration.nix`: + +- Ersätt `REPLACE_ME` i `installDisk` med rätt disk från `/dev/disk/by-id` +- Sätt `networking.hostId` till en unik sträng med 8 hextecken, till exempel + värdet från `openssl rand -hex 4` + +### 3. Partitionera, formatera och montera måldisken ```bash -nix run github:nix-community/disko -- --mode disko .#kronos +nix run github:nix-community/disko -- --mode destroy,format,mount --flake .#daidalos ``` -Generera hårdvarufilen och kopiera in den i förrådet: +Kommandot raderar all data på måldisken och monterar systemet under `/mnt`. + +### 4. Generera `hardware.nix` för just den här maskinen ```bash -nixos-generate-config --root /mnt -cp /mnt/etc/nixos/hardware-configuration.nix ./hosts/kronos/hardware-configuration.nix +mkdir -p /tmp/hw +nixos-generate-config --root /mnt --dir /tmp/hw --no-filesystems +cp /tmp/hw/hardware-configuration.nix modules/hosts/daidalos/hardware.nix ``` -Kom ihåg att ta bort alla filesystemkonfiguration från `hardware-configuration.nix`. -Disko sköter ju redan det. +`--no-filesystems` är viktigt här. Disklayouten hanteras redan av `disko`. -Kopiera också över konfigurationen till målenheten +### 5. Kopiera konfigurationen och installera systemet ```bash -rm -rf /mnt/etc/nixos -cp -r /tmp/nixcfg /mnt/etc/nixos +mkdir -p /mnt/etc +cp -a /tmp/nixcfg /mnt/etc/nixos +nixos-install --root /mnt --flake /mnt/etc/nixos#daidalos ``` -Installera systemet: +`nixos-install` frågar efter ett root-lösenord för den installerade maskinen. -```bash -nixos-install --flake .#kronos -``` +### 6. Starta om -Registrera TPM-nyckeln: - -```bash -nixos-enter --root /mnt -./systemd-cryptenroll.sh -``` - -Starta om: +Ta bort installationskortet och starta om: ```bash reboot ``` -## Efter första uppstart - -```bash -git clone ~/dotfiles -``` +Om Pi:n inte bootar från måldisken efter installationen är firmware troligen +inte inställd för USB-boot ännu. Då behöver Raspberry Pi EEPROM uppdateras innan +systemet kan starta från en USB-disk. ## Vanligt underhåll -När systemet väl är installerat jobbar man oftast så här. +På en installerad maskin ligger konfigurationen under `/etc/nixos`. Uppdatera flake-låset: ```bash +cd /etc/nixos nix flake update ``` -Bygg och applicera ändringar på den lokala maskinen: +Bygg och aktivera konfigurationen: ```bash -sudo nixos-rebuild switch --flake .#kronos +cd /etc/nixos +sudo nixos-rebuild switch --flake .#daidalos ``` -Testa en konfiguration utan att göra den permanent vid nästa boot: +Testa utan att göra ändringen permanent över reboot: ```bash -sudo nixos-rebuild test --flake .#kronos +cd /etc/nixos +sudo nixos-rebuild test --flake .#daidalos ``` -Bygg bara, utan att byta system direkt: +Bygg bara: ```bash -sudo nixos-rebuild build --flake .#kronos +cd /etc/nixos +sudo nixos-rebuild build --flake .#daidalos ``` Rensa gamla generationer och oanvända paket: @@ -111,7 +130,7 @@ Rensa gamla generationer och oanvända paket: sudo nix-collect-garbage -d ``` -Kontrollera `ZFS`-snapshots: +Visa ZFS-snapshots: ```bash zfs list -t snapshot diff --git a/modules/flake/lib.nix b/modules/flake/lib.nix index 5d1a1a7..abd3b51 100644 --- a/modules/flake/lib.nix +++ b/modules/flake/lib.nix @@ -14,10 +14,11 @@ in disko, lolcat, nixosModules, + system ? "x86_64-linux", hostModules ? [ ], }: nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + inherit system; specialArgs = { inputs = inputs // { "lolcat++" = lolcat; @@ -33,10 +34,11 @@ in disko, lolcat, nixosModules, + system ? "x86_64-linux", hostModules ? [ ], }: nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + inherit system; specialArgs = { inputs = inputs // { "lolcat++" = lolcat; diff --git a/modules/hosts/daidalos/configuration.nix b/modules/hosts/daidalos/configuration.nix new file mode 100644 index 0000000..334c4ff --- /dev/null +++ b/modules/hosts/daidalos/configuration.nix @@ -0,0 +1,80 @@ +{ + lib, + pkgs, + nixosModules, + ... +}: +let + userName = "root"; + hostName = "Daidalos"; + installDisk = "/dev/disk/by-id/REPLACE_ME"; +in +{ + _module.args = { + inherit + userName + hostName + installDisk + ; + }; + + imports = [ + ./disko.nix + ./hardware.nix + nixosModules.base + nixosModules.binBashWrapper + ]; + + my.binBashWrapper.enable = true; + + boot = { + kernelPackages = pkgs.linuxPackages_rpi4; + supportedFilesystems = [ "zfs" ]; + zfs.devNodes = "/dev/disk/by-id"; + extraModprobeConfig = '' + options zfs zfs_arc_min=67108864 + options zfs zfs_arc_max=134217728 + ''; + loader = { + grub.enable = lib.mkForce false; + systemd-boot.enable = lib.mkForce false; + generic-extlinux-compatible.enable = true; + }; + }; + + services.zfs = { + autoScrub.enable = true; + trim.enable = false; + autoSnapshot.enable = false; + }; + + services.fstrim.enable = false; + + hardware.enableRedistributableFirmware = true; + hardware.deviceTree = { + enable = true; + filter = "*rpi-4-*.dtb"; + }; + + environment.systemPackages = with pkgs; [ + libraspberrypi + raspberrypi-eeprom + ]; + + networking.hostName = hostName; + networking.hostId = "69aaeea1"; + + systemd.network.networks."10-wired".matchConfig.Name = lib.mkForce [ + "en*" + "eth*" + "end0" + ]; + + zramSwap = { + enable = true; + memoryPercent = 50; + algorithm = "zstd"; + }; + + system.stateVersion = "25.05"; +} diff --git a/modules/hosts/daidalos/default.nix b/modules/hosts/daidalos/default.nix new file mode 100644 index 0000000..ff724ab --- /dev/null +++ b/modules/hosts/daidalos/default.nix @@ -0,0 +1,20 @@ +{ + inputs, + mkHost, + nixosModules, + ... +}: +let + host = mkHost { + nixpkgs = inputs.nixpkgs-stable; + disko = inputs.disko-stable; + lolcat = inputs."lolcat++-stable"; + system = "aarch64-linux"; + inherit nixosModules; + hostModules = [ ./configuration.nix ]; + }; +in +{ + Daidalos = host; + daidalos = host; +} diff --git a/modules/hosts/daidalos/disko.nix b/modules/hosts/daidalos/disko.nix new file mode 100644 index 0000000..e276703 --- /dev/null +++ b/modules/hosts/daidalos/disko.nix @@ -0,0 +1,116 @@ +{ installDisk, ... }: +{ + disko.devices = { + disk.main = { + type = "disk"; + device = installDisk; + content = { + type = "gpt"; + partitions = { + firmware = { + label = "FIRMWARE"; + size = "1G"; + type = "0700"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot/firmware"; + mountOptions = [ "umask=0077" ]; + }; + }; + + zfs = { + label = "zfs"; + size = "100%"; + content = { + type = "zfs"; + pool = "rpool"; + }; + }; + }; + }; + }; + + zpool.rpool = { + type = "zpool"; + + options = { + ashift = "12"; + autotrim = "on"; + }; + + rootFsOptions = { + acltype = "posixacl"; + atime = "off"; + compression = "lz4"; + dnodesize = "auto"; + mountpoint = "none"; + xattr = "sa"; + }; + + datasets = { + root = { + type = "zfs_fs"; + options.mountpoint = "none"; + }; + + "root/nixos" = { + type = "zfs_fs"; + mountpoint = "/"; + options = { + canmount = "noauto"; + mountpoint = "legacy"; + }; + postCreateHook = '' + zfs list -t snapshot -H -o name | grep -E '^rpool/root/nixos@blank$' \ + || zfs snapshot rpool/root/nixos@blank + ''; + }; + + home = { + type = "zfs_fs"; + mountpoint = "/home"; + options.mountpoint = "legacy"; + }; + + nix = { + type = "zfs_fs"; + mountpoint = "/nix"; + options = { + mountpoint = "legacy"; + "com.sun:auto-snapshot" = "false"; + primarycache = "metadata"; + }; + }; + + persist = { + type = "zfs_fs"; + mountpoint = "/persist"; + options.mountpoint = "legacy"; + }; + + var = { + type = "zfs_fs"; + options.mountpoint = "none"; + }; + + "var/log" = { + type = "zfs_fs"; + mountpoint = "/var/log"; + options.mountpoint = "legacy"; + }; + + "var/lib" = { + type = "zfs_fs"; + mountpoint = "/var/lib"; + options.mountpoint = "legacy"; + }; + + reserved = { + type = "zfs_volume"; + size = "1G"; + }; + }; + }; + }; +} diff --git a/modules/hosts/daidalos/hardware.nix b/modules/hosts/daidalos/hardware.nix new file mode 100644 index 0000000..3a2b0b1 --- /dev/null +++ b/modules/hosts/daidalos/hardware.nix @@ -0,0 +1,20 @@ +{ lib, modulesPath, ... }: +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ + "pcie_brcmstb" + "reset-raspberrypi" + "usbhid" + "usb_storage" + "vc4" + "xhci_pci" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux"; +} diff --git a/modules/hosts/default.nix b/modules/hosts/default.nix index 1fffd54..649a205 100644 --- a/modules/hosts/default.nix +++ b/modules/hosts/default.nix @@ -1 +1 @@ -args: (import ./hermes args) // (import ./kronos args) +args: (import ./daidalos args) // (import ./hermes args) // (import ./kronos args)