Add a generic installer that asks for the basics and builds offline

The installer ISO no longer needs a prebuilt system: `router-setup` asks
for the disk, the WAN and LAN interfaces, DHCP or PPPoE (optionally on a
VLAN), host name, LAN address and a password, writes settings.json and
the secrets, builds that router offline (the ISO carries a reference
router system whose closure has everything the build needs) and installs
it with `router-install --system`.

The password is used for the web UI and, hashed, as root's console
password (routerSettings sets root's hashedPasswordFile; it applies when
the account is created at installation).

checks.setup answers router-setup on the console and checks the installed
box: its settings, the web UI and console login with that password, and
a rebuild that reproduces the installed system.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
2026-10-29 09:19:14 +01:00
co-authored by Claude Opus 5.5
parent 5ddff44a35
commit f5909fbdcb
7 changed files with 468 additions and 17 deletions
+16 -7
View File
@@ -21,25 +21,30 @@ let
];
text = ''
usage() {
echo "usage: router-install [--yes] [--secrets DIR] <disk>" >&2
echo " Wipes <disk> (e.g. /dev/nvme0n1) and installs ${cfg.system}." >&2
echo "usage: router-install [--yes] [--secrets DIR] [--system PATH] <disk>" >&2
echo " Wipes <disk> (e.g. /dev/nvme0n1) and installs a router system." >&2
echo " --secrets DIR copied to /var/lib/router (PPPoE password, WireGuard keys, ...)" >&2
echo " --system PATH the system to install${lib.optionalString (cfg.system != null) " (default: ${cfg.system})"}" >&2
exit 2
}
yes=0
secrets=
system=${if cfg.system != null then toString cfg.system else ""}
disk=
while [ $# -gt 0 ]; do
case $1 in
--yes) yes=1 ;;
--secrets) shift; [ $# -gt 0 ] || usage; secrets=$1 ;;
--system) shift; [ $# -gt 0 ] || usage; system=$1 ;;
-*) usage ;;
*) [ -z "$disk" ] || usage; disk=$1 ;;
esac
shift
done
[ -n "$disk" ] || usage
[ -n "$system" ] || usage
[ -x "$system/bin/switch-to-configuration" ] || { echo "router-install: $system is not a NixOS system" >&2; exit 1; }
[ "$(id -u)" -eq 0 ] || { echo "router-install: must run as root" >&2; exit 1; }
[ -b "$disk" ] || { echo "router-install: $disk is not a block device" >&2; exit 1; }
@@ -94,8 +99,8 @@ let
echo "note: no --secrets given; put the PPPoE password etc. in /var/lib/router later" >&2
fi
echo ">> installing ${cfg.system}"
nixos-install --system ${cfg.system} --root /mnt --no-root-passwd --no-channel-copy
echo ">> installing $system"
nixos-install --system "$system" --root /mnt --no-root-passwd --no-channel-copy
echo ">> unmounting"
umount -R /mnt
@@ -106,13 +111,17 @@ let
in
{
options.router.installer.system = lib.mkOption {
type = lib.types.package;
description = "The system (a `system.build.toplevel`) `router-install` writes to disk.";
type = lib.types.nullOr lib.types.package;
default = null;
description = ''
The system (a `system.build.toplevel`) `router-install` writes to disk;
null if it is always given with `--system` (as `router-setup` does).
'';
};
config = {
environment.systemPackages = [ installScript ];
# The closure must be on the installer itself.
system.extraDependencies = [ cfg.system ];
system.extraDependencies = lib.optional (cfg.system != null) cfg.system;
};
}