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
|
@ -225,11 +225,26 @@ in
|
||||||
install -m "$mode" "$source" "$target"
|
install -m "$mode" "$source" "$target"
|
||||||
else
|
else
|
||||||
[[ -x $source ]] && isExecutable=1 || isExecutable=""
|
[[ -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"
|
ln -s "$source" "$target"
|
||||||
else
|
else
|
||||||
cp "$source" "$target"
|
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"
|
chmod +x "$target"
|
||||||
else
|
else
|
||||||
chmod -x "$target"
|
chmod -x "$target"
|
||||||
|
|
|
@ -24,17 +24,17 @@ let
|
||||||
|
|
||||||
buildService = style: name: serviceCfg:
|
buildService = style: name: serviceCfg:
|
||||||
let
|
let
|
||||||
source = pkgs.writeScript "${name}.${style}" (toSystemdIni serviceCfg);
|
source = pkgs.writeText "${name}.${style}" (toSystemdIni serviceCfg);
|
||||||
|
|
||||||
wantedBy = target:
|
wantedBy = target:
|
||||||
{
|
{
|
||||||
name = "systemd/user/${target}.wants/${name}.${style}";
|
name = "systemd/user/${target}.wants/${name}.${style}";
|
||||||
value = { inherit source; executable = false; };
|
value = { inherit source; };
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
singleton {
|
singleton {
|
||||||
name = "systemd/user/${name}.${style}";
|
name = "systemd/user/${name}.${style}";
|
||||||
value = { inherit source; executable = false; };
|
value = { inherit source; };
|
||||||
}
|
}
|
||||||
++
|
++
|
||||||
map wantedBy (serviceCfg.Install.WantedBy or []);
|
map wantedBy (serviceCfg.Install.WantedBy or []);
|
||||||
|
|
Loading…
Reference in a new issue