···6161 Configuration for ntfy.sh, supported values are [here](https://ntfy.sh/docs/config/#config-options).
6262 '';
6363 };
6464+6565+ environmentFile = lib.mkOption {
6666+ type = lib.types.nullOr lib.types.path;
6767+ default = null;
6868+ example = "/run/secrets/ntfy";
6969+ description = ''
7070+ Path to a file containing extra ntfy environment variables in the systemd `EnvironmentFile`
7171+ format. Refer to the [documentation](https://docs.ntfy.sh/config/) for config options.
7272+7373+ This can be used to pass secrets such as creating declarative users or token without putting them in the Nix store.
7474+ '';
7575+ };
6476 };
65776678 config =
···109121 MemoryDenyWriteExecute = true;
110122 # Upstream Recommendation
111123 LimitNOFILE = 20500;
124124+ EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
112125 };
113126 };
114127
+33-19
nixos/tests/ntfy-sh.nix
···11-import ./make-test-python.nix {
22- name = "ntfy-sh";
11+import ./make-test-python.nix (
22+ { pkgs, ... }:
33+ {
44+ name = "ntfy-sh";
3544- nodes.machine =
55- { ... }:
66- {
77- services.ntfy-sh.enable = true;
88- services.ntfy-sh.settings.base-url = "http://localhost:2586";
99- };
66+ nodes.machine =
77+ { ... }:
88+ {
99+ services.ntfy-sh.enable = true;
1010+ services.ntfy-sh.settings.base-url = "http://localhost:2586";
10111111- testScript = ''
1212- import json
1212+ # Create a user with user:123
1313+ services.ntfy-sh.environmentFile = pkgs.writeText "ntfy.env" ''
1414+ NTFY_AUTH_DEFAULT_ACCESS='deny-all'
1515+ NTFY_AUTH_USERS='user:$2a$12$W2v7IQhkayvJOYRpg6YEruxj.jUO3R2xQOU7s1vC3HzLLB9gSKJ9.:user'
1616+ NTFY_AUTH_ACCESS='user:test:rw'
1717+ '';
1818+ };
13191414- msg = "Test notification"
2020+ testScript = ''
2121+ import json
15221616- machine.wait_for_unit("multi-user.target")
2323+ msg = "Test notification"
17241818- machine.wait_for_open_port(2586)
2525+ machine.wait_for_unit("multi-user.target")
19262020- machine.succeed(f"curl -d '{msg}' localhost:2586/test")
2727+ machine.wait_for_open_port(2586)
21282222- notif = json.loads(machine.succeed("curl -s localhost:2586/test/json?poll=1"))
2929+ machine.succeed(f"curl -u user:1234 -d '{msg}' localhost:2586/test")
23302424- assert msg == notif["message"], "Wrong message"
3131+ # If we have a user, receive a message
3232+ notif = json.loads(machine.succeed("curl -u user:1234 -s localhost:2586/test/json?poll=1"))
3333+ assert msg == notif["message"], "Wrong message"
25342626- machine.succeed("ntfy user list")
2727- '';
2828-}
3535+ # If we have no user, we should get forbidden, making sure the default access config works
3636+ notif = json.loads(machine.succeed("curl -s localhost:2586/test/json?poll=1"))
3737+ assert 403 == notif["http"], f"Should return 403, got {notif["http"]}"
3838+3939+ machine.succeed("ntfy user list")
4040+ '';
4141+ }
4242+)