fix: build closure in build-step instead of on iso

This commit is contained in:
UGA Innovation Factory
2026-01-05 12:29:32 -05:00
parent 4c218190c3
commit b23525df78
2 changed files with 20 additions and 8 deletions

View File

@@ -20,6 +20,12 @@ let
targetConfig = self.nixosConfigurations.${hostName}.config; targetConfig = self.nixosConfigurations.${hostName}.config;
targetSystem = targetConfig.system.build.toplevel; targetSystem = targetConfig.system.build.toplevel;
diskoScript = targetConfig.system.build.diskoScript; diskoScript = targetConfig.system.build.diskoScript;
# Build the closure export at build time (not runtime in ISO)
closureExport = pkgs.runCommand "closure-export-${hostName}" { } ''
mkdir -p $out
${pkgs.nix}/bin/nix-store --export $(${pkgs.nix}/bin/nix-store -qR ${targetSystem}) > $out/closure.nar
'';
in in
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
inherit system; inherit system;
@@ -29,6 +35,7 @@ let
hostName hostName
targetSystem targetSystem
diskoScript diskoScript
closureExport
; ;
hostPlatform = system; hostPlatform = system;
}; };

View File

@@ -1,6 +1,7 @@
# This module defines a systemd service that automatically installs NixOS to the disk. # This module defines a systemd service that automatically installs NixOS to the disk.
# It is intended to be used in an installation ISO. # It is intended to be used in an installation ISO.
# It expects `targetSystem` (the closure to install) and `diskoScript` (the partitioning script) to be passed as arguments. # It expects `targetSystem` (the closure to install), `diskoScript` (the partitioning script),
# and `closureExport` (the pre-built NAR archive) to be passed as arguments.
{ {
config, config,
lib, lib,
@@ -10,6 +11,7 @@
hostPlatform, hostPlatform,
targetSystem, targetSystem,
diskoScript, diskoScript,
closureExport,
... ...
}: }:
{ {
@@ -21,8 +23,12 @@
targetSystem targetSystem
]; ];
# Explicitly include the system closure in the ISO image to prevent any need to build or fetch # Explicitly include the pre-built closure export and system in the ISO image
isoImage.contents = [ isoImage.contents = [
{
source = closureExport;
target = "/closure-export";
}
{ {
source = targetSystem; source = targetSystem;
target = "/system"; target = "/system";
@@ -53,14 +59,13 @@
echo ">>> Running disko script..." echo ">>> Running disko script..."
${diskoScript} ${diskoScript}
echo ">>> Copying system closure to target..." echo ">>> Importing pre-built closure into target store..."
# Copy the entire system closure without substitution # Import the closure that was exported at build time
nix-store --store /mnt --load-db < <(nix-store --dump-db) ${pkgs.nix}/bin/nix-store --store /mnt --import < /closure-export/closure.nar > /dev/null
nix-copy-closure --to /mnt ${targetSystem} 2>/dev/null || true
echo ">>> Running nixos-install..." echo ">>> Running nixos-install..."
# Install with pre-built closure already in store # Install with pre-built closure already imported (no evaluation or fetching needed)
nixos-install \ ${pkgs.nix}/bin/nixos-install \
--no-root-passwd \ --no-root-passwd \
--root /mnt \ --root /mnt \
--system ${targetSystem} \ --system ${targetSystem} \