1{2 pkgs,3 config,4 lib,5}:6let7 inherit (lib.strings) optionalString;8 9 systemBuilder = ''10 mkdir $out1112 ${13 if config.boot.initrd.enable && config.boot.initrd.systemd.enable then14 ''15 # This must not be a symlink or the abs_path of the grub builder for the tests16 # will resolve the symlink and we end up with a path that doesn't point to a17 # system closure.18 cp "$systemd/lib/systemd/systemd" $out/init1920 ${lib.optionalString (!config.system.nixos-init.enable) ''21 cp ${config.system.build.bootStage2} $out/prepare-root22 substituteInPlace $out/prepare-root --subst-var-by systemConfig $out23 ''}24 ''25 else26 ''27 cp ${config.system.build.bootStage2} $out/init28 substituteInPlace $out/init --subst-var-by systemConfig $out29 ''30 }3132 ln -s ${config.system.build.etc}/etc $out/etc3334 ${lib.optionalString config.system.etc.overlay.enable ''35 ln -s ${config.system.build.etcMetadataImage} $out/etc-metadata-image36 ln -s ${config.system.build.etcBasedir} $out/etc-basedir37 ''}3839 ln -s ${config.system.path} $out/sw40 ln -s "$systemd" $out/systemd4142 echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version43 echo -n "$nixosLabel" > $out/nixos-version44 echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system4546 ${config.system.systemBuilderCommands}4748 cp "$extraDependenciesPath" "$out/extra-dependencies"4950 ${config.boot.bootspec.writer}51 ${optionalString config.boot.bootspec.enableValidation ''${config.boot.bootspec.validator} "$out/${config.boot.bootspec.filename}"''}52 '';53in54{55 system.build.toplevel-fleet = pkgs.stdenvNoCC.mkDerivation (56 {57 name = "nixos-system-${config.system.name}-${config.system.nixos.label}";58 preferLocalBuild = true;59 allowSubstitutes = false;60 passAsFile = [ "extraDependencies" ];61 buildCommand = systemBuilder;6263 systemd = config.systemd.package;6465 nixosLabel = config.system.nixos.label;6667 inherit (config.system) extraDependencies;68 }69 // config.system.systemBuilderArgs70 );71}