From 4c8647b1ed35d0e1822c7997172786dfa18cd7da Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Wed, 4 Sep 2024 09:22:09 +0100 Subject: [PATCH] trayscale: add module Trayscale is an unofficial GUI wrapper around the Tailscale CLI client. PR #5803 --- modules/lib/maintainers.nix | 8 ++++ modules/misc/news.nix | 10 +++++ modules/modules.nix | 1 + modules/services/trayscale.nix | 39 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/services/trayscale/default.nix | 4 ++ .../services/trayscale/hide-window.nix | 15 +++++++ .../services/trayscale/show-window.nix | 15 +++++++ 8 files changed, 93 insertions(+) create mode 100644 modules/services/trayscale.nix create mode 100644 tests/modules/services/trayscale/default.nix create mode 100644 tests/modules/services/trayscale/hide-window.nix create mode 100644 tests/modules/services/trayscale/show-window.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 9793d5c3f..832e025d3 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -587,4 +587,12 @@ github = "zorrobert"; githubId = 118135271; }; + callumio = { + name = "Callum Leslie"; + email = "git+nix@cleslie.uk"; + github = "callumio"; + githubId = 16057677; + keys = + [{ fingerprint = "BC82 4BB5 1656 D144 285E A0EC D382 C4AF EECE AA90"; }]; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bef867bb4..eae438e26 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1703,6 +1703,16 @@ in { one place. See https://github.com/glanceapp/glance for more. ''; } + + { + time = "2024-09-13T08:58:17+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.trayscale'. + + An unofficial GUI wrapper around the Tailscale CLI client. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index dbeebfbf7..7223fb4bf 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -374,6 +374,7 @@ let ./services/tahoe-lafs.nix ./services/taskwarrior-sync.nix ./services/trayer.nix + ./services/trayscale.nix ./services/twmn.nix ./services/udiskie.nix ./services/unclutter.nix diff --git a/modules/services/trayscale.nix b/modules/services/trayscale.nix new file mode 100644 index 000000000..d9853d7aa --- /dev/null +++ b/modules/services/trayscale.nix @@ -0,0 +1,39 @@ +{ config, lib, pkgs, ... }: + +let cfg = config.services.trayscale; +in { + meta.maintainers = [ lib.hm.maintainers.callumio ]; + + options.services.trayscale = { + enable = lib.mkEnableOption + "An unofficial GUI wrapper around the Tailscale CLI client."; + + package = lib.mkPackageOption pkgs "trayscale" { }; + + hideWindow = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Whether to hide the trayscale window on startup."; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.trayscale" pkgs + lib.platforms.linux) + ]; + + systemd.user.services.trayscale = { + Unit = { + Description = + "An unofficial GUI wrapper around the Tailscale CLI client"; + Requires = [ "tray.target" ]; + After = [ "graphical-session-pre.target" "tray.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Install = { WantedBy = [ "graphical-session.target" ]; }; + Service.ExecStart = toString ([ "${cfg.package}/bin/trayscale" ] + ++ lib.optional cfg.hideWindow "--hide-window"); + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 12bc11da7..82aa2f6c4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -275,6 +275,7 @@ in import nmtSrc { ./modules/services/sxhkd ./modules/services/syncthing/linux ./modules/services/trayer + ./modules/services/trayscale ./modules/services/twmn ./modules/services/udiskie ./modules/services/window-managers/bspwm diff --git a/tests/modules/services/trayscale/default.nix b/tests/modules/services/trayscale/default.nix new file mode 100644 index 000000000..9702b1c7c --- /dev/null +++ b/tests/modules/services/trayscale/default.nix @@ -0,0 +1,4 @@ +{ + trayscale-show-window = ./show-window.nix; + trayscale-hide-window = ./hide-window.nix; +} diff --git a/tests/modules/services/trayscale/hide-window.nix b/tests/modules/services/trayscale/hide-window.nix new file mode 100644 index 000000000..72181e898 --- /dev/null +++ b/tests/modules/services/trayscale/hide-window.nix @@ -0,0 +1,15 @@ +{ ... }: { + services.trayscale = { + enable = true; + hideWindow = true; + }; + + test.stubs = { trayscale = { }; }; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/trayscale.service + assertFileExists $serviceFile + assertFileRegex $serviceFile \ + '^ExecStart=@trayscale@/bin/trayscale --hide-window$' + ''; +} diff --git a/tests/modules/services/trayscale/show-window.nix b/tests/modules/services/trayscale/show-window.nix new file mode 100644 index 000000000..62157ab54 --- /dev/null +++ b/tests/modules/services/trayscale/show-window.nix @@ -0,0 +1,15 @@ +{ ... }: { + services.trayscale = { + enable = true; + hideWindow = false; + }; + + test.stubs = { trayscale = { }; }; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/trayscale.service + assertFileExists $serviceFile + assertFileRegex $serviceFile \ + '^ExecStart=@trayscale@/bin/trayscale$' + ''; +}