1 { config, lib, pkgs, ... }:
3 cfg = config.services.ntfy-sh;
5 settingsFormat = pkgs.formats.yaml { };
9 options.services.ntfy-sh = {
10 enable = lib.mkEnableOption "[ntfy-sh](https://ntfy.sh), a push notification service";
12 package = lib.mkPackageOption pkgs "ntfy-sh" { };
17 description = "User the ntfy-sh server runs under.";
20 group = lib.mkOption {
23 description = "Primary group of ntfy-sh user.";
26 settings = lib.mkOption {
27 type = lib.types.submodule {
28 freeformType = settingsFormat.type;
30 base-url = lib.mkOption {
32 example = "https://ntfy.example";
34 Public facing base URL of the service
36 This setting is required for any of the following features:
37 - attachments (to return a download URL)
38 - e-mail sending (for the topic URL in the email footer)
39 - iOS push notifications for self-hosted servers
40 (to calculate the Firebase poll_request topic)
41 - Matrix Push Gateway (to validate that the pushkey is correct)
49 example = lib.literalExpression ''
51 listen-http = ":8080";
56 Configuration for ntfy.sh, supported values are [here](https://ntfy.sh/docs/config/#config-options).
63 configuration = settingsFormat.generate "server.yml" cfg.settings;
66 # to configure access control via the cli
68 etc."ntfy/server.yml".source = configuration;
69 systemPackages = [ cfg.package ];
72 services.ntfy-sh.settings = {
73 auth-file = lib.mkDefault "/var/lib/ntfy-sh/user.db";
74 listen-http = lib.mkDefault "127.0.0.1:2586";
75 attachment-cache-dir = lib.mkDefault "/var/lib/ntfy-sh/attachments";
76 cache-file = lib.mkDefault "/var/lib/ntfy-sh/cache-file.db";
79 systemd.services.ntfy-sh = {
80 description = "Push notifications server";
82 wantedBy = [ "multi-user.target" ];
83 after = [ "network.target" ];
86 ExecStart = "${cfg.package}/bin/ntfy serve -c ${configuration}";
88 StateDirectory = "ntfy-sh";
91 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
93 NoNewPrivileges = true;
94 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
95 ProtectSystem = "full";
96 ProtectKernelTunables = true;
97 ProtectKernelModules = true;
98 ProtectKernelLogs = true;
99 ProtectControlGroups = true;
100 PrivateDevices = true;
101 RestrictSUIDSGID = true;
102 RestrictNamespaces = true;
103 RestrictRealtime = true;
104 MemoryDenyWriteExecute = true;
105 # Upstream Recommandation
110 users.groups = lib.optionalAttrs (cfg.group == "ntfy-sh") {
114 users.users = lib.optionalAttrs (cfg.user == "ntfy-sh") {