From 0411b51a00565552bf376d723f364508efdff4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Sat, 30 Apr 2022 14:44:01 +0200 Subject: [PATCH] nixos/systemd-stage-1: Remove unnecessary binaries We can make the growfs and makefs binaries conditional because we know if we'll need them. Also move the cryptsetup generator to the luksroot so it's not included when not needed. We drop some generators altogether: systemd-getty-generator because we don't have getty anyway in stage 1, systemd-system-update-generator because we don't use that logic in NixOS and systemd-veritysetup-generator because stage 1 has no veritysetup support (yet) and if it had, we still wouldn't want to include the generator unconditionally. --- nixos/modules/system/boot/luksroot.nix | 1 + nixos/modules/system/boot/systemd/initrd.nix | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/nixos/modules/system/boot/luksroot.nix b/nixos/modules/system/boot/luksroot.nix index 57fc02a2e322..4103a7af57cd 100644 --- a/nixos/modules/system/boot/luksroot.nix +++ b/nixos/modules/system/boot/luksroot.nix @@ -992,6 +992,7 @@ in ]; storePaths = [ "${config.boot.initrd.systemd.package}/lib/systemd/systemd-cryptsetup" + "${config.boot.initrd.systemd.package}/lib/systemd/system-generators/systemd-cryptsetup-generator" ]; }; diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index a93fda11bec2..2ec521a98449 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -105,6 +105,9 @@ let opts = options ++ optional autoFormat "x-systemd.makefs" ++ optional autoResize "x-systemd.growfs"; in "${device} /sysroot${mountPoint} ${fsType} ${lib.concatStringsSep "," opts}") fileSystems); + needMakefs = lib.any (fs: fs.autoFormat) fileSystems; + needGrowfs = lib.any (fs: fs.autoResize) fileSystems; + kernel-name = config.boot.kernelPackages.kernel.name or "kernel"; modulesTree = config.system.modulesTree.override { name = kernel-name + "-modules"; }; firmware = config.hardware.firmware; @@ -360,18 +363,22 @@ in { storePaths = [ # systemd tooling "${cfg.package}/lib/systemd/systemd-fsck" - "${cfg.package}/lib/systemd/systemd-growfs" + (lib.mkIf needGrowfs "${cfg.package}/lib/systemd/systemd-growfs") "${cfg.package}/lib/systemd/systemd-hibernate-resume" "${cfg.package}/lib/systemd/systemd-journald" - "${cfg.package}/lib/systemd/systemd-makefs" + (lib.mkIf needMakefs "${cfg.package}/lib/systemd/systemd-makefs") "${cfg.package}/lib/systemd/systemd-modules-load" "${cfg.package}/lib/systemd/systemd-remount-fs" "${cfg.package}/lib/systemd/systemd-shutdown" "${cfg.package}/lib/systemd/systemd-sulogin-shell" "${cfg.package}/lib/systemd/systemd-sysctl" - # additional systemd directories - "${cfg.package}/lib/systemd/system-generators" + # generators + "${cfg.package}/lib/systemd/system-generators/systemd-debug-generator" + "${cfg.package}/lib/systemd/system-generators/systemd-fstab-generator" + "${cfg.package}/lib/systemd/system-generators/systemd-gpt-auto-generator" + "${cfg.package}/lib/systemd/system-generators/systemd-hibernate-resume-generator" + "${cfg.package}/lib/systemd/system-generators/systemd-run-generator" # utilities needed by systemd "${cfg.package.util-linux}/bin/mount" @@ -409,8 +416,8 @@ in { mkdir -p $out/etc/systemd/system touch $out/etc/systemd/system/systemd-{makefs,growfs}@.service '')]; - services."systemd-makefs@".unitConfig.IgnoreOnIsolate = true; - services."systemd-growfs@".unitConfig.IgnoreOnIsolate = true; + services."systemd-makefs@" = lib.mkIf needMakefs { unitConfig.IgnoreOnIsolate = true; }; + services."systemd-growfs@" = lib.mkIf needGrowfs { unitConfig.IgnoreOnIsolate = true; }; services.initrd-nixos-activation = { after = [ "initrd-fs.target" ];