From 0ff78c684890785c92654d9edab0146fbecefe74 Mon Sep 17 00:00:00 2001 From: moons Date: Wed, 2 Sep 2026 21:36:23 +0900 Subject: [PATCH] nix-builder disko --- AGENTS.md | 22 ++++--- hosts/nix-builder/disko.nix | 66 ++++++++++++++++++++ hosts/nix-builder/filesystem.nix | 25 -------- hosts/nix-builder/hardware-configuration.nix | 14 ----- hosts/nix-builder/nixos.nix | 2 +- 5 files changed, 82 insertions(+), 47 deletions(-) create mode 100644 hosts/nix-builder/disko.nix delete mode 100644 hosts/nix-builder/filesystem.nix diff --git a/AGENTS.md b/AGENTS.md index 7bd9027..b163b8e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -653,7 +653,8 @@ A host registry may use a specification like this: The current role assignment is intentional: nix-example is the development VM; ops is the remote-access VM with host-specific static networking; -internal-app-01 is the container server VM; and installer builds the minimal +internal-app-01 is the container server VM; nix-builder is the remote Nix build +VM with dedicated build and store disks; and installer builds the minimal installation ISO without Home Manager. x1g9 is a full NixOS desktop with niri, labwc, ly, the shared Linux desktop applications, and the personal workload. x1g13 is the secure NixOS development and personal ThinkPad, with the same @@ -692,6 +693,10 @@ configuration fragments. For example: ```text hosts/ +├── nix-builder/ +│ ├── disko.nix +│ ├── hardware-configuration.nix +│ └── nixos.nix ├── installer/ │ └── nixos.nix ├── internal-app-01/ @@ -721,12 +726,15 @@ hosts/ ``` `hosts/x1g9/nixos.nix` explicitly loads `hardware-configuration.nix` with the -normal top-level Nix module `imports`. `hosts/x1g13/nixos.nix` loads its -generated hardware configuration and host-local `disko.nix` the same way. Do -not confuse these host imports with the prohibition on top-level `imports` in -unit configuration fragments. `hosts/galleria/disko.nix` manages only the two -dedicated NixOS partitions by PARTUUID and deliberately excludes the Windows -disk, Windows partitions, and the Windows EFI System Partition. +normal top-level Nix module `imports`. `hosts/nix-builder/nixos.nix` and +`hosts/x1g13/nixos.nix` load their generated hardware configuration and +host-local `disko.nix` the same way. The nix-builder Disko definition mounts its +existing VM filesystems by stable QEMU SCSI IDs and does not take destructive +ownership of them. Do not confuse these host imports with the prohibition on +top-level `imports` in unit configuration fragments. `hosts/galleria/disko.nix` +manages only the two dedicated NixOS partitions by PARTUUID and deliberately +excludes the Windows disk, Windows partitions, and the Windows EFI System +Partition. Derive the system class from the host's `system`: diff --git a/hosts/nix-builder/disko.nix b/hosts/nix-builder/disko.nix new file mode 100644 index 0000000..40ed703 --- /dev/null +++ b/hosts/nix-builder/disko.nix @@ -0,0 +1,66 @@ +_: +let + osDisk = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0"; +in +{ + disko.enableConfig = true; + + # The VM disks already contain live filesystems. Model each existing + # filesystem without giving Disko ownership of their partitioning or data. + disko.devices.disk = { + boot = { + type = "disk"; + device = "${osDisk}-part1"; + destroy = false; + + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + + root = { + type = "disk"; + device = "${osDisk}-part2"; + destroy = false; + + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + + nix-build = { + type = "disk"; + device = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi1"; + destroy = false; + + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/var/lib/nix-build"; + mountOptions = [ "noatime" ]; + }; + }; + + nix-store = { + type = "disk"; + device = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi2"; + destroy = false; + + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/nix/store"; + mountOptions = [ "noatime" ]; + }; + }; + }; + + fileSystems."/nix/store".neededForBoot = true; + nix.settings.build-dir = "/var/lib/nix-build"; + services.fstrim.enable = true; +} diff --git a/hosts/nix-builder/filesystem.nix b/hosts/nix-builder/filesystem.nix deleted file mode 100644 index 518a261..0000000 --- a/hosts/nix-builder/filesystem.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ - fileSystems."/nix/store" = { - device = "/dev/disk/by-label/nix-store"; - fsType = "ext4"; - - options = [ - "noatime" - ]; - - neededForBoot = true; - }; - - fileSystems."/var/lib/nix-build" = { - device = "/dev/disk/by-label/nix-build"; - fsType = "ext4"; - - options = [ - "noatime" - ]; - }; - - nix.settings.build-dir = "/var/lib/nix-build"; - - services.fstrim.enable = true; -} diff --git a/hosts/nix-builder/hardware-configuration.nix b/hosts/nix-builder/hardware-configuration.nix index 564b4b4..deb4a1b 100644 --- a/hosts/nix-builder/hardware-configuration.nix +++ b/hosts/nix-builder/hardware-configuration.nix @@ -20,20 +20,6 @@ boot.kernelModules = [ ]; boot.extraModulePackages = [ ]; - fileSystems."/" = { - device = "/dev/disk/by-uuid/49fc2e1c-7909-41cc-ac78-55b4d9a01e62"; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-uuid/40D4-ABBE"; - fsType = "vfat"; - options = [ - "fmask=0077" - "dmask=0077" - ]; - }; - swapDevices = [ ]; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; diff --git a/hosts/nix-builder/nixos.nix b/hosts/nix-builder/nixos.nix index 7d423ac..801bc3e 100644 --- a/hosts/nix-builder/nixos.nix +++ b/hosts/nix-builder/nixos.nix @@ -1,6 +1,6 @@ { imports = [ - ./filesystem.nix + ./disko.nix ./hardware-configuration.nix ]; }