mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-20 00:53:12 +03:00
nixos/lib, nixos/filesystems: Make fsBefore more stable, and add depends
option
This commit is contained in:
parent
c8e32eddf8
commit
b07602a604
@ -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.
|
||||
|
@ -24,13 +24,15 @@ let
|
||||
|
||||
specialFSTypes = [ "proc" "sysfs" "tmpfs" "ramfs" "devtmpfs" "devpts" ];
|
||||
|
||||
nonEmptyWithoutTrailingSlash = addCheckDesc "non-empty without trailing slash" types.str
|
||||
(s: isNonEmpty s && (builtins.match ".+/" s) == null);
|
||||
|
||||
coreFileSystemOpts = { name, config, ... }: {
|
||||
|
||||
options = {
|
||||
mountPoint = mkOption {
|
||||
example = "/mnt/usb";
|
||||
type = addCheckDesc "non-empty without trailing slash" types.str
|
||||
(s: isNonEmpty s && (builtins.match ".+/" s) == null);
|
||||
type = nonEmptyWithoutTrailingSlash;
|
||||
description = "Location of the mounted the file system.";
|
||||
};
|
||||
|
||||
@ -55,6 +57,20 @@ let
|
||||
type = types.listOf nonEmptyStr;
|
||||
};
|
||||
|
||||
depends = mkOption {
|
||||
default = [ ];
|
||||
example = [ "/persist" ];
|
||||
type = types.listOf nonEmptyWithoutTrailingSlash;
|
||||
description = ''
|
||||
List of paths that should be mounted before this one. This filesystem's
|
||||
<option>device</option> and <option>mountPoint</option> are always
|
||||
checked and do not need to be included explicitly. If a path is added
|
||||
to this list, any other filesystem whose mount point is a parent of
|
||||
the path will be mounted before this filesystem. The paths do not need
|
||||
to actually be the <option>mountPoint</option> of some other filesystem.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = {
|
||||
|
Loading…
Reference in New Issue
Block a user