Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #186163 from lilyinstarlight/feature/systemd-stage-1-fs-label

nixos/systemd-stage-1: unify initrd fstab generation logic with system fstab

authored by Will Fancher and committed by GitHub 2239c5d5 fd58e457

+31 -25
-8
nixos/modules/system/boot/systemd/initrd.nix
··· 100 100 101 101 fileSystems = filter utils.fsNeededForBoot config.system.build.fileSystems; 102 102 103 - fstab = pkgs.writeText "initrd-fstab" (lib.concatMapStringsSep "\n" 104 - ({ fsType, mountPoint, device, options, autoFormat, autoResize, ... }@fs: let 105 - opts = options ++ optional autoFormat "x-systemd.makefs" ++ optional autoResize "x-systemd.growfs"; 106 - finalDevice = if (lib.elem "bind" options) then "/sysroot${device}" else device; 107 - in "${finalDevice} /sysroot${mountPoint} ${fsType} ${lib.concatStringsSep "," opts}") fileSystems); 108 - 109 103 needMakefs = lib.any (fs: fs.autoFormat) fileSystems; 110 104 needGrowfs = lib.any (fs: fs.autoResize) fileSystems; 111 105 ··· 353 347 [Manager] 354 348 DefaultEnvironment=PATH=/bin:/sbin ${optionalString (isBool cfg.emergencyAccess && cfg.emergencyAccess) "SYSTEMD_SULOGIN_FORCE=1"} 355 349 ''; 356 - 357 - "/etc/fstab".source = fstab; 358 350 359 351 "/lib/modules".source = "${modulesClosure}/lib/modules"; 360 352 "/lib/firmware".source = "${modulesClosure}/lib/firmware";
+31 -17
nixos/modules/tasks/filesystems.nix
··· 153 153 specialMount "${mount.device}" "${mount.mountPoint}" "${concatStringsSep "," mount.options}" "${mount.fsType}" 154 154 '') mounts); 155 155 156 + makeFstabEntries = 157 + let 158 + fsToSkipCheck = [ "none" "bindfs" "btrfs" "zfs" "tmpfs" "nfs" "vboxsf" "glusterfs" "apfs" "9p" "cifs" "prl_fs" "vmhgfs" ]; 159 + isBindMount = fs: builtins.elem "bind" fs.options; 160 + skipCheck = fs: fs.noCheck || fs.device == "none" || builtins.elem fs.fsType fsToSkipCheck || isBindMount fs; 161 + # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces 162 + escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; 163 + in fstabFileSystems: { rootPrefix ? "", excludeChecks ? false, extraOpts ? (fs: []) }: concatMapStrings (fs: 164 + (optionalString (isBindMount fs) (escape rootPrefix)) 165 + + (if fs.device != null then escape fs.device 166 + else if fs.label != null then "/dev/disk/by-label/${escape fs.label}" 167 + else throw "No device specified for mount point ‘${fs.mountPoint}’.") 168 + + " " + escape (rootPrefix + fs.mountPoint) 169 + + " " + fs.fsType 170 + + " " + builtins.concatStringsSep "," (fs.options ++ (extraOpts fs)) 171 + + " " + (optionalString (!excludeChecks) 172 + ("0 " + (if skipCheck fs then "0" else if fs.mountPoint == "/" then "1" else "2"))) 173 + + "\n" 174 + ) fstabFileSystems; 175 + 176 + initrdFstab = pkgs.writeText "initrd-fstab" (makeFstabEntries (filter utils.fsNeededForBoot fileSystems) { 177 + rootPrefix = "/sysroot"; 178 + excludeChecks = true; 179 + extraOpts = fs: 180 + (optional fs.autoResize "x-systemd.growfs") 181 + ++ (optional fs.autoFormat "x-systemd.makefs"); 182 + }); 183 + 156 184 in 157 185 158 186 { ··· 278 306 279 307 environment.etc.fstab.text = 280 308 let 281 - fsToSkipCheck = [ "none" "bindfs" "btrfs" "zfs" "tmpfs" "nfs" "vboxsf" "glusterfs" "apfs" "9p" "cifs" "prl_fs" "vmhgfs" ]; 282 - isBindMount = fs: builtins.elem "bind" fs.options; 283 - skipCheck = fs: fs.noCheck || fs.device == "none" || builtins.elem fs.fsType fsToSkipCheck || isBindMount fs; 284 - # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces 285 - escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; 286 309 swapOptions = sw: concatStringsSep "," ( 287 310 sw.options 288 311 ++ optional (sw.priority != null) "pri=${toString sw.priority}" ··· 297 320 # <file system> <mount point> <type> <options> <dump> <pass> 298 321 299 322 # Filesystems. 300 - ${concatMapStrings (fs: 301 - (if fs.device != null then escape fs.device 302 - else if fs.label != null then "/dev/disk/by-label/${escape fs.label}" 303 - else throw "No device specified for mount point ‘${fs.mountPoint}’.") 304 - + " " + escape fs.mountPoint 305 - + " " + fs.fsType 306 - + " " + builtins.concatStringsSep "," fs.options 307 - + " 0" 308 - + " " + (if skipCheck fs then "0" else 309 - if fs.mountPoint == "/" then "1" else "2") 310 - + "\n" 311 - ) fileSystems} 323 + ${makeFstabEntries fileSystems {}} 312 324 313 325 # Swap devices. 314 326 ${flip concatMapStrings config.swapDevices (sw: 315 327 "${sw.realDevice} none swap ${swapOptions sw}\n" 316 328 )} 317 329 ''; 330 + 331 + boot.initrd.systemd.contents."/etc/fstab".source = initrdFstab; 318 332 319 333 # Provide a target that pulls in all filesystems. 320 334 systemd.targets.fs =