Skip to content

Commit 3cf5447

Browse files
Joker9944khaneliman
andcommitted
gotify-desktop: init module
Co-authored-by: Austin Horstman <[email protected]>
1 parent 7702d14 commit 3cf5447

File tree

9 files changed

+200
-0
lines changed

9 files changed

+200
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ pkgs, ... }:
2+
{
3+
time = "2025-11-24T11:05:54+00:00";
4+
condition = pkgs.stdenv.hostPlatform.isLinux;
5+
message = ''
6+
A new module is available: 'services.gotify-desktop'
7+
8+
gotify-desktop is a small daemon to receive messages from a Gotify server
9+
and forward them as desktop notifications. It supports message priorities,
10+
automatic reconnection, retrieval of missed messages
11+
and automatic deletion of shown messages.
12+
'';
13+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
lib,
3+
pkgs,
4+
config,
5+
...
6+
}:
7+
let
8+
cfg = config.services.gotify-desktop;
9+
tomlFormat = pkgs.formats.toml { };
10+
in
11+
{
12+
meta.maintainers = with lib.hm.maintainers; [
13+
joker9944
14+
];
15+
16+
options.services.gotify-desktop =
17+
let
18+
inherit (lib)
19+
mkEnableOption
20+
mkPackageOption
21+
mkOption
22+
literalExpression
23+
types
24+
;
25+
in
26+
{
27+
enable = mkEnableOption "Gotify daemon to receive messages and forward them as desktop notifications";
28+
29+
package = mkPackageOption pkgs "gotify-desktop" { };
30+
31+
url = mkOption {
32+
type = types.str;
33+
example = "wss://gotify.example.com:8443";
34+
description = ''
35+
Gotify server websocket URL, use wss:// prefix for TLS, or ws:// for unencrypted.
36+
'';
37+
};
38+
39+
token = mkOption {
40+
type = types.oneOf [
41+
types.str
42+
(types.submodule {
43+
options = {
44+
command = mkOption {
45+
type = types.str;
46+
};
47+
};
48+
})
49+
];
50+
example = literalExpression ''
51+
"gotify-token"
52+
or
53+
{ command = "''${lib.getExe pkgs.libsecret} lookup Title 'Gotify token'"; }
54+
or
55+
{ command = "''${lib.getExe' pkgs.coreutils "cat"} /foo/bar/token"; }
56+
'';
57+
description = ''
58+
Secret Gotify client token.
59+
Either directly as string or as command for fetching client token.
60+
'';
61+
};
62+
63+
settings = mkOption {
64+
inherit (tomlFormat) type;
65+
default = { };
66+
example = literalExpression ''
67+
{
68+
# optional, if true, deletes messages that have been handled, defaults to false
69+
gotify.auto_delete = true;
70+
71+
# optional, ignores messages with priority lower than given value, defaults to 0
72+
notification.min_priority = 1;
73+
74+
# optional, run the given command for each message, with the following environment variables set: GOTIFY_MSG_PRIORITY, GOTIFY_MSG_TITLE and GOTIFY_MSG_TEXT.
75+
action.on_msg_command = "/usr/bin/beep";
76+
}
77+
'';
78+
description = ''
79+
Configuration settings for gotify-desktop. All available options can be found here:
80+
<https://github.com/desbma/gotify-desktop/blob/master/README.md#configuration>
81+
'';
82+
};
83+
};
84+
85+
config =
86+
lib.mkIf cfg.enable {
87+
assertions = [
88+
(lib.hm.assertions.assertPlatform "services.gotify-desktop" pkgs lib.platforms.linux)
89+
];
90+
91+
xdg.configFile."gotify-desktop/config.toml".source =
92+
tomlFormat.generate "gotify-desktop-config.toml"
93+
(lib.recursiveUpdate cfg.settings { gotify = { inherit (cfg) url token; }; });
94+
95+
# Based on systemd service example provided by package
96+
# https://github.com/desbma/gotify-desktop/blob/521dbf4d175833b6338856248c7c6b383c1e5fa6/gotify-desktop.service
97+
systemd.user.services.gotify-desktop = {
98+
Unit = {
99+
Description = "Gotify daemon to send desktop notifications";
100+
PartOf = [ "graphical-session.target" ];
101+
};
102+
103+
Service = {
104+
ExecStart = lib.getExe cfg.package;
105+
Restart = "always";
106+
RestartSec = "5s";
107+
};
108+
109+
Install.WantedBy = [ "graphical-session.target" ];
110+
};
111+
};
112+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[gotify]
2+
url = "wss://foo.bar"
3+
4+
[gotify.token]
5+
command = "secret-token-command"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[foo]
2+
bar = "extra"
3+
4+
[gotify]
5+
token = "secret-token"
6+
url = "wss://foo.bar"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[gotify]
2+
token = "secret-token"
3+
url = "wss://foo.bar"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{ lib, pkgs, ... }:
2+
3+
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
4+
gotify-dekstop-str-token = ./gotify-dekstop-str-token.nix;
5+
gotify-dekstop-command-token = ./gotify-dekstop-command-token.nix;
6+
gotify-dekstop-settings = ./gotify-dekstop-settings.nix;
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
services.gotify-desktop = {
3+
enable = true;
4+
url = "wss://foo.bar";
5+
token.command = "secret-token-command";
6+
};
7+
8+
nmt.script = ''
9+
servicePath=home-files/.config/systemd/user
10+
configPath=home-files/.config/gotify-desktop
11+
12+
assertFileExists $servicePath/gotify-desktop.service
13+
assertFileExists $configPath/config.toml
14+
15+
assertFileContent $configPath/config.toml ${./config-command-token.toml}
16+
'';
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
services.gotify-desktop = {
3+
enable = true;
4+
url = "wss://foo.bar";
5+
token = "secret-token";
6+
settings = {
7+
foo.bar = "extra";
8+
};
9+
};
10+
11+
nmt.script = ''
12+
servicePath=home-files/.config/systemd/user
13+
configPath=home-files/.config/gotify-desktop
14+
15+
assertFileExists $servicePath/gotify-desktop.service
16+
assertFileExists $configPath/config.toml
17+
18+
assertFileContent $configPath/config.toml ${./config-settings.toml}
19+
'';
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
services.gotify-desktop = {
3+
enable = true;
4+
url = "wss://foo.bar";
5+
token = "secret-token";
6+
};
7+
8+
nmt.script = ''
9+
servicePath=home-files/.config/systemd/user
10+
configPath=home-files/.config/gotify-desktop
11+
12+
assertFileExists $servicePath/gotify-desktop.service
13+
assertFileExists $configPath/config.toml
14+
15+
assertFileContent $configPath/config.toml ${./config-str-token.toml}
16+
'';
17+
}

0 commit comments

Comments
 (0)