From 3612ca58e8d592e58762da9ea650f82b9c7c05d9 Mon Sep 17 00:00:00 2001 From: Nick Hu Date: Tue, 18 May 2021 15:43:17 +0100 Subject: [PATCH] syncthing: make syncthing tray package configurable (#1257) Also sets the default syncthing tray package to https://github.com/Martchus/syncthingtray instead of https://github.com/sieren/QSyncthingTray, which indirectly fixes #603 --- modules/misc/news.nix | 21 ++++ modules/services/syncthing.nix | 100 ++++++++++++++---- tests/default.nix | 1 + tests/modules/services/syncthing/default.nix | 4 + .../tray-as-bool-triggers-warning.nix | 17 +++ tests/modules/services/syncthing/tray.nix | 13 +++ 6 files changed, 133 insertions(+), 23 deletions(-) create mode 100644 tests/modules/services/syncthing/default.nix create mode 100644 tests/modules/services/syncthing/tray-as-bool-triggers-warning.nix create mode 100644 tests/modules/services/syncthing/tray.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index daa86665..270454a5 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2000,6 +2000,27 @@ in login shells. ''; } + + { + time = "2021-05-18T12:22:42+00:00"; + condition = config.services.syncthing != {}; + message = '' + Setting 'services.syncthing.tray' as a boolean will be deprecated in + the future. + + This is to make the syncthing tray package configurable, with + `services.syncthing.tray.package`, following QSyncthingTray becoming + no longer actively maintained. The default syncthing tray package has + also changed to https://github.com/Martchus/syncthingtray. To + continue as before, set `services.syncthing.tray.enable`. + + See + + https://github.com/nix-community/home-manager/pulls/1257 + + for discussion. + ''; + } ]; }; } diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 4622ac2e..f1f39d2b 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -10,9 +10,34 @@ with lib; enable = mkEnableOption "Syncthing continuous file synchronization"; tray = mkOption { - type = types.bool; - default = false; - description = "Whether to enable QSyncthingTray service."; + type = with types; + either bool (submodule { + options = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable a syncthing tray service."; + }; + + command = mkOption { + type = types.str; + default = "syncthingtray"; + defaultText = literalExample "syncthingtray"; + example = literalExample "qsyncthingtray"; + description = "Syncthing tray command to use."; + }; + + package = mkOption { + type = types.package; + default = pkgs.syncthingtray-minimal; + defaultText = literalExample "pkgs.syncthingtray-minimal"; + example = literalExample "pkgs.qsyncthingtray"; + description = "Syncthing tray package to use."; + }; + }; + }); + default = { enable = false; }; + description = "Syncthing tray service configuration."; }; }; }; @@ -43,28 +68,57 @@ with lib; }; }) - (mkIf config.services.syncthing.tray { - systemd.user.services = { - qsyncthingtray = { - Unit = { - Description = "QSyncthingTray"; - After = [ - "graphical-session-pre.target" - "polybar.service" - "taffybar.service" - "stalonetray.service" - ]; - PartOf = [ "graphical-session.target" ]; - }; + (mkIf (isAttrs config.services.syncthing.tray + && config.services.syncthing.tray.enable) { + systemd.user.services = { + ${config.services.syncthing.tray.package.pname} = { + Unit = { + Description = config.services.syncthing.tray.package.pname; + After = [ + "graphical-session-pre.target" + "polybar.service" + "taffybar.service" + "stalonetray.service" + ]; + PartOf = [ "graphical-session.target" ]; + }; - Service = { - Environment = "PATH=${config.home.profileDirectory}/bin"; - ExecStart = "${pkgs.qsyncthingtray}/bin/QSyncthingTray"; - }; + Service = { + ExecStart = + "${config.services.syncthing.tray.package}/bin/${config.services.syncthing.tray.command}"; + }; - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; }; - }; - }) + }) + + # deprecated + (mkIf (isBool config.services.syncthing.tray + && config.services.syncthing.tray) { + systemd.user.services = { + "syncthingtray" = { + Unit = { + Description = "syncthingtray"; + After = [ + "graphical-session-pre.target" + "polybar.service" + "taffybar.service" + "stalonetray.service" + ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = "${pkgs.syncthingtray-minimal}/bin/syncthingtray"; + }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; + warnings = [ + "Specifying 'services.syncthing.tray' as a boolean is deprecated, set 'services.syncthing.tray.enable' instead. See https://github.com/nix-community/home-manager/pull/1257." + ]; + }) ]; } diff --git a/tests/default.nix b/tests/default.nix index 6721c14a..e186ba81 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -114,6 +114,7 @@ import nmt { ./modules/services/polybar ./modules/services/redshift-gammastep ./modules/services/sxhkd + ./modules/services/syncthing ./modules/services/window-managers/i3 ./modules/services/window-managers/sway ./modules/services/wlsunset diff --git a/tests/modules/services/syncthing/default.nix b/tests/modules/services/syncthing/default.nix new file mode 100644 index 00000000..14136fe6 --- /dev/null +++ b/tests/modules/services/syncthing/default.nix @@ -0,0 +1,4 @@ +{ + syncthing-tray = ./tray.nix; + syncthing-tray-as-bool-triggers-warning = ./tray-as-bool-triggers-warning.nix; +} diff --git a/tests/modules/services/syncthing/tray-as-bool-triggers-warning.nix b/tests/modules/services/syncthing/tray-as-bool-triggers-warning.nix new file mode 100644 index 00000000..65e69933 --- /dev/null +++ b/tests/modules/services/syncthing/tray-as-bool-triggers-warning.nix @@ -0,0 +1,17 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + services.syncthing.tray = true; + + test.asserts.warnings.expected = [ + "Specifying 'services.syncthing.tray' as a boolean is deprecated, set 'services.syncthing.tray.enable' instead. See https://github.com/nix-community/home-manager/pull/1257." + ]; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/syncthingtray.service + ''; + }; +} diff --git a/tests/modules/services/syncthing/tray.nix b/tests/modules/services/syncthing/tray.nix new file mode 100644 index 00000000..14388411 --- /dev/null +++ b/tests/modules/services/syncthing/tray.nix @@ -0,0 +1,13 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + services.syncthing.tray.enable = true; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/syncthingtray.service + ''; + }; +}