diff options
author | Jan Malakhovski <oxij@oxij.org> | 2015-11-25 19:09:09 +0000 |
---|---|---|
committer | Jan Malakhovski <oxij@oxij.org> | 2016-08-23 18:14:05 +0000 |
commit | 65d26c4dc12f8f0113b6b128573f18492ac5b6f6 (patch) | |
tree | bcd427c83dab4633c9c4b06c338ac10350f0209e /nixos/modules/tasks/filesystems.nix | |
parent | 2c8ca0d1bd1df838b3e3b2d2e17c6855b3b520c1 (diff) |
nixos: apply toposort to fileSystems to support bind and move mounts
And use new `config.system.build.fileSystems` property everywhere.
Diffstat (limited to 'nixos/modules/tasks/filesystems.nix')
-rw-r--r-- | nixos/modules/tasks/filesystems.nix | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index b0abf5eda871..78dca662dc9d 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -5,7 +5,16 @@ with utils; let - fileSystems = attrValues config.fileSystems; + fileSystems' = toposort fsBefore (attrValues config.fileSystems); + + fileSystems = if fileSystems' ? "result" + then # use topologically sorted fileSystems everywhere + fileSystems'.result + else # the assertion below will catch this, + # but we fall back to the original order + # anyway so that other modules could check + # their assertions too + (attrValues config.fileSystems); prioOption = prio: optionalString (prio != null) " pri=${toString prio}"; @@ -162,6 +171,17 @@ in config = { + assertions = let + ls = sep: concatMapStringsSep sep (x: x.mountPoint); + in [ + { assertion = ! (fileSystems' ? "cycle"); + message = "The ‘fileSystems’ option can't be topologically sorted: mountpoint dependency path ${ls " -> " fileSystems'.cycle} loops to ${ls ", " fileSystems'.loops}"; + } + ]; + + # Export for use in other modules + system.build.fileSystems = fileSystems; + boot.supportedFilesystems = map (fs: fs.fsType) fileSystems; # Add the mount helpers to the system path so that `mount' can find them. @@ -177,7 +197,7 @@ in # This is a generated file. Do not edit! # Filesystems. - ${flip concatMapStrings fileSystems (fs: + ${concatMapStrings (fs: (if fs.device != null then fs.device else if fs.label != null then "/dev/disk/by-label/${fs.label}" else throw "No device specified for mount point ‘${fs.mountPoint}’.") @@ -188,7 +208,7 @@ in + " " + (if skipCheck fs then "0" else if fs.mountPoint == "/" then "1" else "2") + "\n" - )} + ) fileSystems} # Swap devices. ${flip concatMapStrings config.swapDevices (sw: |