From 39c40228564fd8480c928793d4c251c303f87df8 Mon Sep 17 00:00:00 2001 From: Peter Kling 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 165ff1455..20bbd13ee 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -46,6 +46,21 @@ let install = "${pkgs.coreutils}/bin/install"; syncthing = "${pkgs.syncthing}/bin/syncthing"; + copyKeys = pkgs.writers.writeBash "syncthing-copy-keys" '' + syncthing_dir="''${XDG_STATE_HOME:-$HOME/.local/state}/syncthing" + ${install} -dm700 "$syncthing_dir" + ${optionalString (cfg.cert != null) '' + ${install} -Dm400 ${ + toString cfg.cert + } "$syncthing_dir/cert.pem" + ''} + ${optionalString (cfg.key != null) '' + ${install} -Dm400 ${ + toString cfg.key + } "$syncthing_dir/key.pem" + ''} + ''; + updateConfig = pkgs.writers.writeBash "merge-syncthing-config" ('' set -efu @@ -618,22 +633,7 @@ in { }; Service = { - ExecStartPre = 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" - ${optionalString (cfg.cert != null) '' - ${install} -Dm400 ${ - toString cfg.cert - } "$syncthing_dir/cert.pem" - ''} - ${optionalString (cfg.key != null) '' - ${install} -Dm400 ${ - toString cfg.key - } "$syncthing_dir/key.pem" - ''} - '' - }"; + ExecStartPre = mkIf (cfg.cert != null || cfg.key != null) "+${copyKeys}"; ExecStart = escapeShellArgs syncthingArgs; Restart = "on-failure"; SuccessExitStatus = [ 3 4 ];