Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ let
_path: lhs: rhs:
!(isAttrs lhs && isAttrs rhs)
) lhs rhs;

in
recursiveMerge left right;

Expand Down Expand Up @@ -357,6 +356,44 @@ let
*/
maybeStr = x: lib.optionalString (x != null) x;

/*
Check whenever `b` depends on `a` as a fileSystem

Note: copied from nixpkgs/nixos/utils.nix @ 47718fe8858fa4642cd6a4f0b5a1173bad9ce8df
because the file that exports it is not meant to be used standalone.
*/
fsBefore =
a: b:
with lib;
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 (toString 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;

/*
Takes a Submodules config and options argument and returns a serializable
subset of config variables as a shell script snippet.
Expand Down Expand Up @@ -956,9 +993,25 @@ let
default =
with lib;
let
mountOrder = pipe cfg.config._config.fileSystems.contents [
(foldl' recursiveUpdate { })
(mapAttrsToList (
mountPoint: value:
value
// {
mountPoint = value.mountPoint or mountPoint;
depends = [ ];
}
))
(toposort diskoLib.fsBefore)
(getAttr "result")
(map (getAttr "mountPoint"))
];

fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or { }) (
flatten (map attrValues (attrValues devices))
);

sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }
) devices;
in
Expand All @@ -968,7 +1021,7 @@ let
${concatMapStrings (dev: (attrByPath (dev ++ [ "_mount" ]) { } devices).dev or "") sortedDeviceList}

# and then mount the filesystems in alphabetical order
${concatStrings (attrValues fsMounts)}
${concatStrings (attrVals mountOrder fsMounts)}
'';
};
_unmount = lib.mkOption {
Expand Down