syncthing: add cfg variable for convenience

This commit is contained in:
Robert Helgesson 2022-01-27 00:30:39 +01:00
parent 86248a2d5c
commit 24ed6e6d4d
Failed to generate hash of commit

View file

@ -2,7 +2,11 @@
with lib; with lib;
{ let
cfg = config.services.syncthing;
in {
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
options = { options = {
@ -52,7 +56,7 @@ with lib;
}; };
config = mkMerge [ config = mkMerge [
(mkIf config.services.syncthing.enable { (mkIf cfg.enable {
home.packages = [ (getOutput "man" pkgs.syncthing) ]; home.packages = [ (getOutput "man" pkgs.syncthing) ];
systemd.user.services = { systemd.user.services = {
@ -67,8 +71,8 @@ with lib;
Service = { Service = {
ExecStart = ExecStart =
"${pkgs.syncthing}/bin/syncthing -no-browser -no-restart -logflags=0" "${pkgs.syncthing}/bin/syncthing -no-browser -no-restart -logflags=0"
+ optionalString (config.services.syncthing.extraOptions != [ ]) + optionalString (cfg.extraOptions != [ ])
(" " + escapeShellArgs config.services.syncthing.extraOptions); (" " + escapeShellArgs cfg.extraOptions);
Restart = "on-failure"; Restart = "on-failure";
SuccessExitStatus = [ 3 4 ]; SuccessExitStatus = [ 3 4 ];
RestartForceExitStatus = [ 3 4 ]; RestartForceExitStatus = [ 3 4 ];
@ -88,20 +92,18 @@ with lib;
}; };
}) })
(mkIf (isAttrs config.services.syncthing.tray (mkIf (isAttrs cfg.tray && cfg.tray.enable) {
&& config.services.syncthing.tray.enable) {
systemd.user.services = { systemd.user.services = {
${config.services.syncthing.tray.package.pname} = { ${cfg.tray.package.pname} = {
Unit = { Unit = {
Description = config.services.syncthing.tray.package.pname; Description = cfg.tray.package.pname;
Requires = [ "tray.target" ]; Requires = [ "tray.target" ];
After = [ "graphical-session-pre.target" "tray.target" ]; After = [ "graphical-session-pre.target" "tray.target" ];
PartOf = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ];
}; };
Service = { Service = {
ExecStart = ExecStart = "${cfg.tray.package}/bin/${cfg.tray.command}";
"${config.services.syncthing.tray.package}/bin/${config.services.syncthing.tray.command}";
}; };
Install = { WantedBy = [ "graphical-session.target" ]; }; Install = { WantedBy = [ "graphical-session.target" ]; };
@ -110,8 +112,7 @@ with lib;
}) })
# deprecated # deprecated
(mkIf (isBool config.services.syncthing.tray (mkIf (isBool cfg.tray && cfg.tray) {
&& config.services.syncthing.tray) {
systemd.user.services = { systemd.user.services = {
"syncthingtray" = { "syncthingtray" = {
Unit = { Unit = {