From 53efb68b4b098a37b1584757e2e7f4119d7ad92c Mon Sep 17 00:00:00 2001 From: Peter Kling <1018801+pitkling@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:21:38 +0200 Subject: [PATCH] move syncthing-copy-keys to dedicated variable This makes it possible to reuse the script in launchd setup. --- modules/services/syncthing.nix | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 197d00d0c..323cf1e14 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -46,6 +46,21 @@ let install = lib.getExe' pkgs.coreutils "install"; syncthing = lib.getExe cfg.package; + copyKeys = pkgs.writers.writeBash "syncthing-copy-keys" '' + syncthing_dir="''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing" + ${install} -dm700 "$syncthing_dir" + ${lib.optionalString (cfg.cert != null) '' + ${install} -Dm400 ${ + toString cfg.cert + } "$syncthing_dir/cert.pem" + ''} + ${lib.optionalString (cfg.key != null) '' + ${install} -Dm400 ${ + toString cfg.key + } "$syncthing_dir/key.pem" + ''} + ''; + updateConfig = pkgs.writers.writeBash "merge-syncthing-config" ('' set -efu @@ -619,22 +634,7 @@ in { }; Service = { - ExecStartPre = lib.mkIf (cfg.cert != null || cfg.key != null) "+${ - pkgs.writers.writeBash "syncthing-copy-keys" '' - syncthing_dir="''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing" - ${install} -dm700 "$syncthing_dir" - ${lib.optionalString (cfg.cert != null) '' - ${install} -Dm400 ${ - toString cfg.cert - } "$syncthing_dir/cert.pem" - ''} - ${lib.optionalString (cfg.key != null) '' - ${install} -Dm400 ${ - toString cfg.key - } "$syncthing_dir/key.pem" - ''} - '' - }"; + ExecStartPre = lib.mkIf (cfg.cert != null || cfg.key != null) "+${copyKeys}"; ExecStart = lib.escapeShellArgs syncthingArgs; Restart = "on-failure"; SuccessExitStatus = [ 3 4 ];