diff options
author | Lily Foster <lily@lily.flowers> | 2022-08-16 09:33:28 -0400 |
---|---|---|
committer | Lily Foster <lily@lily.flowers> | 2022-08-18 13:33:43 -0400 |
commit | 69d79431016fdb8096447f5b5ab0d8e18ffb8f54 (patch) | |
tree | a71f435c56bdcc27ee363b69402ae1c7947cc821 /nixos/modules/tasks | |
parent | 0608bffda6cd018075afc7ec73a2c97bd23ae31f (diff) |
nixos/systemd-stage-1: unify initrd fstab generation logic with system fstab
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r-- | nixos/modules/tasks/filesystems.nix | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index 318740a44f4ae..a4152a1fe4dfa 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -153,6 +153,34 @@ let specialMount "${mount.device}" "${mount.mountPoint}" "${concatStringsSep "," mount.options}" "${mount.fsType}" '') mounts); + makeFstabEntries = + let + fsToSkipCheck = [ "none" "bindfs" "btrfs" "zfs" "tmpfs" "nfs" "vboxsf" "glusterfs" "apfs" "9p" "cifs" "prl_fs" "vmhgfs" ]; + isBindMount = fs: builtins.elem "bind" fs.options; + skipCheck = fs: fs.noCheck || fs.device == "none" || builtins.elem fs.fsType fsToSkipCheck || isBindMount fs; + # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces + escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; + in fstabFileSystems: { rootPrefix ? "", excludeChecks ? false, extraOpts ? (fs: []) }: concatMapStrings (fs: + (optionalString (isBindMount fs) (escape rootPrefix)) + + (if fs.device != null then escape fs.device + else if fs.label != null then "/dev/disk/by-label/${escape fs.label}" + else throw "No device specified for mount point ‘${fs.mountPoint}’.") + + " " + escape (rootPrefix + fs.mountPoint) + + " " + fs.fsType + + " " + builtins.concatStringsSep "," (fs.options ++ (extraOpts fs)) + + " " + (optionalString (!excludeChecks) + ("0 " + (if skipCheck fs then "0" else if fs.mountPoint == "/" then "1" else "2"))) + + "\n" + ) fstabFileSystems; + + initrdFstab = pkgs.writeText "initrd-fstab" (makeFstabEntries (filter utils.fsNeededForBoot fileSystems) { + rootPrefix = "/sysroot"; + excludeChecks = true; + extraOpts = fs: + (optional fs.autoResize "x-systemd.growfs") + ++ (optional fs.autoFormat "x-systemd.makefs"); + }); + in { @@ -279,11 +307,6 @@ in environment.etc.fstab.text = let - fsToSkipCheck = [ "none" "bindfs" "btrfs" "zfs" "tmpfs" "nfs" "vboxsf" "glusterfs" "apfs" "9p" "cifs" "prl_fs" "vmhgfs" ]; - isBindMount = fs: builtins.elem "bind" fs.options; - skipCheck = fs: fs.noCheck || fs.device == "none" || builtins.elem fs.fsType fsToSkipCheck || isBindMount fs; - # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces - escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; swapOptions = sw: concatStringsSep "," ( sw.options ++ optional (sw.priority != null) "pri=${toString sw.priority}" @@ -298,18 +321,7 @@ in # <file system> <mount point> <type> <options> <dump> <pass> # Filesystems. - ${concatMapStrings (fs: - (if fs.device != null then escape fs.device - else if fs.label != null then "/dev/disk/by-label/${escape fs.label}" - else throw "No device specified for mount point ‘${fs.mountPoint}’.") - + " " + escape fs.mountPoint - + " " + fs.fsType - + " " + builtins.concatStringsSep "," fs.options - + " 0" - + " " + (if skipCheck fs then "0" else - if fs.mountPoint == "/" then "1" else "2") - + "\n" - ) fileSystems} + ${makeFstabEntries fileSystems {}} # Swap devices. ${flip concatMapStrings config.swapDevices (sw: @@ -317,6 +329,8 @@ in )} ''; + boot.initrd.systemd.contents."/etc/fstab".source = initrdFstab; + # Provide a target that pulls in all filesystems. systemd.targets.fs = { description = "All File Systems"; |