From 6b9f8e44c987461016b7e7a259b5783a5f9acc5f Mon Sep 17 00:00:00 2001 From: FUFSoB Date: Sun, 27 Sep 2026 17:56:54 +0500 Subject: [PATCH] fix: use disko for iso --- deploy/disk-layout.nix | 83 ++++++++++++++++++++++++++++++++++++ deploy/installer.nix | 12 ++---- deploy/installer.sh | 59 ++++++------------------- deploy/iso.nix | 19 ++++----- deploy/server-module.nix | 32 +++++++++++++- docs/usage/server.md | 5 ++- flake.lock | 21 +++++++++ flake.nix | 11 ++++- nix/checks.nix | 2 + nix/checks/lib.nix | 2 + nix/checks/module-suite.nix | 2 +- nix/checks/server-module.nix | 23 ++++++++-- 12 files changed, 199 insertions(+), 72 deletions(-) create mode 100644 deploy/disk-layout.nix diff --git a/deploy/disk-layout.nix b/deploy/disk-layout.nix new file mode 100644 index 0000000..c491c14 --- /dev/null +++ b/deploy/disk-layout.nix @@ -0,0 +1,83 @@ +# The disk layout of an installed server, for disko: GPT with a BIOS boot partition (GRUB +# on BIOS), an ESP on /boot (GRUB on UEFI) and btrfs over the rest, compressed, with a +# subvolume per mount point and a swap file. Subvolumes follow the @ convention: @ is /, +# @ the rest. services.proxy-suite-server.disko uses it +# for the installed system; proxy-suite-install passes it to the disko CLI to partition. +{ + device, + swapSize ? "2G", + ... +}: + +let + mountOptions = [ + "compress=zstd:3" + "noatime" + ]; +in +{ + disko.devices.disk.main = { + type = "disk"; + inherit device; + content = { + type = "gpt"; + partitions = { + bios = { + size = "1M"; + type = "EF02"; + priority = 1; + }; + ESP = { + size = "512M"; + type = "EF00"; + priority = 2; + content = { + type = "filesystem"; + format = "vfat"; + extraArgs = [ + "-n" + "ESP" + ]; + mountpoint = "/boot"; + mountOptions = [ "umask=077" ]; + }; + }; + root = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ + "-f" + "-L" + "nixos" + ]; + subvolumes = { + "@" = { + mountpoint = "/"; + inherit mountOptions; + }; + "@nix" = { + mountpoint = "/nix"; + inherit mountOptions; + }; + "@varlog" = { + mountpoint = "/var/log"; + inherit mountOptions; + }; + "@home" = { + mountpoint = "/home"; + inherit mountOptions; + }; + # btrfs filesystem mkswapfile makes the file NOCOW, so it is never compressed. + "@swap" = { + mountpoint = "/swap"; + mountOptions = [ "noatime" ]; + swap.swapfile.size = swapSize; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/deploy/installer.nix b/deploy/installer.nix index 780d701..de7b798 100644 --- a/deploy/installer.nix +++ b/deploy/installer.nix @@ -3,25 +3,23 @@ lib, writeShellApplication, xray, + disko, + diskLayout, flakeUrl, flakeSource, stateVersion, coreutils, curl, - dosfstools, - e2fsprogs, gawk, getent, gnugrep, gnused, - gptfdisk, iproute2, iputils, mkpasswd, nix, nixos-install-tools, openssl, - parted, systemd, util-linux, xkcdpass, @@ -33,20 +31,17 @@ import ./script.nix { inherit lib writeShellApplication; } { runtimeInputs = [ coreutils curl - dosfstools - e2fsprogs + disko gawk getent gnugrep gnused - gptfdisk iproute2 iputils mkpasswd nix nixos-install-tools openssl - parted systemd util-linux xkcdpass @@ -56,5 +51,6 @@ import ./script.nix { inherit lib writeShellApplication; } { PSI_FLAKE_URL = flakeUrl; PSI_FLAKE_SRC = "${flakeSource}"; PSI_STATE_VERSION = stateVersion; + PSI_DISK_LAYOUT = "${diskLayout}"; }; } diff --git a/deploy/installer.sh b/deploy/installer.sh index 92a3273..c1681f5 100644 --- a/deploy/installer.sh +++ b/deploy/installer.sh @@ -40,16 +40,7 @@ confirm_install() { step() { printf '\n\033[1;36m== %s ==\033[0m\n' "$*"; } -# nvme0n1 -> nvme0n1p1, vda -> vda1 -partition() { - if [[ $1 =~ [0-9]$ ]]; then - printf '%sp%s' "$1" "$2" - else - printf '%s%s' "$1" "$2" - fi -} - -# A stable name for GRUB, where the disk has one. +# A stable name for disko and GRUB, where the disk has one. stable_disk_path() { local link for link in /dev/disk/by-id/*; do @@ -204,7 +195,7 @@ show_summary() { net_summary="$NET_V4 via $NET_V4_GW${NET_V6:+, $NET_V6 via $NET_V6_GW} on $NET_IFACE ($NET_MAC)" fi cat </dev/null || true -wipefs -af "$DISK" -sgdisk --zap-all "$DISK" -sgdisk \ - -n 1:0:+1M -t 1:EF02 -c 1:bios \ - -n 2:0:+512M -t 2:EF00 -c 2:ESP \ - -n 3:0:0 -t 3:8300 -c 3:nixos \ - "$DISK" -# sgdisk has the kernel reread the table; wait for udev to finish recreating the -# partition nodes, or mkfs can write to a node that is about to be replaced. -udevadm settle -esp=$(partition "$DISK" 2) -root=$(partition "$DISK" 3) -for _ in {1..20}; do - [[ -b $esp && -b $root ]] && break - sleep 0.5 -done -wipefs -aq "$esp" "$root" -mkfs.vfat -F 32 -n ESP "$esp" -mkfs.ext4 -qF -L nixos "$root" -sync -udevadm settle -mount -t ext4 "$root" "$MNT" -mkdir -p "$MNT/boot" -mount -t vfat -o umask=077 "$esp" "$MNT/boot" +# The layout host.nix enables (services.proxy-suite-server.disko), mounted on $MNT. +disko --mode destroy,format,mount --yes-wipe-all-disks --root-mountpoint "$MNT" \ + --argstr device "$boot_disk" "$PSI_DISK_LAYOUT" -nixos-generate-config --root "$MNT" +# The filesystems and swap come from disko in host.nix, not from here. +nixos-generate-config --root "$MNT" --no-filesystems rm -f "$MNT/etc/nixos/configuration.nix" -# Evaluating NixOS takes more memory than the smallest VPS plans have. Added after -# nixos-generate-config, which would list it in swapDevices. -fallocate -l 2G "$MNT/.install-swap" -chmod 600 "$MNT/.install-swap" -mkswap "$MNT/.install-swap" >/dev/null -swapon "$MNT/.install-swap" +# Evaluating NixOS takes more memory than the smallest VPS plans have: the installed +# system's swap file, which disko made, serves the install too. +swapon "$MNT/swap/swapfile" # --- Secrets -------------------------------------------------------------------- step "Generating keys" @@ -300,7 +269,8 @@ cat >"$etc_nixos/host.nix" <