1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-02 16:09:46 +01:00

move syncthing-copy-keys to dedicated variable

This makes it possible to reuse the script in launchd setup.
This commit is contained in:
Peter Kling 2024-08-29 20:21:38 +02:00
parent a42fa14b53
commit 39c4022856

View file

@ -46,6 +46,21 @@ let
install = "${pkgs.coreutils}/bin/install"; install = "${pkgs.coreutils}/bin/install";
syncthing = "${pkgs.syncthing}/bin/syncthing"; 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" ('' updateConfig = pkgs.writers.writeBash "merge-syncthing-config" (''
set -efu set -efu
@ -618,22 +633,7 @@ in {
}; };
Service = { Service = {
ExecStartPre = mkIf (cfg.cert != null || cfg.key != null) "+${ ExecStartPre = mkIf (cfg.cert != null || cfg.key != null) "+${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"
''}
''
}";
ExecStart = escapeShellArgs syncthingArgs; ExecStart = escapeShellArgs syncthingArgs;
Restart = "on-failure"; Restart = "on-failure";
SuccessExitStatus = [ 3 4 ]; SuccessExitStatus = [ 3 4 ];