From d16a5416de17802afdb3ff9733fabfba610c03b2 Mon Sep 17 00:00:00 2001 From: File Magic Date: Thu, 13 Aug 2026 22:24:17 -0400 Subject: [PATCH] installer.nix [13-inch-thin-cannon]: persist-config copies repo to /persistent/etc/nixos --- 13-inch-thin-cannon/installer.nix | 54 ++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/13-inch-thin-cannon/installer.nix b/13-inch-thin-cannon/installer.nix index 3c018bd..a8bc7f8 100644 --- a/13-inch-thin-cannon/installer.nix +++ b/13-inch-thin-cannon/installer.nix @@ -26,17 +26,18 @@ originalSystem = self.nixosConfigurations."13-inch-thin-cannon"; - modifiedDisks = lib.mapAttrs ( - name: value: - let - dev = installDiskMappings.${name}; - in - value - // { - device = dev; - content = value.content // {device = dev;}; - } - ) originalSystem.config.disko.devices.disk; + modifiedDisks = + lib.mapAttrs ( + name: value: let + dev = installDiskMappings.${name}; + in + value + // { + device = dev; + content = value.content // {device = dev;}; + } + ) + originalSystem.config.disko.devices.disk; # filter all nixos module internal attributes cleanedDisks = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) modifiedDisks; @@ -51,10 +52,7 @@ installSystem = originalSystem.extendModules { modules = [ - ({ - lib, - ... - }: { + ({lib, ...}: { boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride true; boot.loader.grub.devices = lib.mkVMOverride (lib.attrValues installDiskMappings); imports = [ @@ -114,6 +112,31 @@ in { vim git inputs.disko.packages.${pkgs.system}.disko-install + (pkgs.writeShellScriptBin "persist-config" '' + # Copy the baked-in flake into the installed /persistent/etc/nixos so the + # impermanence bind-mount on /etc/nixos is populated. Must run after + # disko-install; the target is unmounted by then, so mount the /persistent + # subvolume ourselves (mirrors the rollback service's LUKS device lookup). + set -euo pipefail + luks_device="" + for device in /dev/mapper/enc /dev/mapper/cryptroot; do + if [[ -b "$device" ]]; then + luks_device="$device" + break + fi + done + if [[ -z "$luks_device" ]]; then + echo "ERROR: no LUKS device found — run disko-install first" >&2 + exit 1 + fi + mnt="$(mktemp -d)" + mount -o subvol=/persistent "$luks_device" "$mnt" + trap 'umount "$mnt" || true; rmdir "$mnt" || true' EXIT + rm -rf "$mnt/etc/nixos" + mkdir -p "$mnt/etc/nixos" + cp -a /iso/repo/. "$mnt/etc/nixos/" + echo "Flake copied to /persistent/etc/nixos" + '') ]; isoImage = { @@ -155,6 +178,7 @@ in { echo " To install (WIPES the target disk):" echo " disko-install --flake /iso/repo#13-inch-thin-cannon \\" echo " --disk main /dev/vda --write-efi-boot-entries" + echo " persist-config # copies the repo to /persistent/etc/nixos" echo "================================================================" ''; }; -- 2.51.2