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,
disko,
diskLayout,
flakeUrl,
flakeRev,
flakeSource,
stateVersion,
coreutils,
@@ -16,6 +16,7 @@
gnused,
iproute2,
iputils,
jq,
mkpasswd,
nix,
nixos-install-tools,
@@ -38,6 +39,7 @@ import ./script.nix { inherit lib writeShellApplication; } {
gnused
iproute2
iputils
jq
mkpasswd
nix
nixos-install-tools
@@ -48,7 +50,7 @@ import ./script.nix { inherit lib writeShellApplication; } {
xray
];
runtimeEnv = {
PSI_FLAKE_URL = flakeUrl;
PSI_FLAKE_REV = flakeRev;
PSI_FLAKE_SRC = "${flakeSource}";
PSI_STATE_VERSION = stateVersion;
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
# 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
# empty), PSI_FLAKE_SRC (this flake's source in the store), PSI_STATE_VERSION.
# Baked in by deploy/installer.nix: PSI_FLAKE_REV (the ISO's commit, or empty for a
# 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).
: "${PSI_FLAKE_URL?}" "${PSI_FLAKE_SRC:?}" "${PSI_STATE_VERSION:?}"
: "${PSI_FLAKE_REV?}" "${PSI_FLAKE_SRC:?}" "${PSI_STATE_VERSION:?}"
MNT=/mnt
SECRETS_DIR=/var/lib/proxy-suite-server
@@ -112,6 +113,7 @@ ask_all() {
fi
reject "A free port from 1 to 65535 (80, 443, 2053 and 8443 are taken)." SSH_PORT
done
ask_yes QEMU_GUEST "QEMU guest agent (lets the VPS panel see the server's state)" "y"
# --- Proxy --------------------------------------------------------------------
step "Proxy"
@@ -201,6 +203,7 @@ show_summary() {
Public IP $PUBLIC_IP
Hostname $HOST_NAME
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
Certificate ${DOMAIN:-$PUBLIC_IP (IP certificate)}${ACME_EMAIL:+, $ACME_EMAIL}
REALITY 443 as $REALITY_SNI
@@ -266,6 +269,7 @@ cat >"$etc_nixos/host.nix" <<HOST
networking.hostName = $(nix_str "$HOST_NAME");
time.timeZone = "UTC";
system.stateVersion = $(nix_str "$PSI_STATE_VERSION");
services.qemuGuest.enable = $QEMU_GUEST;
services.proxy-suite-server = {
enable = true;
@@ -311,15 +315,24 @@ write_flake() {
FLAKE
}
# The ISO's own commit on GitHub, so `nix flake update` follows upstream later. An ISO
# built from an unpushed tree has none: its source is copied next to the flake instead.
# Upstream on GitHub, locked to the ISO's commit, so `nix flake update` follows upstream
# 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
if [[ -n $PSI_FLAKE_URL ]]; then
write_flake "$PSI_FLAKE_URL"
if nix flake lock "$etc_nixos"; then
if [[ -n $PSI_FLAKE_REV ]]; then
write_flake "$flake_repo/$PSI_FLAKE_REV"
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
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
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
# closure goes on the ISO, so installing downloads little and builds nothing big.
template = import "${modulesPath}/../lib/eval-config.nix" {
inherit system;
# Evaluated like the installed flake evaluates it, so the two share their store paths.
template = self.inputs.nixpkgs.lib.nixosSystem {
modules = [
serverModule
{
nixpkgs.hostPlatform = system;
networking.hostName = "proxy-template";
system.stateVersion = config.system.nixos.release;
# Asked by the installer, on by default.
services.qemuGuest.enable = true;
services.proxy-suite-server = {
enable = true;
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 =
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 {
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;
# 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}";
flakeSource = self.outPath;
# The installer pins this commit on GitHub when it holds what flakeSource does, and
# installs flakeSource itself otherwise (not pushed, dirty, or built from path:).
flakeRev = self.rev or "";
inherit flakeSource;
stateVersion = config.system.nixos.release;
};
in
{
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 = {
edition = "proxy-suite";
# The template's disko script brings the partitioning tools (btrfs-progs, sgdisk...).
storeContents = [
template.config.system.build.toplevel
template.config.system.build.diskoScript
flakeSource
]
++ 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.
networking = {
@@ -82,6 +160,8 @@ in
};
systemd.network.wait-online.enable = 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-command"
@@ -95,9 +175,14 @@ in
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 = [
installer
(pkgs.callPackage ./net-rescue.nix { })
pkgs.htop
];
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
# as nixos, which has passwordless sudo.
programs.bash.interactiveShellInit = ''
if [[ $(tty) == /dev/tty1 && ! -e /tmp/.proxy-suite-install-started ]]; then
programs.fish.interactiveShellInit = ''
if test (tty) = /dev/tty1; and not test -e /tmp/.proxy-suite-install-started
touch /tmp/.proxy-suite-install-started
sudo proxy-suite-install
fi
end
'';
}
+32
View File
@@ -77,6 +77,15 @@ in
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 {
type = types.str;
description = "Disk GRUB installs its BIOS stage to.";
@@ -360,6 +369,29 @@ in
environment.systemPackages = [
pkgs.qrencode
(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
```
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. The disk is laid out by disko
The image is `result/iso/proxy-suite-installer-<build time>-<commit>-<system>.iso`. Boot
the VPS from it. The console installer asks for the public IP, users, an optional
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 `/`,
`@nix`, `@varlog` on `/var/log` and `@home`, and a 2G swap file in `@swap`. After the reboot, log in
and run:
+1 -1
View File
@@ -185,7 +185,7 @@
})
{ nixpkgs.hostPlatform = system; }
];
}).config.system.build.isoImage;
}).config.system.build.installerIso;
optionsDoc = mkOptionsDoc system;
usageSnippets = pkgs.runCommand "proxy-suite-usage-snippets" { } (
''
+8
View File
@@ -58,6 +58,7 @@ let
disko.enable = true;
};
diskoFs = diskoServer.config.fileSystems;
plainServer = mkServer { tools.enable = false; };
failedAssertions =
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);
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
# ''${...} used to reach the login screen verbatim.
(