systemd mount units: use 'escapeSystemdPath' from lib/utils
This commit is contained in:
parent
16a9bcfe81
commit
ebf4816717
@ -5,6 +5,6 @@ rec {
|
|||||||
# Escape a path according to the systemd rules, e.g. /dev/xyzzy
|
# Escape a path according to the systemd rules, e.g. /dev/xyzzy
|
||||||
# becomes dev-xyzzy. FIXME: slow.
|
# becomes dev-xyzzy. FIXME: slow.
|
||||||
escapeSystemdPath = s:
|
escapeSystemdPath = s:
|
||||||
replaceChars ["/" "-"] ["-" "\\x2d"] (substring 1 (stringLength s) s);
|
replaceChars ["/" "-" " "] ["-" "\\x2d" "\\x20"] (substring 1 (stringLength s) s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, utils, ... }:
|
||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
with utils;
|
||||||
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -290,15 +291,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
# this is by no means the full escaping-logic systemd uses
|
|
||||||
# so feel free to extend this further.
|
|
||||||
mountName = path:
|
|
||||||
let escaped = replaceChars [ "-" " " "/" ]
|
|
||||||
[ "\x2d" "\x20" "-" ] (toString path);
|
|
||||||
in if (substring 0 1 escaped == "-")
|
|
||||||
then substring 1 (sub (stringLength escaped) 1) escaped
|
|
||||||
else escaped;
|
|
||||||
|
|
||||||
mountToUnit = name: def:
|
mountToUnit = name: def:
|
||||||
assert def.mountConfig.What != "";
|
assert def.mountConfig.What != "";
|
||||||
assert def.mountConfig.Where != "";
|
assert def.mountConfig.Where != "";
|
||||||
@ -550,7 +542,7 @@ in
|
|||||||
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
||||||
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
||||||
// listToAttrs (map
|
// listToAttrs (map
|
||||||
(v: let n = mountName v.where;
|
(v: let n = escapeSystemdPath v.where;
|
||||||
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts);
|
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts);
|
||||||
|
|
||||||
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [
|
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user