Skip to content

Commit

Permalink
nixos: Improve handling of special file systems in create-needed-for-…
Browse files Browse the repository at this point in the history
…boot

When generating the dependencies for the systemd unit, take into
account the special cases where there not be any backing file system,
such as with tmpfs.
  • Loading branch information
talyz committed Dec 22, 2024
1 parent 0ab2f85 commit c6afc3a
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let
intersectLists
any
id
head
;

inherit (utils)
Expand All @@ -43,9 +44,10 @@ let
;

inherit (pkgs.callPackage ./lib.nix { })
splitPath
concatPaths
duplicates
parentsOf
duplicates
;

cfg = config.environment.persistence;
Expand Down Expand Up @@ -724,7 +726,13 @@ in
let
neededForBootFs = catAttrs "mountPoint" (filter fsNeededForBoot (attrValues config.fileSystems));
neededForBootDirs = filter (dir: elem dir.dirPath neededForBootFs) directories;
getDevice = fs: if fs.device != null then fs.device else "/dev/disk/by-label/${fs.label}";
getDevice = fs:
if fs.device != null then
fs.device
else if fs.label != null then
"/dev/disk/by-label/${fs.label}"
else
"none";
mkMount = fs:
let
mountPoint = concatPaths [ "/persist-tmp-mnt" fs.mountPoint ];
Expand All @@ -750,14 +758,24 @@ in
in
concatMap matchFileSystems persistentStoragePaths;
deviceUnits = unique
(map
(concatMap
(fs:
if fs.fsType == "zfs" then
"zfs-import.target"
else if builtins.elem "bind" fs.options then
"${escapeSystemdPath fs.device}.mount"
# If the device path starts with “dev” or “sys”,
# it's a real device and should have an associated
# .device unit. If not, it's probably either a
# temporary file system lacking a backing device, a
# ZFS pool or a bind mount.
let
device = getDevice fs;
in
if elem (head (splitPath [ device ])) [ "dev" "sys" ] then
[ "${escapeSystemdPath device}.device" ]
else if device == "none" || device == fs.fsType then
[ ]
else if fs.fsType == "zfs" then
[ "zfs-import.target" ]
else
"${(escapeSystemdPath (getDevice fs))}.device")
[ "${escapeSystemdPath device}.mount" ])
fileSystems);
createNeededForBootDirs = ''
${concatMapStrings mkMount fileSystems}
Expand Down

0 comments on commit c6afc3a

Please sign in to comment.