mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-22 10:19:39 +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:
parent
8bc5e4c9b2
commit
53efb68b4b
1 changed files with 16 additions and 16 deletions
|
|
@ -46,6 +46,21 @@ let
|
||||||
install = lib.getExe' pkgs.coreutils "install";
|
install = lib.getExe' pkgs.coreutils "install";
|
||||||
syncthing = lib.getExe cfg.package;
|
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" (''
|
updateConfig = pkgs.writers.writeBash "merge-syncthing-config" (''
|
||||||
set -efu
|
set -efu
|
||||||
|
|
||||||
|
|
@ -619,22 +634,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
Service = {
|
Service = {
|
||||||
ExecStartPre = lib.mkIf (cfg.cert != null || cfg.key != null) "+${
|
ExecStartPre = lib.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"
|
|
||||||
${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"
|
|
||||||
''}
|
|
||||||
''
|
|
||||||
}";
|
|
||||||
ExecStart = lib.escapeShellArgs syncthingArgs;
|
ExecStart = lib.escapeShellArgs syncthingArgs;
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
SuccessExitStatus = [ 3 4 ];
|
SuccessExitStatus = [ 3 4 ];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue