From 86248a2d5ca027af2ce605defbb505c4f6706fe1 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 27 Jan 2022 00:29:00 +0100 Subject: [PATCH] syncthing: add option `extraOptions` Fixes #2598 --- modules/services/syncthing.nix | 13 ++++++++++++- tests/modules/services/syncthing/default.nix | 1 + .../modules/services/syncthing/extra-options.nix | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/modules/services/syncthing/extra-options.nix diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index d2f7f2964..fd9e34180 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -9,6 +9,15 @@ with lib; services.syncthing = { enable = mkEnableOption "Syncthing continuous file synchronization"; + extraOptions = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "--gui-apikey=apiKey" ]; + description = '' + Extra command-line arguments to pass to syncthing. + ''; + }; + tray = mkOption { type = with types; either bool (submodule { @@ -57,7 +66,9 @@ with lib; Service = { 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 != [ ]) + (" " + escapeShellArgs config.services.syncthing.extraOptions); Restart = "on-failure"; SuccessExitStatus = [ 3 4 ]; RestartForceExitStatus = [ 3 4 ]; diff --git a/tests/modules/services/syncthing/default.nix b/tests/modules/services/syncthing/default.nix index 14136fe63..86f72b571 100644 --- a/tests/modules/services/syncthing/default.nix +++ b/tests/modules/services/syncthing/default.nix @@ -1,4 +1,5 @@ { + syncthing-extra-options = ./extra-options.nix; syncthing-tray = ./tray.nix; syncthing-tray-as-bool-triggers-warning = ./tray-as-bool-triggers-warning.nix; } diff --git a/tests/modules/services/syncthing/extra-options.nix b/tests/modules/services/syncthing/extra-options.nix new file mode 100644 index 000000000..c78b00f9c --- /dev/null +++ b/tests/modules/services/syncthing/extra-options.nix @@ -0,0 +1,16 @@ +{ config, ... }: + +{ + services.syncthing = { + enable = true; + extraOptions = [ "-foo" ''-bar "baz"'' ]; + }; + + test.stubs.syncthing = { }; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/syncthing.service + assertFileContains home-files/.config/systemd/user/syncthing.service \ + "ExecStart=@syncthing@/bin/syncthing -no-browser -no-restart -logflags=0 '-foo' '-bar \"baz\"'" + ''; +}