1pkgs: with pkgs.lib;
2
3rec {
4
5 # Check whenever fileSystem is needed for boot
6 fsNeededForBoot = fs: fs.neededForBoot
7 || elem fs.mountPoint [ "/" "/nix" "/nix/store" "/var" "/var/log" "/var/lib" "/etc" ];
8
9 # Check whenever `b` depends on `a` as a fileSystem
10 # FIXME: it's incorrect to simply use hasPrefix here: "/dev/a" is not a parent of "/dev/ab"
11 fsBefore = a: b: ((any (x: elem x [ "bind" "move" ]) b.options) && (a.mountPoint == b.device))
12 || (hasPrefix a.mountPoint b.mountPoint);
13
14 # Escape a path according to the systemd rules, e.g. /dev/xyzzy
15 # becomes dev-xyzzy. FIXME: slow.
16 escapeSystemdPath = s:
17 replaceChars ["/" "-" " "] ["-" "\\x2d" "\\x20"]
18 (if hasPrefix "/" s then substring 1 (stringLength s) s else s);
19
20 # Returns a system path for a given shell package
21 toShellPath = shell:
22 if types.shellPackage.check shell then
23 "/run/current-system/sw${shell.shellPath}"
24 else if types.package.check shell then
25 throw "${shell} is not a shell package"
26 else
27 shell;
28}