From 7a88ff6ad1e001043f876ebdb1d7460cdfe874d2 Mon Sep 17 00:00:00 2001 From: Kacper Koniuszy <120419423+kkoniuszy@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:41:48 +0200 Subject: [PATCH] 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 --- modules/systemd.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/systemd.nix b/modules/systemd.nix index f209f65dd..1d96ec8d2 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -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