From ebf48167174a2f3d80560f9a55750e7f304499a2 Mon Sep 17 00:00:00 2001 From: Mathijs Kwik Date: Tue, 1 Jan 2013 14:42:43 +0100 Subject: [PATCH] systemd mount units: use 'escapeSystemdPath' from lib/utils --- lib/utils.nix | 2 +- modules/system/boot/systemd.nix | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/utils.nix b/lib/utils.nix index b75e063eaa9..35c56e8c32b 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -5,6 +5,6 @@ rec { # Escape a path according to the systemd rules, e.g. /dev/xyzzy # becomes dev-xyzzy. FIXME: slow. escapeSystemdPath = s: - replaceChars ["/" "-"] ["-" "\\x2d"] (substring 1 (stringLength s) s); + replaceChars ["/" "-" " "] ["-" "\\x2d" "\\x20"] (substring 1 (stringLength s) s); } diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index fbd28e6e836..f0e94266b17 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -1,6 +1,7 @@ -{ config, pkgs, ... }: +{ config, pkgs, utils, ... }: with pkgs.lib; +with utils; with import ./systemd-unit-options.nix { inherit config pkgs; }; 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: assert def.mountConfig.What != ""; 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}.socket" (socketToUnit n v)) cfg.sockets // listToAttrs (map - (v: let n = mountName v.where; + (v: let n = escapeSystemdPath v.where; in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts); system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [