about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJanne Heß <janne@hess.ooo>2022-04-04 22:51:08 +0100
committerJanne Heß <janne@hess.ooo>2022-04-04 22:56:31 +0100
commitacf089edefdf80abc6c5fb18937393a9e4519a62 (patch)
treefa1b2b7b04ae9d924f1cfab6fee412ed381d657c /nixos
parent9ae3813cdabd28794b29ce1c0a932d68de3294a2 (diff)
nixos/systemd-stage-1: Softcode bin tools...
...and other cleanups and fixes
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/systemd/initrd.nix28
1 files changed, 22 insertions, 6 deletions
diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 36a14d7a82565..a3ea787303764 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -108,7 +108,7 @@ let
 
   fileSystems = filter utils.fsNeededForBoot config.system.build.fileSystems;
 
-  fstab = pkgs.writeText "fstab" (lib.concatMapStringsSep "\n"
+  fstab = pkgs.writeText "initrd-fstab" (lib.concatMapStringsSep "\n"
     ({ fsType, mountPoint, device, options, autoFormat, autoResize, ... }@fs: let
         opts = options ++ optional autoFormat "x-systemd.makefs" ++ optional autoResize "x-systemd.growfs";
       in "${device} /sysroot${mountPoint} ${fsType} ${lib.concatStringsSep "," opts}") fileSystems);
@@ -128,11 +128,7 @@ let
     name = "initrd-emergency-env";
     paths = map getBin cfg.initrdBin;
     pathsToLink = ["/bin" "/sbin"];
-    # Make recovery easier
-    postBuild = ''
-      ln -s ${cfg.package.util-linux}/bin/mount $out/bin/
-      ln -s ${cfg.package.util-linux}/bin/umount $out/bin/
-    '';
+    postBuild = concatStringsSep "\n" (mapAttrsToList (n: v: "ln -s '${v}' $out/bin/'${n}'") cfg.extraBin);
   };
 
   initialRamdisk = pkgs.makeInitrdNG {
@@ -205,6 +201,19 @@ in {
       default = [];
     };
 
+    extraBin = mkOption {
+      description = ''
+        Tools to add to /bin
+      '';
+      example = literalExpression ''
+        {
+          umount = ''${pkgs.util-linux}/bin/umount;
+        }
+      '';
+      type = types.attrsOf types.path;
+      default = {};
+    };
+
     suppressedStorePaths = mkOption {
       description = ''
         Store paths specified in the storePaths option that
@@ -342,8 +351,15 @@ in {
 
   config = mkIf (config.boot.initrd.enable && cfg.enable) {
     system.build = { inherit initialRamdisk; };
+
+    boot.initrd.availableKernelModules = [ "autofs4" ]; # systemd needs this for some features
+
     boot.initrd.systemd = {
       initrdBin = [pkgs.bash pkgs.coreutils pkgs.kmod cfg.package] ++ config.system.fsPackages;
+      extraBin = {
+        mount = "${cfg.package.util-linux}/bin/mount";
+        umount = "${cfg.package.util-linux}/bin/umount";
+      };
 
       contents = {
         "/init".source = "${cfg.package}/lib/systemd/systemd";