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,
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}";
};
}
+14 -45
View File
@@ -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 <<SUMMARY
Disk $DISK (everything on it is erased)
Disk $DISK (everything on it is erased; btrfs, 2G swap file)
Network $net_summary
DNS $NET_DNS
Public IP $PUBLIC_IP
@@ -228,42 +219,20 @@ done
# --- Partition ------------------------------------------------------------------
step "Partitioning $DISK"
boot_disk=$(stable_disk_path "$DISK")
swapoff -a || true
umount -R "$MNT" 2>/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" <<HOST
services.proxy-suite-server = {
enable = true;
bootDisk = $(nix_str "$(stable_disk_path "$DISK")");
bootDisk = $(nix_str "$boot_disk");
disko.enable = true;
adminUser = $(nix_str "$ADMIN_USER");
sshPort = $SSH_PORT;
$(print_network_nix " ")
@@ -375,8 +345,7 @@ password=${password,,}
hash=$(mkpasswd -m yescrypt --stdin <<<"$password")
nixos-enter --root "$MNT" -- usermod -p "$hash" "$ADMIN_USER"
swapoff "$MNT/.install-swap"
rm -f "$MNT/.install-swap"
swapoff "$MNT/swap/swapfile"
# --- Done -----------------------------------------------------------------------
clear
+9 -10
View File
@@ -22,18 +22,10 @@ let
{
networking.hostName = "proxy-template";
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 = {
enable = true;
bootDisk = "/dev/vda";
disko.enable = true;
network = {
mac = "52:54:00:00:00:01";
ipv4 = {
@@ -58,6 +50,8 @@ let
installer = pkgs.callPackage ./installer.nix {
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
# 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}";
@@ -70,7 +64,12 @@ in
isoImage = {
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.
+30 -2
View File
@@ -2,7 +2,7 @@
# 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
# host.nix, but usable on its own.
{ proxySuiteModule }:
{ proxySuiteModule, diskoModule }:
{
config,
@@ -58,6 +58,7 @@ in
{
imports = [
proxySuiteModule
diskoModule
"${modulesPath}/profiles/qemu-guest.nix"
];
@@ -82,6 +83,25 @@ in
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 = {
mac = mkOption {
type = types.strMatching "([0-9a-f]{2}:){5}[0-9a-f]{2}";
@@ -179,9 +199,17 @@ in
};
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 = {
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,
# and needs no NVRAM entry the VPS may not keep.
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
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
proxy-ctl inbounds link vless-reality --qr
Generated
+21
View File
@@ -1,5 +1,25 @@
{
"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": {
"flake": false,
"locked": {
@@ -34,6 +54,7 @@
},
"root": {
"inputs": {
"disko": "disko",
"nfqws2-keenetic": "nfqws2-keenetic",
"nixpkgs": "nixpkgs",
"z2k": "z2k",
+10 -1
View File
@@ -15,6 +15,10 @@
url = "github:necronicle/z2k/z2k-enhanced";
flake = false;
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
@@ -24,6 +28,7 @@
zapret,
nfqws2-keenetic,
z2k,
disko,
}:
let
systems = [
@@ -58,7 +63,10 @@
nixosModules.default = proxySuiteModule;
# 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
# up, and what else needs no root.
@@ -222,6 +230,7 @@
proxySuiteModules
zapret
;
serverModule = self.nixosModules.server;
generatedOptionsDoc = mkOptionsDoc system;
generatedReadmeDoc = mkReadmeDoc system;
}
+2
View File
@@ -3,6 +3,7 @@
nixpkgs,
proxySuiteModule,
proxySuiteModules,
serverModule,
generatedOptionsDoc,
generatedReadmeDoc,
zapret,
@@ -27,6 +28,7 @@ let
system
nixpkgs
proxySuiteModule
serverModule
zapret
;
};
+2
View File
@@ -3,6 +3,7 @@
system,
nixpkgs,
proxySuiteModule,
serverModule,
zapret,
}:
@@ -278,5 +279,6 @@ in
system
nixpkgs
proxySuiteModule
serverModule
;
}
+1 -1
View File
@@ -284,7 +284,7 @@ let
serverModuleChecks = import ./server-module.nix {
inherit checkLib pkgs mkInboundsSpec;
inherit (checkLib) system nixpkgs proxySuiteModule;
inherit (checkLib) system nixpkgs serverModule;
};
xrayBackendChecks = import ./xray-backends.nix {
+19 -4
View File
@@ -5,7 +5,7 @@
pkgs,
system,
nixpkgs,
proxySuiteModule,
serverModule,
mkInboundsSpec,
}:
@@ -13,8 +13,6 @@ let
inherit (checkLib) ok;
inherit (pkgs) lib;
serverModule = import ../../deploy/server-module.nix { inherit proxySuiteModule; };
mkServer =
extra:
import "${nixpkgs}/nixos/lib/eval-config.nix" {
@@ -23,7 +21,7 @@ let
serverModule
{
system.stateVersion = "26.05";
fileSystems."/" = {
fileSystems."/" = lib.mkDefault {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
@@ -54,6 +52,12 @@ let
domain = "vpn.example.com";
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 =
fixture: map (a: a.message) (builtins.filter (a: !a.assertion) fixture.config.assertions);
@@ -70,6 +74,17 @@ in
assertions = [
(ok (failedAssertions ipServer == [ ]))
(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