fix: iso minification

This commit is contained in:
FUFSoB committed 2026-09-27 20:43:52 +05:00
1 parent 6b9f8e44c9
commit cbdd0d543e
7 files changed
+173 -27

No files matched your search

+4 -2
View File
@@ -5,7 +5,7 @@
xray, xray,
disko, disko,
diskLayout, diskLayout,
flakeUrl, flakeRev,
flakeSource, flakeSource,
stateVersion, stateVersion,
coreutils, coreutils,
@@ -16,6 +16,7 @@
gnused, gnused,
iproute2, iproute2,
iputils, iputils,
jq,
mkpasswd, mkpasswd,
nix, nix,
nixos-install-tools, nixos-install-tools,
@@ -38,6 +39,7 @@ import ./script.nix { inherit lib writeShellApplication; } {
gnused gnused
iproute2 iproute2
iputils iputils
jq
mkpasswd mkpasswd
nix nix
nixos-install-tools nixos-install-tools
@@ -48,7 +50,7 @@ import ./script.nix { inherit lib writeShellApplication; } {
xray xray
]; ];
runtimeEnv = { runtimeEnv = {
PSI_FLAKE_URL = flakeUrl; PSI_FLAKE_REV = flakeRev;
PSI_FLAKE_SRC = "${flakeSource}"; PSI_FLAKE_SRC = "${flakeSource}";
PSI_STATE_VERSION = stateVersion; PSI_STATE_VERSION = stateVersion;
PSI_DISK_LAYOUT = "${diskLayout}"; PSI_DISK_LAYOUT = "${diskLayout}";
+22 -9
View File
@@ -1,11 +1,12 @@
# proxy-suite-install: turn a VPS booted from the installer ISO into a proxy-suite # proxy-suite-install: turn a VPS booted from the installer ISO into a proxy-suite
# server. Everything asked here ends up in /etc/nixos/host.nix on the target. # server. Everything asked here ends up in /etc/nixos/host.nix on the target.
# #
# Baked in by deploy/installer.nix: PSI_FLAKE_URL (github ref at the ISO's commit, or # Baked in by deploy/installer.nix: PSI_FLAKE_REV (the ISO's commit, or empty for a
# empty), PSI_FLAKE_SRC (this flake's source in the store), PSI_STATE_VERSION. # dirty tree or a path: build), PSI_FLAKE_SRC (this flake's source in the store),
# PSI_STATE_VERSION.
# Unattended: PSI_UNATTENDED=1 plus PSI_<NAME> for every answer (see ask in net-lib.sh). # Unattended: PSI_UNATTENDED=1 plus PSI_<NAME> for every answer (see ask in net-lib.sh).
: "${PSI_FLAKE_URL?}" "${PSI_FLAKE_SRC:?}" "${PSI_STATE_VERSION:?}" : "${PSI_FLAKE_REV?}" "${PSI_FLAKE_SRC:?}" "${PSI_STATE_VERSION:?}"
MNT=/mnt MNT=/mnt
SECRETS_DIR=/var/lib/proxy-suite-server SECRETS_DIR=/var/lib/proxy-suite-server
@@ -112,6 +113,7 @@ ask_all() {
fi fi
reject "A free port from 1 to 65535 (80, 443, 2053 and 8443 are taken)." SSH_PORT reject "A free port from 1 to 65535 (80, 443, 2053 and 8443 are taken)." SSH_PORT
done done
ask_yes QEMU_GUEST "QEMU guest agent (lets the VPS panel see the server's state)" "y"
# --- Proxy -------------------------------------------------------------------- # --- Proxy --------------------------------------------------------------------
step "Proxy" step "Proxy"
@@ -201,6 +203,7 @@ show_summary() {
Public IP $PUBLIC_IP Public IP $PUBLIC_IP
Hostname $HOST_NAME Hostname $HOST_NAME
SSH $ADMIN_USER@$PUBLIC_IP port $SSH_PORT (password shown at the end) SSH $ADMIN_USER@$PUBLIC_IP port $SSH_PORT (password shown at the end)
Guest agent $(if [[ $QEMU_GUEST == true ]]; then echo yes; else echo no; fi)
Proxy user $PROXY_USER Proxy user $PROXY_USER
Certificate ${DOMAIN:-$PUBLIC_IP (IP certificate)}${ACME_EMAIL:+, $ACME_EMAIL} Certificate ${DOMAIN:-$PUBLIC_IP (IP certificate)}${ACME_EMAIL:+, $ACME_EMAIL}
REALITY 443 as $REALITY_SNI REALITY 443 as $REALITY_SNI
@@ -266,6 +269,7 @@ cat >"$etc_nixos/host.nix" <<HOST
networking.hostName = $(nix_str "$HOST_NAME"); networking.hostName = $(nix_str "$HOST_NAME");
time.timeZone = "UTC"; time.timeZone = "UTC";
system.stateVersion = $(nix_str "$PSI_STATE_VERSION"); system.stateVersion = $(nix_str "$PSI_STATE_VERSION");
services.qemuGuest.enable = $QEMU_GUEST;
services.proxy-suite-server = { services.proxy-suite-server = {
enable = true; enable = true;
@@ -311,15 +315,24 @@ write_flake() {
FLAKE FLAKE
} }
# The ISO's own commit on GitHub, so `nix flake update` follows upstream later. An ISO # Upstream on GitHub, locked to the ISO's commit, so `nix flake update` follows upstream
# built from an unpushed tree has none: its source is copied next to the flake instead. # later. Only if GitHub has that commit with the very source on this ISO: otherwise (not
# pushed, a dirty tree, a path: build) the source is copied next to the flake instead,
# so what is installed is always what the ISO carries.
flake_repo=github:FUFSoB/proxy-suite-flake
locked=false locked=false
if [[ -n $PSI_FLAKE_URL ]]; then if [[ -n $PSI_FLAKE_REV ]]; then
write_flake "$PSI_FLAKE_URL" write_flake "$flake_repo/$PSI_FLAKE_REV"
if nix flake lock "$etc_nixos"; then if nix flake lock "$etc_nixos" &&
[[ $(jq -r '.nodes["proxy-suite"].locked.narHash' "$etc_nixos/flake.lock") == "$(nix hash path "$PSI_FLAKE_SRC")" ]]; then
# Unpinned in flake.nix, as `nix flake lock` would have left it had upstream been
# at this commit.
write_flake "$flake_repo"
jq '.nodes["proxy-suite"].original |= del(.rev)' "$etc_nixos/flake.lock" >"$etc_nixos/flake.lock.tmp"
mv "$etc_nixos/flake.lock.tmp" "$etc_nixos/flake.lock"
locked=true locked=true
else else
warn "Could not lock $PSI_FLAKE_URL; using the copy of proxy-suite on this ISO instead." warn "GitHub does not have this ISO's commit $PSI_FLAKE_REV; using the copy of proxy-suite on this ISO instead."
fi fi
fi fi
if [[ $locked == false ]]; then if [[ $locked == false ]]; then
+97 -12
View File
@@ -15,13 +15,16 @@ let
# The configuration the installer writes, with placeholders for what it asks. Its # The configuration the installer writes, with placeholders for what it asks. Its
# closure goes on the ISO, so installing downloads little and builds nothing big. # closure goes on the ISO, so installing downloads little and builds nothing big.
template = import "${modulesPath}/../lib/eval-config.nix" { # Evaluated like the installed flake evaluates it, so the two share their store paths.
inherit system; template = self.inputs.nixpkgs.lib.nixosSystem {
modules = [ modules = [
serverModule serverModule
{ {
nixpkgs.hostPlatform = system;
networking.hostName = "proxy-template"; networking.hostName = "proxy-template";
system.stateVersion = config.system.nixos.release; system.stateVersion = config.system.nixos.release;
# Asked by the installer, on by default.
services.qemuGuest.enable = true;
services.proxy-suite-server = { services.proxy-suite-server = {
enable = true; enable = true;
bootDisk = "/dev/vda"; bootDisk = "/dev/vda";
@@ -44,33 +47,108 @@ let
]; ];
}; };
# The sources of this flake and of its inputs, so locking /etc/nixos finds them here. # This flake's source without what a path: build picks up besides the tracked files.
flakeSource = lib.cleanSourceWith {
name = "source";
src = self;
filter =
path: type:
lib.cleanSourceFilter path type
&& !(lib.elem (baseNameOf path) [
"__pycache__"
".ruff_cache"
".direnv"
]);
};
# The sources of the flakes this one is locked to, so locking /etc/nixos finds them
# here. Non-flake inputs (z2k alone is 270M) are fetched when evaluation needs them,
# which the server never does.
inputSources = inputSources =
flake: [ flake.outPath ] ++ lib.concatMap inputSources (lib.attrValues (flake.inputs or { })); flake:
lib.concatMap (input: [ input.outPath ] ++ inputSources input) (
lib.filter (input: input._type or null == "flake") (lib.attrValues (flake.inputs or { }))
);
# Tells ISOs apart: the commit, and a hash of the tree when it differs from it (dirty,
# or built from path:). The file name adds the build time.
treeId = builtins.substring 0 8 (builtins.hashString "sha256" self.narHash);
sourceId =
if self ? rev then
self.shortRev
else if self ? dirtyShortRev then
"${self.dirtyShortRev}-${treeId}"
else
treeId;
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; # Evaluates the layout against the nixpkgs source on the ISO, not a copy of it.
disko = self.inputs.disko.packages.${system}.disko.override {
path = self.inputs.nixpkgs.outPath;
};
diskLayout = ./disk-layout.nix; diskLayout = ./disk-layout.nix;
# A github ref only for a clean, committed tree; the installer falls back to the # The installer pins this commit on GitHub when it holds what flakeSource does, and
# copy in PSI_FLAKE_SRC when it cannot be fetched (e.g. not pushed yet). # installs flakeSource itself otherwise (not pushed, dirty, or built from path:).
flakeUrl = lib.optionalString (self ? rev) "github:FUFSoB/proxy-suite-flake/${self.rev}"; flakeRev = self.rev or "";
flakeSource = self.outPath; inherit flakeSource;
stateVersion = config.system.nixos.release; stateVersion = config.system.nixos.release;
}; };
in in
{ {
imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix" ]; imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix" ];
# The generic installer's extras, none of which a VPS console needs: rescue and disk
# tools with zfs and bcachefs (base.nix), a copy of nixpkgs as a channel, and the
# ISO's own configuration in /etc/nixos.
disabledModules = [
"profiles/base.nix"
"installer/cd-dvd/channel.nix"
"profiles/clone-config.nix"
];
isoImage = { isoImage = {
edition = "proxy-suite"; edition = "proxy-suite";
# The template's disko script brings the partitioning tools (btrfs-progs, sgdisk...). # The template's disko script brings the partitioning tools (btrfs-progs, sgdisk...).
storeContents = [ storeContents = [
template.config.system.build.toplevel template.config.system.build.toplevel
template.config.system.build.diskoScript template.config.system.build.diskoScript
flakeSource
] ]
++ lib.unique (inputSources self); ++ lib.unique (inputSources self);
# Smaller than the default zstd, at the cost of a slower boot and build.
squashfsCompression =
"xz -Xdict-size 100%" + lib.optionalString pkgs.stdenv.hostPlatform.isx86 " -Xbcj x86";
}; };
image.baseName = lib.mkForce "proxy-suite-installer-${sourceId}-${system}";
# The ISO under a name with its build time. The store path keeps the plain name, so an
# unchanged ISO is not rebuilt and keeps its first build time.
system.build.installerIso = config.system.build.isoImage.overrideAttrs (old: {
buildCommandPath = pkgs.writeText "make-iso9660-image-stamped.sh" ''
isoName="proxy-suite-installer-$(date -u +%Y%m%d-%H%M)-${sourceId}-${system}.iso"
source ${old.buildCommandPath}
'';
});
# Smaller: no firmware (a VM needs none, 800M+), docs, git, RAID or memtest.
hardware.enableRedistributableFirmware = lib.mkForce false;
documentation = {
enable = lib.mkForce false;
man.enable = lib.mkForce false;
doc.enable = lib.mkForce false;
info.enable = lib.mkForce false;
nixos.enable = lib.mkForce false;
};
programs.git.enable = lib.mkForce false;
environment.defaultPackages = lib.mkForce [ ];
boot.swraid.enable = lib.mkForce false;
boot.loader.grub.memtest86.enable = lib.mkForce false;
# What the installer mounts: disko's ESP and btrfs.
boot.supportedFilesystems = [
"btrfs"
"vfat"
];
# 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.
networking = { networking = {
@@ -82,6 +160,8 @@ in
}; };
systemd.network.wait-online.enable = false; systemd.network.wait-online.enable = false;
services.openssh.enable = lib.mkForce false; services.openssh.enable = lib.mkForce false;
# Lets the VPS panel see the installer's address.
services.qemuGuest.enable = true;
nix.settings.experimental-features = [ nix.settings.experimental-features = [
"nix-command" "nix-command"
@@ -95,9 +175,14 @@ in
packages = [ pkgs.terminus_font ]; packages = [ pkgs.terminus_font ];
}; };
# The installed server's shell and tools, which the template brings anyway.
programs.fish.enable = true;
users.defaultUserShell = pkgs.fish;
programs.vim.enable = true;
environment.systemPackages = [ environment.systemPackages = [
installer installer
(pkgs.callPackage ./net-rescue.nix { }) (pkgs.callPackage ./net-rescue.nix { })
pkgs.htop
]; ];
services.getty.helpLine = lib.mkForce '' services.getty.helpLine = lib.mkForce ''
@@ -107,10 +192,10 @@ in
# Once, on tty1 only: other consoles (Alt+F2) stay plain shells. The console logs in # Once, on tty1 only: other consoles (Alt+F2) stay plain shells. The console logs in
# as nixos, which has passwordless sudo. # as nixos, which has passwordless sudo.
programs.bash.interactiveShellInit = '' programs.fish.interactiveShellInit = ''
if [[ $(tty) == /dev/tty1 && ! -e /tmp/.proxy-suite-install-started ]]; then if test (tty) = /dev/tty1; and not test -e /tmp/.proxy-suite-install-started
touch /tmp/.proxy-suite-install-started touch /tmp/.proxy-suite-install-started
sudo proxy-suite-install sudo proxy-suite-install
fi end
''; '';
} }
+32
View File
@@ -77,6 +77,15 @@ in
description = "SSH port."; description = "SSH port.";
}; };
tools.enable = mkOption {
type = types.bool;
default = true;
description = ''
Admin comforts: fish as the login shell, vim next to nano (still the default
editor), and htop, tmux, jq, mtr, iftop, dig and ncdu.
'';
};
bootDisk = mkOption { bootDisk = mkOption {
type = types.str; type = types.str;
description = "Disk GRUB installs its BIOS stage to."; description = "Disk GRUB installs its BIOS stage to.";
@@ -360,6 +369,29 @@ in
environment.systemPackages = [ environment.systemPackages = [
pkgs.qrencode pkgs.qrencode
(pkgs.callPackage ./net-rescue.nix { }) (pkgs.callPackage ./net-rescue.nix { })
]
++ lib.optionals cfg.tools.enable [
pkgs.htop
pkgs.jq
pkgs.iftop
pkgs.dig
pkgs.ncdu
]; ];
programs = lib.mkIf cfg.tools.enable {
fish.enable = true;
# Next to nano, which stays the default editor.
vim.enable = true;
tmux.enable = true;
mtr.enable = true;
};
users.defaultUserShell = lib.mkIf cfg.tools.enable pkgs.fish;
# Man pages stay; the NixOS manual, info and HTML docs are a download no server needs.
documentation = {
doc.enable = lib.mkDefault false;
info.enable = lib.mkDefault false;
nixos.enable = lib.mkDefault false;
};
}; };
} }
+9 -3
View File
@@ -11,9 +11,15 @@ If your provider lets you boot a custom ISO, build the installer:
nix build github:FUFSoB/proxy-suite-flake#installer-iso 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 The image is `result/iso/proxy-suite-installer-<build time>-<commit>-<system>.iso`. Boot
domain and the disk to erase, then installs NixOS with `nixosModules.server`: VLESS the VPS from it. The console installer asks for the public IP, users, an optional
REALITY, TLS and WS listeners, ACME certificates and SSH. The disk is laid out by disko domain, whether to run the QEMU guest agent (so the VPS panel sees the server's state)
and the disk to erase, then installs NixOS with `nixosModules.server`: VLESS
REALITY, TLS and WS listeners, ACME certificates and SSH, with fish as the login shell
and vim (nano stays the default editor), htop, tmux, jq, mtr, iftop, dig and ncdu
(`services.proxy-suite-server.tools`).
It installs the proxy-suite source the ISO carries: `/etc/nixos` follows this repository
on GitHub when the ISO's commit is there, and holds a copy otherwise. The disk is laid out by disko
(`services.proxy-suite-server.disko`): btrfs with `compress=zstd:3`, subvolumes `@` on `/`, (`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 `@nix`, `@varlog` on `/var/log` and `@home`, and a 2G swap file in `@swap`. After the reboot, log in
and run: and run:
+1 -1
View File
@@ -185,7 +185,7 @@
}) })
{ nixpkgs.hostPlatform = system; } { nixpkgs.hostPlatform = system; }
]; ];
}).config.system.build.isoImage; }).config.system.build.installerIso;
optionsDoc = mkOptionsDoc system; optionsDoc = mkOptionsDoc system;
usageSnippets = pkgs.runCommand "proxy-suite-usage-snippets" { } ( usageSnippets = pkgs.runCommand "proxy-suite-usage-snippets" { } (
'' ''
+8
View File
@@ -58,6 +58,7 @@ let
disko.enable = true; disko.enable = true;
}; };
diskoFs = diskoServer.config.fileSystems; diskoFs = diskoServer.config.fileSystems;
plainServer = mkServer { tools.enable = false; };
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);
@@ -176,6 +177,13 @@ in
&& !(lib.hasInfix "--onion" ipServer.config.services.getty.helpLine); && !(lib.hasInfix "--onion" ipServer.config.services.getty.helpLine);
true true
) )
# tools: fish for every login, and vim next to nano, which stays the editor; off, the
# NixOS defaults.
(ok (ipServer.config.users.defaultUserShell.pname == "fish"))
(ok (ipServer.config.users.users.admin.shell.pname == "fish"))
(ok (ipServer.config.programs.vim.enable && ipServer.config.programs.nano.enable))
(ok (ipServer.config.environment.variables.EDITOR == "nano"))
(ok (!plainServer.config.programs.fish.enable && !plainServer.config.programs.vim.enable))
# The console banner names the server and the admin account, interpolated: an escaped # The console banner names the server and the admin account, interpolated: an escaped
# ''${...} used to reach the login screen verbatim. # ''${...} used to reach the login screen verbatim.
( (