diff --git a/modules/home/discord/jellyfin-rpc.nix b/modules/home/discord/jellyfin-rpc.nix index 62c8208..5a6d708 100644 --- a/modules/home/discord/jellyfin-rpc.nix +++ b/modules/home/discord/jellyfin-rpc.nix @@ -50,48 +50,35 @@ in { }; config = lib.mkIf cfg.enable { - systemd.user.services.jellyfin-rpc-configure = { - Service = { - Type = "oneshot"; - ExecStart = - let - jq = lib.getExe pkgs.jq; - api-key-file = config.sops.secrets.jellyfin-rpc-api-key.path; - in pkgs.writeShellScript "jellyfin-rpc-configure" '' - dest=''${XDG_CONFIG_HOME:-$HOME/.config}/jellyfin-rpc/main.json - umask 177 - [[ -f "$dest" ]] && chmod 600 "$dest" - jq < ${jellyfin-rpc-config-template} > "$dest" \ - --rawfile api_key ${api-key-file} \ - '.jellyfin.api_key = $api_key' - ''; - }; + systemd.user.services.jellyfin-rpc-configure = + let api-key-file = config.sops.secrets.jellyfin-rpc-api-key.path; + in { + Unit = { + After = [ "sops-nix.service" ]; + Requires = [ "sops-nix.service" ]; + X-Restart-Triggers = [ api-key-file ]; + }; + Install.WantedBy = [ "default.target" ]; + Service = { + Type = "oneshot"; + ExecStart = + pkgs.writeShellScript "jellyfin-rpc-configure" '' + dest=''${XDG_CONFIG_HOME:-$HOME/.config}/jellyfin-rpc/main.json + mkdir -p "$(dirname "$dest")" + umask 177 + [[ -f "$dest" ]] && chmod 600 "$dest" + ${lib.getExe pkgs.jq} \ + < ${jellyfin-rpc-config-template} \ + > "$dest" \ + --rawfile api_key ${api-key-file} \ + '.jellyfin.api_key = $api_key' + ''; + }; }; - home.activation.jellyfin-rpc-configure = - let - jq = lib.getExe pkgs.jq; - api-key-file = config.sops.secrets.jellyfin-rpc-api-key.path; - in lib.hm.dag.entryAfter ["writeBoundary"] '' - dest=''${XDG_CONFIG_HOME:-$HOME/.config}/jellyfin-rpc/main.json - um=$(umask) - mkdir -p "$(dirname "$dest")" - umask 177 - [[ -f "$dest" ]] && chmod 600 "$dest" - jq < ${jellyfin-rpc-config-template} > "$dest" \ - --rawfile api_key ${api-key-file} \ - '.jellyfin.api_key = $api_key' - umask $(um) - ''; - systemd.user.services.jellyfin-rpc = { - Unit = { - After = ["jellyfin-rpc-configure"]; - Wants = ["jellyfin-rpc-configure"]; - }; - Service = { - ExecStart = lib.getExe pkgs.jellyfin-rpc; - }; + Unit.After = [ "jellyfin-rpc-configure.service" ]; + Service.ExecStart = lib.getExe pkgs.jellyfin-rpc; }; sydnix.sops.secrets.jellyfin-rpc-api-key = {};