Skip to content

Commit

Permalink
nixos/lib, nixos/filesystems: Make fsBefore more stable, and add `dep…
Browse files Browse the repository at this point in the history
…ends` option
  • Loading branch information
jakobrs committed May 22, 2020
1 parent 87b3ad9 commit a0fa49e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nixos/lib/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ rec {
|| elem fs.mountPoint [ "/" "/nix" "/nix/store" "/var" "/var/log" "/var/lib" "/etc" ];

# 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 = 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 (dependency: hasPrefix a'.mountPoint dependency) b'.depends;

# Escape a path according to the systemd rules, e.g. /dev/xyzzy
# becomes dev-xyzzy. FIXME: slow.
Expand Down
10 changes: 10 additions & 0 deletions nixos/modules/tasks/filesystems.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ let
type = types.listOf nonEmptyStr;
};

depends = mkOption {
default = [ ];
example = [ "/persist" ];
type = types.listOf nonEmptyStr;
description = ''
List of paths that must be mounted before this one. Note that you do
not need to add the value of .device or .mountPoint to this list.
'';
};

};

config = {
Expand Down

0 comments on commit a0fa49e

Please sign in to comment.