From 7a9c8730931b0d6ec13ad115cd79826f30877d88 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 12 Nov 2017 00:49:36 +0100 Subject: [PATCH] files: add special handling of systemd files Unfortunately systemd derives nonsensical unit names when the unit file is a link to a link to a file. This commit ensures that any file whose target path matches the pattern `*/systemd/user/*` will be reachable with only one link hop. This also reverts f52ec0df7c00a2d3938091f3d72641d023385878, which contained a temporary fix. This commit is an improvements in that it is more explicit and also handles unit files given directly as a home file source. --- modules/files.nix | 19 +++++++++++++++++-- modules/systemd.nix | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/files.nix b/modules/files.nix index f2495f5b4..45aa99659 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -225,11 +225,26 @@ in install -m "$mode" "$source" "$target" else [[ -x $source ]] && isExecutable=1 || isExecutable="" - if [[ $executable == inherit || $isExecutable == $executable ]]; then + + # Link the file into the home file directory if possible, + # i.e., if the executable bit of the source is the same we + # expect for the target. Otherwise, we copy the file and + # set the executable bit to the expected value. + # + # Note, as a special case we always copy systemd units + # because it derives the unit name from the ultimate link + # target, which may be a store path with the hash + # included. + if [[ ($executable == inherit || $isExecutable == $executable) \ + && $relTarget != *"/systemd/user/"* ]]; then ln -s "$source" "$target" else cp "$source" "$target" - if [[ $executable ]]; then + + if [[ $executable == inherit ]]; then + # Don't change file mode if it should match the source. + : + elif [[ $executable ]]; then chmod +x "$target" else chmod -x "$target" diff --git a/modules/systemd.nix b/modules/systemd.nix index 939dc832c..8ee2db659 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -24,17 +24,17 @@ let buildService = style: name: serviceCfg: let - source = pkgs.writeScript "${name}.${style}" (toSystemdIni serviceCfg); + source = pkgs.writeText "${name}.${style}" (toSystemdIni serviceCfg); wantedBy = target: { name = "systemd/user/${target}.wants/${name}.${style}"; - value = { inherit source; executable = false; }; + value = { inherit source; }; }; in singleton { name = "systemd/user/${name}.${style}"; - value = { inherit source; executable = false; }; + value = { inherit source; }; } ++ map wantedBy (serviceCfg.Install.WantedBy or []);