fix: use disko for iso

This commit is contained in:
FUFSoB committed 2026-09-27 18:04:01 +05:00
1 parent a24d2a976b
commit 6b9f8e44c9
12 files changed
+199 -72

No files matched your search

+83
View File
@@ -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 /,
# @<name> 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;
};
};
};
};
};
};
};
}
+4 -8
View File
@@ -3,25 +3,23 @@
lib, lib,
writeShellApplication, writeShellApplication,
xray, xray,
disko,
diskLayout,
flakeUrl, flakeUrl,
flakeSource, flakeSource,
stateVersion, stateVersion,
coreutils, coreutils,
curl, curl,
dosfstools,
e2fsprogs,
gawk, gawk,
getent, getent,
gnugrep, gnugrep,
gnused, gnused,
gptfdisk,
iproute2, iproute2,
iputils, iputils,
mkpasswd, mkpasswd,
nix, nix,
nixos-install-tools, nixos-install-tools,
openssl, openssl,
parted,
systemd, systemd,
util-linux, util-linux,
xkcdpass, xkcdpass,
@@ -33,20 +31,17 @@ import ./script.nix { inherit lib writeShellApplication; } {
runtimeInputs = [ runtimeInputs = [
coreutils coreutils
curl curl
dosfstools disko
e2fsprogs
gawk gawk
getent getent
gnugrep gnugrep
gnused gnused
gptfdisk
iproute2 iproute2
iputils iputils
mkpasswd mkpasswd
nix nix
nixos-install-tools nixos-install-tools
openssl openssl
parted
systemd systemd
util-linux util-linux
xkcdpass xkcdpass
@@ -56,5 +51,6 @@ import ./script.nix { inherit lib writeShellApplication; } {
PSI_FLAKE_URL = flakeUrl; PSI_FLAKE_URL = flakeUrl;
PSI_FLAKE_SRC = "${flakeSource}"; PSI_FLAKE_SRC = "${flakeSource}";
PSI_STATE_VERSION = stateVersion; PSI_STATE_VERSION = stateVersion;
PSI_DISK_LAYOUT = "${diskLayout}";
}; };
} }
+14 -45
View File
@@ -40,16 +40,7 @@ confirm_install() {
step() { printf '\n\033[1;36m== %s ==\033[0m\n' "$*"; } step() { printf '\n\033[1;36m== %s ==\033[0m\n' "$*"; }
# nvme0n1 -> nvme0n1p1, vda -> vda1 # A stable name for disko and GRUB, where the disk has one.
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.
stable_disk_path() { stable_disk_path() {
local link local link
for link in /dev/disk/by-id/*; do 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)" net_summary="$NET_V4 via $NET_V4_GW${NET_V6:+, $NET_V6 via $NET_V6_GW} on $NET_IFACE ($NET_MAC)"
fi fi
cat <<SUMMARY cat <<SUMMARY
Disk $DISK (everything on it is erased) Disk $DISK (everything on it is erased; btrfs, 2G swap file)
Network $net_summary Network $net_summary
DNS $NET_DNS DNS $NET_DNS
Public IP $PUBLIC_IP Public IP $PUBLIC_IP
@@ -228,42 +219,20 @@ done
# --- Partition ------------------------------------------------------------------ # --- Partition ------------------------------------------------------------------
step "Partitioning $DISK" step "Partitioning $DISK"
boot_disk=$(stable_disk_path "$DISK")
swapoff -a || true swapoff -a || true
umount -R "$MNT" 2>/dev/null || true umount -R "$MNT" 2>/dev/null || true
wipefs -af "$DISK" # The layout host.nix enables (services.proxy-suite-server.disko), mounted on $MNT.
sgdisk --zap-all "$DISK" disko --mode destroy,format,mount --yes-wipe-all-disks --root-mountpoint "$MNT" \
sgdisk \ --argstr device "$boot_disk" "$PSI_DISK_LAYOUT"
-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"
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" rm -f "$MNT/etc/nixos/configuration.nix"
# Evaluating NixOS takes more memory than the smallest VPS plans have. Added after # Evaluating NixOS takes more memory than the smallest VPS plans have: the installed
# nixos-generate-config, which would list it in swapDevices. # system's swap file, which disko made, serves the install too.
fallocate -l 2G "$MNT/.install-swap" swapon "$MNT/swap/swapfile"
chmod 600 "$MNT/.install-swap"
mkswap "$MNT/.install-swap" >/dev/null
swapon "$MNT/.install-swap"
# --- Secrets -------------------------------------------------------------------- # --- Secrets --------------------------------------------------------------------
step "Generating keys" step "Generating keys"
@@ -300,7 +269,8 @@ cat >"$etc_nixos/host.nix" <<HOST
services.proxy-suite-server = { services.proxy-suite-server = {
enable = true; enable = true;
bootDisk = $(nix_str "$(stable_disk_path "$DISK")"); bootDisk = $(nix_str "$boot_disk");
disko.enable = true;
adminUser = $(nix_str "$ADMIN_USER"); adminUser = $(nix_str "$ADMIN_USER");
sshPort = $SSH_PORT; sshPort = $SSH_PORT;
$(print_network_nix " ") $(print_network_nix " ")
@@ -375,8 +345,7 @@ password=${password,,}
hash=$(mkpasswd -m yescrypt --stdin <<<"$password") hash=$(mkpasswd -m yescrypt --stdin <<<"$password")
nixos-enter --root "$MNT" -- usermod -p "$hash" "$ADMIN_USER" nixos-enter --root "$MNT" -- usermod -p "$hash" "$ADMIN_USER"
swapoff "$MNT/.install-swap" swapoff "$MNT/swap/swapfile"
rm -f "$MNT/.install-swap"
# --- Done ----------------------------------------------------------------------- # --- Done -----------------------------------------------------------------------
clear clear
+9 -10
View File
@@ -22,18 +22,10 @@ let
{ {
networking.hostName = "proxy-template"; networking.hostName = "proxy-template";
system.stateVersion = config.system.nixos.release; system.stateVersion = config.system.nixos.release;
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
options = [ "umask=077" ];
};
services.proxy-suite-server = { services.proxy-suite-server = {
enable = true; enable = true;
bootDisk = "/dev/vda"; bootDisk = "/dev/vda";
disko.enable = true;
network = { network = {
mac = "52:54:00:00:00:01"; mac = "52:54:00:00:00:01";
ipv4 = { ipv4 = {
@@ -58,6 +50,8 @@ let
installer = pkgs.callPackage ./installer.nix { installer = pkgs.callPackage ./installer.nix {
xray = import ../pkgs/xray.nix { inherit pkgs; }; xray = import ../pkgs/xray.nix { inherit pkgs; };
inherit (self.inputs.disko.packages.${system}) disko;
diskLayout = ./disk-layout.nix;
# A github ref only for a clean, committed tree; the installer falls back to the # A github ref only for a clean, committed tree; the installer falls back to the
# copy in PSI_FLAKE_SRC when it cannot be fetched (e.g. not pushed yet). # copy in PSI_FLAKE_SRC when it cannot be fetched (e.g. not pushed yet).
flakeUrl = lib.optionalString (self ? rev) "github:FUFSoB/proxy-suite-flake/${self.rev}"; flakeUrl = lib.optionalString (self ? rev) "github:FUFSoB/proxy-suite-flake/${self.rev}";
@@ -70,7 +64,12 @@ in
isoImage = { isoImage = {
edition = "proxy-suite"; edition = "proxy-suite";
storeContents = [ template.config.system.build.toplevel ] ++ lib.unique (inputSources self); # The template's disko script brings the partitioning tools (btrfs-progs, sgdisk...).
storeContents = [
template.config.system.build.toplevel
template.config.system.build.diskoScript
]
++ lib.unique (inputSources self);
}; };
# The same stack the installed system uses, so settings tested here carry over. # The same stack the installed system uses, so settings tested here carry over.
+30 -2
View File
@@ -2,7 +2,7 @@
# certificates (for the domain, or the bare IP), SSH, and networking pinned to the # certificates (for the domain, or the bare IP), SSH, and networking pinned to the
# uplink's MAC. Written for the installer ISO (deploy/iso.nix), which fills in # uplink's MAC. Written for the installer ISO (deploy/iso.nix), which fills in
# host.nix, but usable on its own. # host.nix, but usable on its own.
{ proxySuiteModule }: { proxySuiteModule, diskoModule }:
{ {
config, config,
@@ -58,6 +58,7 @@ in
{ {
imports = [ imports = [
proxySuiteModule proxySuiteModule
diskoModule
"${modulesPath}/profiles/qemu-guest.nix" "${modulesPath}/profiles/qemu-guest.nix"
]; ];
@@ -82,6 +83,25 @@ in
example = "/dev/vda"; example = "/dev/vda";
}; };
disko = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Lay out bootDisk with disko (deploy/disk-layout.nix): a BIOS boot partition, a
512M ESP on /boot, and btrfs (compress=zstd:3) with subvolumes @ on /, @nix,
@varlog on /var/log, @home, and @swap holding a swap file. The filesystems then
come from here, not hardware-configuration.nix. Off for servers installed
before it, whose ext4 root hardware-configuration.nix mounts.
'';
};
swapSize = mkOption {
type = types.str;
default = "2G";
description = "Size of the swap file in the swap subvolume.";
};
};
network = { network = {
mac = mkOption { mac = mkOption {
type = types.strMatching "([0-9a-f]{2}:){5}[0-9a-f]{2}"; type = types.strMatching "([0-9a-f]{2}:){5}[0-9a-f]{2}";
@@ -179,9 +199,17 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
disko.devices =
lib.mkIf cfg.disko.enable
(import ./disk-layout.nix {
device = cfg.bootDisk;
inherit (cfg.disko) swapSize;
}).disko.devices;
boot.loader.grub = { boot.loader.grub = {
enable = true; enable = true;
device = cfg.bootDisk; # disko lists the disk with the BIOS boot partition itself; twice fails an assertion.
device = lib.mkIf (!cfg.disko.enable) cfg.bootDisk;
# BIOS stage on the disk, EFI stage at the removable path: boots either way, # BIOS stage on the disk, EFI stage at the removable path: boots either way,
# and needs no NVRAM entry the VPS may not keep. # and needs no NVRAM entry the VPS may not keep.
efiSupport = true; efiSupport = true;
+4 -1
View File
@@ -13,7 +13,10 @@ nix build github:FUFSoB/proxy-suite-flake#installer-iso
Boot the VPS from it. The console installer asks for the public IP, users, an optional Boot the VPS from it. The console installer asks for the public IP, users, an optional
domain and the disk to erase, then installs NixOS with `nixosModules.server`: VLESS domain and the disk to erase, then installs NixOS with `nixosModules.server`: VLESS
REALITY, TLS and WS listeners, ACME certificates and SSH. After the reboot, log in and run: REALITY, TLS and WS listeners, ACME certificates and SSH. The disk is laid out by disko
(`services.proxy-suite-server.disko`): btrfs with `compress=zstd:3`, subvolumes `@` on `/`,
`@nix`, `@varlog` on `/var/log` and `@home`, and a 2G swap file in `@swap`. After the reboot, log in
and run:
```sh ```sh
proxy-ctl inbounds link vless-reality --qr proxy-ctl inbounds link vless-reality --qr
Generated
+21
View File
@@ -1,5 +1,25 @@
{ {
"nodes": { "nodes": {
"disko": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1789770686,
"narHash": "sha256-uZkBR7yHdIKUFB5SZdfgh1qkGfI3XmYmI/lTiquxbck=",
"owner": "nix-community",
"repo": "disko",
"rev": "725ea35e410ad83be4931d1bff7e090eacaf3563",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "disko",
"type": "github"
}
},
"nfqws2-keenetic": { "nfqws2-keenetic": {
"flake": false, "flake": false,
"locked": { "locked": {
@@ -34,6 +54,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"disko": "disko",
"nfqws2-keenetic": "nfqws2-keenetic", "nfqws2-keenetic": "nfqws2-keenetic",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"z2k": "z2k", "z2k": "z2k",
+10 -1
View File
@@ -15,6 +15,10 @@
url = "github:necronicle/z2k/z2k-enhanced"; url = "github:necronicle/z2k/z2k-enhanced";
flake = false; flake = false;
}; };
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
@@ -24,6 +28,7 @@
zapret, zapret,
nfqws2-keenetic, nfqws2-keenetic,
z2k, z2k,
disko,
}: }:
let let
systems = [ systems = [
@@ -58,7 +63,10 @@
nixosModules.default = proxySuiteModule; nixosModules.default = proxySuiteModule;
# A single-user VPS: VLESS REALITY, TLS and WS inbounds, ACME and SSH. Includes default. # A single-user VPS: VLESS REALITY, TLS and WS inbounds, ACME and SSH. Includes default.
nixosModules.server = import ./deploy/server-module.nix { inherit proxySuiteModule; }; nixosModules.server = import ./deploy/server-module.nix {
inherit proxySuiteModule;
diskoModule = disko.nixosModules.disko;
};
# Rootless, in the user's systemd manager: the local proxy, inbounds on ports from 1024 # Rootless, in the user's systemd manager: the local proxy, inbounds on ports from 1024
# up, and what else needs no root. # up, and what else needs no root.
@@ -222,6 +230,7 @@
proxySuiteModules proxySuiteModules
zapret zapret
; ;
serverModule = self.nixosModules.server;
generatedOptionsDoc = mkOptionsDoc system; generatedOptionsDoc = mkOptionsDoc system;
generatedReadmeDoc = mkReadmeDoc system; generatedReadmeDoc = mkReadmeDoc system;
} }
+2
View File
@@ -3,6 +3,7 @@
nixpkgs, nixpkgs,
proxySuiteModule, proxySuiteModule,
proxySuiteModules, proxySuiteModules,
serverModule,
generatedOptionsDoc, generatedOptionsDoc,
generatedReadmeDoc, generatedReadmeDoc,
zapret, zapret,
@@ -27,6 +28,7 @@ let
system system
nixpkgs nixpkgs
proxySuiteModule proxySuiteModule
serverModule
zapret zapret
; ;
}; };
+2
View File
@@ -3,6 +3,7 @@
system, system,
nixpkgs, nixpkgs,
proxySuiteModule, proxySuiteModule,
serverModule,
zapret, zapret,
}: }:
@@ -278,5 +279,6 @@ in
system system
nixpkgs nixpkgs
proxySuiteModule proxySuiteModule
serverModule
; ;
} }
+1 -1
View File
@@ -284,7 +284,7 @@ let
serverModuleChecks = import ./server-module.nix { serverModuleChecks = import ./server-module.nix {
inherit checkLib pkgs mkInboundsSpec; inherit checkLib pkgs mkInboundsSpec;
inherit (checkLib) system nixpkgs proxySuiteModule; inherit (checkLib) system nixpkgs serverModule;
}; };
xrayBackendChecks = import ./xray-backends.nix { xrayBackendChecks = import ./xray-backends.nix {
+19 -4
View File
@@ -5,7 +5,7 @@
pkgs, pkgs,
system, system,
nixpkgs, nixpkgs,
proxySuiteModule, serverModule,
mkInboundsSpec, mkInboundsSpec,
}: }:
@@ -13,8 +13,6 @@ let
inherit (checkLib) ok; inherit (checkLib) ok;
inherit (pkgs) lib; inherit (pkgs) lib;
serverModule = import ../../deploy/server-module.nix { inherit proxySuiteModule; };
mkServer = mkServer =
extra: extra:
import "${nixpkgs}/nixos/lib/eval-config.nix" { import "${nixpkgs}/nixos/lib/eval-config.nix" {
@@ -23,7 +21,7 @@ let
serverModule serverModule
{ {
system.stateVersion = "26.05"; system.stateVersion = "26.05";
fileSystems."/" = { fileSystems."/" = lib.mkDefault {
device = "/dev/disk/by-label/nixos"; device = "/dev/disk/by-label/nixos";
fsType = "ext4"; fsType = "ext4";
}; };
@@ -54,6 +52,12 @@ let
domain = "vpn.example.com"; domain = "vpn.example.com";
network.dhcp = true; network.dhcp = true;
}; };
# As the installer writes it now: filesystems from disko, not the fixture's ext4 root.
diskoServer = mkServer {
bootDisk = "/dev/disk/by-id/virtio-disk0";
disko.enable = true;
};
diskoFs = diskoServer.config.fileSystems;
failedAssertions = failedAssertions =
fixture: map (a: a.message) (builtins.filter (a: !a.assertion) fixture.config.assertions); fixture: map (a: a.message) (builtins.filter (a: !a.assertion) fixture.config.assertions);
@@ -70,6 +74,17 @@ in
assertions = [ assertions = [
(ok (failedAssertions ipServer == [ ])) (ok (failedAssertions ipServer == [ ]))
(ok (failedAssertions domainServer == [ ])) (ok (failedAssertions domainServer == [ ]))
(ok (failedAssertions diskoServer == [ ]))
# disko: btrfs subvolumes, compressed, the swap file, and GRUB on the disk once.
(ok (diskoFs."/".fsType == "btrfs" && builtins.elem "subvol=@" diskoFs."/".options))
(ok (builtins.elem "compress=zstd:3" diskoFs."/nix".options))
(ok (builtins.elem "subvol=@varlog" diskoFs."/var/log".options))
(ok (builtins.elem "subvol=@home" diskoFs."/home".options))
(ok (diskoFs."/boot".fsType == "vfat"))
(ok (map (s: s.device) diskoServer.config.swapDevices == [ "/swap/swapfile" ]))
(ok (diskoServer.config.boot.loader.grub.devices == [ "/dev/disk/by-id/virtio-disk0" ]))
(ok (ipServer.config.boot.loader.grub.devices == [ "/dev/vda" ]))
( (
assert assert