add ntfy module

This commit is contained in:
Yan Lin 2025-12-02 03:19:52 +01:00
parent c4354805e5
commit 417453f2f3
3 changed files with 72 additions and 1 deletions

View file

@ -66,6 +66,18 @@
}; };
}; };
# ntfy notification service
ntfy = {
rule = "Host(`ntfy.yanlincs.com`)";
service = "ntfy";
tls = {
certResolver = "cloudflare";
domains = [{
main = "*.yanlincs.com";
}];
};
};
}; };
services = { services = {
@ -115,6 +127,15 @@
}; };
}; };
# ntfy backend
ntfy = {
loadBalancer = {
servers = [{
url = "http://localhost:8080";
}];
};
};
}; };
}; };

View file

@ -9,6 +9,7 @@
../../../modules/traefik.nix ../../../modules/traefik.nix
../../../modules/borg/client.nix ../../../modules/borg/client.nix
../../../modules/login-display.nix ../../../modules/login-display.nix
../../../modules/ntfy.nix
]; ];
# GRUB bootloader with UEFI support # GRUB bootloader with UEFI support

49
modules/ntfy.nix Normal file
View file

@ -0,0 +1,49 @@
{ config, pkgs, lib, ... }:
let
cfg = config.services.ntfy-custom;
in
{
options.services.ntfy-custom = {
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "Port for ntfy to listen on";
};
baseUrl = lib.mkOption {
type = lib.types.str;
default = "https://ntfy.yanlincs.com";
description = "Base URL for ntfy server";
};
};
config = {
services.ntfy-sh = {
enable = true;
settings = {
listen-http = ":${toString cfg.port}";
base-url = cfg.baseUrl;
# Authentication
auth-file = "/var/lib/ntfy-sh/user.db";
auth-default-access = "deny-all";
# File attachments
attachment-cache-dir = "/var/lib/ntfy-sh/attachments";
};
};
# Ensure required directories exist
systemd.tmpfiles.rules = [
"d /var/lib/ntfy-sh 0755 ntfy-sh ntfy-sh -"
"d /var/lib/ntfy-sh/attachments 0755 ntfy-sh ntfy-sh -"
];
};
}
# NOTE: After deployment, manage users via ntfy CLI:
# sudo ntfy user add <username>
# sudo ntfy user change-pass <username>
# sudo ntfy access <username> <topic> <read-write|read-only|write-only|deny-all>
# Example: sudo ntfy access alice "*" read-write