1
0
mirror of https://github.com/nix-community/home-manager synced 2024-07-07 22:03:27 +02:00

systemd: fix sd-switch error on empty target directory

After update to sd-switch 0.5.0, `home-manager switch` failed with the
following error message:

> Error: Error switching
>
> Caused by:
>     0: Failed to build switch plan
>     1: No such file or directory (os error 2)

This was caused by a non-existing target unit directory due to no user
services being managed by home-manager. This change makes sd-switch
run with pkgs.emptyDirectory as the target in such cases.

Closes: https://github.com/nix-community/home-manager/issues/5552
This commit is contained in:
Kacper Koniuszy 2024-06-26 17:41:48 +02:00 committed by GitHub
parent 92a26bf6df
commit 7a88ff6ad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -336,7 +336,7 @@ in {
${pkgs.sd-switch}/bin/sd-switch \
''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \
''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \
--new-units $newGenPath/home-files/.config/systemd/user
--new-units "$newUnitsDir"
'';
};
@ -354,8 +354,15 @@ in {
warnEcho "Attempting to reload services anyway..."
fi
newUnitsDir="$newGenPath/home-files/.config/systemd/user"
if [[ ! -e $newUnitsDir ]]; then
newUnitsDir=${pkgs.emptyDirectory}
fi
${ensureRuntimeDir} \
${getAttr cfg.startServices cmd}
unset newUnitsDir
else
echo "User systemd daemon not running. Skipping reload."
fi