From dacc9519f5a45a8a32d64fe91ef13cb3f97b9f48 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Tue, 16 Apr 2024 17:11:42 +0200 Subject: [PATCH] home-manager: Include home.activation-script for linux similar to macos --- README.md | 9 --------- modules/home-manager/sops.nix | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a06ad93..9cd82a0 100644 --- a/README.md +++ b/README.md @@ -804,15 +804,6 @@ The secrets are decrypted in a systemd user service called `sops-nix`, so other } ``` -As home-manager does not restart the `sops-nix` unit automatically instruct home-manager to do so: -```nix -{ - home.activation.setupEtc = config.lib.dag.entryAfter [ "writeBoundary" ] '' - /run/current-system/sw/bin/systemctl start --user sops-nix - ''; -} -``` - ## Use with GPG instead of SSH keys If you prefer having a separate GPG key, sops-nix also comes with a helper tool, `sops-init-gpg-key`: diff --git a/modules/home-manager/sops.nix b/modules/home-manager/sops.nix index f4f4b4a..a1c601b 100644 --- a/modules/home-manager/sops.nix +++ b/modules/home-manager/sops.nix @@ -256,15 +256,29 @@ in { }; }; - # darwin: [re]load secrets on home-manager activation - home.activation = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin { - sops-nix = let + # [re]load secrets on home-manager activation + home.activation = let + darwin = let domain-target = "gui/$(id -u ${config.home.username})"; in '' /bin/launchctl bootout ${domain-target}/org.nix-community.home.sops-nix && true /bin/launchctl bootstrap ${domain-target} ${config.home.homeDirectory}/Library/LaunchAgents/org.nix-community.home.sops-nix.plist ''; - }; + linux = let systemctl = config.systemd.user.systemctlPath; in '' + systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true) + + if [[ $systemdStatus == 'running' ]]; then + ${config.systemd.user.systemctlPath} restart --user sops-nix + else + echo "User systemd daemon not running. Probably executed on boot where no manual start/reload is needed." + fi + + unset systemdStatus + ''; + + in { + sops-nix = if pkgs.stdenv.isLinux then linux else darwin; + }; }; }