mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
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 f52ec0df7c
, 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.
This commit is contained in:
parent
d7537777c3
commit
7a9c873093
2 changed files with 20 additions and 5 deletions
|
@ -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"
|
||||
|
|
|
@ -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 []);
|
||||
|
|
Loading…
Reference in a new issue