lol

systemd-stage-1: Add assertions for unsupported options.

authored by

Will Fancher and committed by
Raito Bezarius
cca22054 ac1dd9de

+45 -22
+1 -1
nixos/modules/services/hardware/udev.nix
··· 350 350 351 351 boot.kernelParams = mkIf (!config.networking.usePredictableInterfaceNames) [ "net.ifnames=0" ]; 352 352 353 - boot.initrd.extraUdevRulesCommands = optionalString (!config.boot.initrd.systemd.enable && config.boot.initrd.services.udev.rules != "") 353 + boot.initrd.extraUdevRulesCommands = mkIf (!config.boot.initrd.systemd.enable && config.boot.initrd.services.udev.rules != "") 354 354 '' 355 355 cat <<'EOF' > $out/99-local.rules 356 356 ${config.boot.initrd.services.udev.rules}
+2 -1
nixos/modules/services/networking/multipath.nix
··· 546 546 # We do not have systemd in stage-1 boot so must invoke `multipathd` 547 547 # with the `-1` argument which disables systemd calls. Invoke `multipath` 548 548 # to display the multipath mappings in the output of `journalctl -b`. 549 + # TODO: Implement for systemd stage 1 549 550 boot.initrd.kernelModules = [ "dm-multipath" "dm-service-time" ]; 550 - boot.initrd.postDeviceCommands = '' 551 + boot.initrd.postDeviceCommands = mkIf (!config.boot.initrd.systemd.enable) '' 551 552 modprobe -a dm-multipath dm-service-time 552 553 multipathd -s 553 554 (set -x && sleep 1 && multipath -ll)
+4 -4
nixos/modules/system/boot/initrd-network.nix
··· 116 116 117 117 boot.initrd.kernelModules = [ "af_packet" ]; 118 118 119 - boot.initrd.extraUtilsCommands = '' 119 + boot.initrd.extraUtilsCommands = mkIf (!config.boot.initrd.systemd.enable) '' 120 120 copy_bin_and_libs ${pkgs.klibc}/lib/klibc/bin.static/ipconfig 121 121 ''; 122 122 123 - boot.initrd.preLVMCommands = mkBefore ( 123 + boot.initrd.preLVMCommands = mkIf (!config.boot.initrd.systemd.enable) (mkBefore ( 124 124 # Search for interface definitions in command line. 125 125 '' 126 126 ifaces="" ··· 148 148 done 149 149 '' 150 150 151 - + cfg.postCommands); 151 + + cfg.postCommands)); 152 152 153 - boot.initrd.postMountCommands = mkIf cfg.flushBeforeStage2 '' 153 + boot.initrd.postMountCommands = mkIf (cfg.flushBeforeStage2 && !config.boot.initrd.systemd.enable) '' 154 154 for iface in $ifaces; do 155 155 ip address flush dev "$iface" 156 156 ip link set dev "$iface" down
+21
nixos/modules/system/boot/systemd/initrd.nix
··· 348 348 }; 349 349 350 350 config = mkIf (config.boot.initrd.enable && cfg.enable) { 351 + assertions = map (name: { 352 + assertion = lib.attrByPath name (throw "impossible") config.boot.initrd == ""; 353 + message = '' 354 + systemd stage 1 does not support 'boot.initrd.${lib.concatStringsSep "." name}'. Please 355 + convert it to analogous systemd units in 'boot.initrd.systemd'. 356 + 357 + Definitions: 358 + ${lib.concatMapStringsSep "\n" ({ file, ... }: " - ${file}") (lib.attrByPath name (throw "impossible") options.boot.initrd).definitionsWithLocations} 359 + ''; 360 + }) [ 361 + [ "preFailCommands" ] 362 + [ "preDeviceCommands" ] 363 + [ "preLVMCommands" ] 364 + [ "postDeviceCommands" ] 365 + [ "postMountCommands" ] 366 + [ "extraUdevRulesCommands" ] 367 + [ "extraUtilsCommands" ] 368 + [ "extraUtilsCommandsTest" ] 369 + [ "network" "postCommands" ] 370 + ]; 371 + 351 372 system.build = { inherit initialRamdisk; }; 352 373 353 374 boot.initrd.availableKernelModules = [
+4 -3
nixos/modules/tasks/encrypted-devices.nix
··· 110 110 }) earlyEncDevs); 111 111 forceLuksSupportInInitrd = true; 112 112 }; 113 - postMountCommands = 114 - concatMapStrings (dev: 113 + # TODO: systemd stage 1 114 + postMountCommands = lib.mkIf (!config.boot.initrd.systemd.enable) 115 + (concatMapStrings (dev: 115 116 "cryptsetup luksOpen --key-file ${dev.encrypted.keyFile} ${dev.encrypted.blkDev} ${dev.encrypted.label};\n" 116 - ) lateEncDevs; 117 + ) lateEncDevs); 117 118 }; 118 119 }; 119 120 }
+2 -2
nixos/modules/tasks/filesystems/bcachefs.nix
··· 102 102 copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs 103 103 copy_bin_and_libs ${mountCommand}/bin/mount.bcachefs 104 104 ''; 105 - boot.initrd.extraUtilsCommandsTest = '' 105 + boot.initrd.extraUtilsCommandsTest = lib.mkIf (!config.boot.initrd.systemd.enable) '' 106 106 $out/bin/bcachefs version 107 107 ''; 108 108 109 - boot.initrd.postDeviceCommands = commonFunctions + concatStrings (mapAttrsToList openCommand bootFs); 109 + boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) (commonFunctions + concatStrings (mapAttrsToList openCommand bootFs)); 110 110 111 111 boot.initrd.systemd.services = lib.mapAttrs' (mkUnits "/sysroot") bootFs; 112 112 })
+6 -6
nixos/modules/tasks/filesystems/zfs.nix
··· 584 584 boot.initrd = mkIf inInitrd { 585 585 kernelModules = [ "zfs" ] ++ optional (!cfgZfs.enableUnstable) "spl"; 586 586 extraUtilsCommands = 587 - '' 587 + mkIf (!config.boot.initrd.systemd.enable) '' 588 588 copy_bin_and_libs ${cfgZfs.package}/sbin/zfs 589 589 copy_bin_and_libs ${cfgZfs.package}/sbin/zdb 590 590 copy_bin_and_libs ${cfgZfs.package}/sbin/zpool 591 591 ''; 592 - extraUtilsCommandsTest = mkIf inInitrd 593 - '' 592 + extraUtilsCommandsTest = 593 + mkIf (!config.boot.initrd.systemd.enable) '' 594 594 $out/bin/zfs --help >/dev/null 2>&1 595 595 $out/bin/zpool --help >/dev/null 2>&1 596 596 ''; 597 - postDeviceCommands = concatStringsSep "\n" (['' 597 + postDeviceCommands = mkIf (!config.boot.initrd.systemd.enable) (concatStringsSep "\n" (['' 598 598 ZFS_FORCE="${optionalString cfgZfs.forceImportRoot "-f"}" 599 599 ''] ++ [(importLib { 600 600 # See comments at importLib definition. ··· 623 623 else concatMapStrings (fs: '' 624 624 zfs load-key -- ${escapeShellArg fs} 625 625 '') (filter (x: datasetToPool x == pool) cfgZfs.requestEncryptionCredentials)} 626 - '') rootPools)); 626 + '') rootPools))); 627 627 628 628 # Systemd in stage 1 629 - systemd = { 629 + systemd = mkIf config.boot.initrd.systemd.enable { 630 630 packages = [cfgZfs.package]; 631 631 services = listToAttrs (map (pool: createImportService { 632 632 inherit pool;
+2 -2
nixos/modules/tasks/swraid.nix
··· 62 62 cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ 63 63 ''; 64 64 65 - extraUtilsCommands = '' 65 + extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 66 66 # Add RAID mdadm tool. 67 67 copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm 68 68 copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon 69 69 ''; 70 70 71 - extraUtilsCommandsTest = '' 71 + extraUtilsCommandsTest = lib.mkIf (!config.boot.initrd.systemd.enable) '' 72 72 $out/bin/mdadm --version 73 73 ''; 74 74
+3 -3
nixos/tests/common/auto-format-root-device.nix
··· 5 5 # `virtualisation.fileSystems."/".autoFormat = true;` 6 6 # instead. 7 7 8 - { config, pkgs, ... }: 8 + { lib, config, pkgs, ... }: 9 9 10 10 let 11 11 rootDevice = config.virtualisation.rootDevice; 12 12 in 13 13 { 14 14 15 - boot.initrd.extraUtilsCommands = '' 15 + boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 16 16 # We need mke2fs in the initrd. 17 17 copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs 18 18 ''; 19 19 20 - boot.initrd.postDeviceCommands = '' 20 + boot.initrd.postDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 21 21 # If the disk image appears to be empty, run mke2fs to 22 22 # initialise. 23 23 FSTYPE=$(blkid -o value -s TYPE ${rootDevice} || true)