summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorKim Lindberger <kim.lindberger@gmail.com>2021-06-14 10:50:07 +0200
committerGitHub <noreply@github.com>2021-06-14 10:50:07 +0200
commit26706834a58daa0c6f699c18f05e0a8b62ed3b7f (patch)
treeff3cfcfc92318122dfb82d170e9a688b3f8fc4a4 /nixos/lib
parent86752e44440dfcd17f53d08fc117bd96c8bac144 (diff)
parentea34fe21e18f87dc8b333672f23edf2bcee98cd7 (diff)
downloadnixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar.gz
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar.bz2
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar.lz
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar.xz
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.tar.zst
nixpkgs-26706834a58daa0c6f699c18f05e0a8b62ed3b7f.zip
Merge pull request #86967 from jakobrs/more-general-fsbefore
nixos/lib/utils: Add `fileSystems.<name>.depends` option and generalise fsBefore (fixes #86955)
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/utils.nix26
1 files changed, 24 insertions, 2 deletions
diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix
index c9dfdbed99a..1a51b149e56 100644
--- a/nixos/lib/utils.nix
+++ b/nixos/lib/utils.nix
@@ -14,8 +14,30 @@ rec {
   fsNeededForBoot = fs: fs.neededForBoot || elem fs.mountPoint pathsNeededForBoot;
 
   # Check whenever `b` depends on `a` as a fileSystem
-  fsBefore = a: b: a.mountPoint == b.device
-                || hasPrefix "${a.mountPoint}${optionalString (!(hasSuffix "/" a.mountPoint)) "/"}" b.mountPoint;
+  fsBefore = a: b:
+    let
+      # normalisePath adds a slash at the end of the path if it didn't already
+      # have one.
+      #
+      # The reason slashes are added at the end of each path is to prevent `b`
+      # from accidentally depending on `a` in cases like
+      #    a = { mountPoint = "/aaa"; ... }
+      #    b = { device     = "/aaaa"; ... }
+      # Here a.mountPoint *is* a prefix of b.device even though a.mountPoint is
+      # *not* a parent of b.device. If we add a slash at the end of each string,
+      # though, this is not a problem: "/aaa/" is not a prefix of "/aaaa/".
+      normalisePath = path: "${path}${optionalString (!(hasSuffix "/" path)) "/"}";
+      normalise = mount: mount // { device = normalisePath mount.device;
+                                    mountPoint = normalisePath mount.mountPoint;
+                                    depends = map normalisePath mount.depends;
+                                  };
+
+      a' = normalise a;
+      b' = normalise b;
+
+    in hasPrefix a'.mountPoint b'.device
+    || hasPrefix a'.mountPoint b'.mountPoint
+    || any (hasPrefix a'.mountPoint) b'.depends;
 
   # Escape a path according to the systemd rules, e.g. /dev/xyzzy
   # becomes dev-xyzzy.  FIXME: slow.