lol

nixos/toplevel: move systemBuilder for `boot.kernel.enable`

This avoids creating a build-time reference on `boot.kernelParams` if
the configuration does not use a kernel, i.e., `boot.kernel.enable` is
set to `false`.

+33 -31
+1 -31
nixos/modules/system/activation/top-level.nix
··· 4 4 5 5 let 6 6 systemBuilder = 7 - let 8 - kernelPath = "${config.boot.kernelPackages.kernel}/" + 9 - "${config.system.boot.loader.kernelFile}"; 10 - initrdPath = "${config.system.build.initialRamdisk}/" + 11 - "${config.system.boot.loader.initrdFile}"; 12 - in '' 7 + '' 13 8 mkdir $out 14 - 15 - # Containers don't have their own kernel or initrd. They boot 16 - # directly into stage 2. 17 - ${optionalString config.boot.kernel.enable '' 18 - if [ ! -f ${kernelPath} ]; then 19 - echo "The bootloader cannot find the proper kernel image." 20 - echo "(Expecting ${kernelPath})" 21 - false 22 - fi 23 - 24 - ln -s ${kernelPath} $out/kernel 25 - ln -s ${config.system.modulesTree} $out/kernel-modules 26 - ${optionalString (config.hardware.deviceTree.package != null) '' 27 - ln -s ${config.hardware.deviceTree.package} $out/dtbs 28 - ''} 29 - 30 - echo -n "$kernelParams" > $out/kernel-params 31 - 32 - ln -s ${initrdPath} $out/initrd 33 - 34 - ln -s ${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets $out 35 - 36 - ln -s ${config.hardware.firmware}/lib/firmware $out/firmware 37 - ''} 38 9 39 10 ${if config.boot.initrd.systemd.enable then '' 40 11 cp ${config.system.build.bootStage2} $out/prepare-root ··· 83 54 84 55 systemd = config.systemd.package; 85 56 86 - kernelParams = config.boot.kernelParams; 87 57 nixosLabel = config.system.nixos.label; 88 58 89 59 inherit (config.system) extraDependencies;
+32
nixos/modules/system/boot/kernel.nix
··· 309 309 310 310 system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; 311 311 312 + # Not required for, e.g., containers as they don't have their own kernel or initrd. 313 + # They boot directly into stage 2. 314 + system.systemBuilderArgs.kernelParams = config.boot.kernelParams; 315 + system.systemBuilderCommands = 316 + let 317 + kernelPath = "${config.boot.kernelPackages.kernel}/" + 318 + "${config.system.boot.loader.kernelFile}"; 319 + initrdPath = "${config.system.build.initialRamdisk}/" + 320 + "${config.system.boot.loader.initrdFile}"; 321 + in 322 + '' 323 + if [ ! -f ${kernelPath} ]; then 324 + echo "The bootloader cannot find the proper kernel image." 325 + echo "(Expecting ${kernelPath})" 326 + false 327 + fi 328 + 329 + ln -s ${kernelPath} $out/kernel 330 + ln -s ${config.system.modulesTree} $out/kernel-modules 331 + ${optionalString (config.hardware.deviceTree.package != null) '' 332 + ln -s ${config.hardware.deviceTree.package} $out/dtbs 333 + ''} 334 + 335 + echo -n "$kernelParams" > $out/kernel-params 336 + 337 + ln -s ${initrdPath} $out/initrd 338 + 339 + ln -s ${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets $out 340 + 341 + ln -s ${config.hardware.firmware}/lib/firmware $out/firmware 342 + ''; 343 + 312 344 # Implement consoleLogLevel both in early boot and using sysctl 313 345 # (so you don't need to reboot to have changes take effect). 314 346 boot.kernelParams =