diff options
| author | Preston Pan <ret2pop@gmail.com> | 2026-02-12 17:37:56 -0800 |
|---|---|---|
| committer | Preston Pan <ret2pop@gmail.com> | 2026-02-12 17:37:56 -0800 |
| commit | ef4bd15026b83f487cf064e7b7ce098cc8aca375 (patch) | |
| tree | d6b8e7a57633164082792ab28932bea24513e2bb /nix/modules/ntfy-sh.nix | |
| parent | 6a4f95482fa2c0faeafa028eae164d00c6418ac3 (diff) | |
fix vps, maddy, everything works
Diffstat (limited to 'nix/modules/ntfy-sh.nix')
| -rw-r--r-- | nix/modules/ntfy-sh.nix | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/nix/modules/ntfy-sh.nix b/nix/modules/ntfy-sh.nix index 9311af2..0eeac78 100644 --- a/nix/modules/ntfy-sh.nix +++ b/nix/modules/ntfy-sh.nix @@ -1,12 +1,48 @@ -{ lib, config, ... }: +{ pkgs, lib, config, ... }: { services.ntfy-sh = { -# enable = lib.mkDefault config.monorepo.profiles.server.enable; - enable = false; + enable = lib.mkDefault config.monorepo.profiles.server.enable; settings = { base-url = "https://ntfy.${config.monorepo.vars.remoteHost}"; listen-http = "127.0.0.1:2586"; envrionmentFile = "/run/secrets/ntfy"; + auth-file = "/var/lib/ntfy-sh/user.db"; + auth-default-access = "deny-all"; + enable-login = true; }; }; + systemd.services.ntfy-sh = { + serviceConfig = { + EnvironmentFile = "/run/secrets/ntfy"; + }; + postStart = lib.mkForce '' + # 1. Wait for the server to initialize the database + echo "Waiting for ntfy auth database to appear..." + TIMEOUT=30 + while [ ! -f /var/lib/ntfy-sh/user.db ]; do + sleep 1 + TIMEOUT=$((TIMEOUT-1)) + if [ $TIMEOUT -le 0 ]; then + echo "Timed out waiting for database creation!" + exit 1 + fi + done + + echo "Database found. Configuring admin user..." + + # 2. Define the username + ADMIN_USER="ret2pop" + + # 3. Check if user exists, create if missing + # We pipe the password twice because 'ntfy user add' asks for confirmation + if ! ${pkgs.ntfy-sh}/bin/ntfy user list | grep -q "$ADMIN_USER"; then + echo "Creating admin user $ADMIN_USER..." + printf "$ADMIN_PASSWORD\n$ADMIN_PASSWORD" | \ + ${pkgs.ntfy-sh}/bin/ntfy user add --role=admin "$ADMIN_USER" + echo "User created." + else + echo "Admin user already exists." + fi + ''; + }; } |
