1 { config, options, lib, pkgs, ... }:
4 cfg = config.services.nextcloud.notify_push;
5 cfgN = config.services.nextcloud;
8 options.services.nextcloud.notify_push = {
9 enable = lib.mkEnableOption "Notify push";
11 package = lib.mkOption {
12 type = lib.types.package;
13 default = pkgs.nextcloud-notify_push;
14 defaultText = lib.literalMD "pkgs.nextcloud-notify_push";
15 description = "Which package to use for notify_push";
18 socketPath = lib.mkOption {
20 default = "/run/nextcloud-notify_push/sock";
21 description = "Socket path to use for notify_push";
24 logLevel = lib.mkOption {
25 type = lib.types.enum [ "error" "warn" "info" "debug" "trace" ];
27 description = "Log level";
30 bendDomainToLocalhost = lib.mkOption {
31 type = lib.types.bool;
34 Whether to add an entry to `/etc/hosts` for the configured nextcloud domain to point to `localhost` and add `localhost `to nextcloud's `trusted_proxies` config option.
36 This is useful when nextcloud's domain is not a static IP address and when the reverse proxy cannot be bypassed because the backend connection is done via unix socket.
49 opt: options.services.nextcloud.config.${opt} // {
50 default = config.services.nextcloud.config.${opt};
51 defaultText = "config.services.nextcloud.config.${opt}";
56 config = lib.mkIf cfg.enable {
57 systemd.services.nextcloud-notify_push = let
58 nextcloudUrl = "http${lib.optionalString cfgN.https "s"}://${cfgN.hostName}";
60 description = "Push daemon for Nextcloud clients";
61 documentation = [ "https://github.com/nextcloud/notify_push" ];
63 "phpfpm-nextcloud.service"
64 "redis-nextcloud.service"
66 wantedBy = [ "multi-user.target" ];
68 NEXTCLOUD_URL = nextcloudUrl;
69 SOCKET_PATH = cfg.socketPath;
70 DATABASE_PREFIX = cfg.dbtableprefix;
74 ${cfgN.occ}/bin/nextcloud-occ notify_push:setup ${nextcloudUrl}/push
77 dbType = if cfg.dbtype == "pgsql" then "postgresql" else cfg.dbtype;
78 dbUser = lib.optionalString (cfg.dbuser != null) cfg.dbuser;
79 dbPass = lib.optionalString (cfg.dbpassFile != null) ":$DATABASE_PASSWORD";
80 isSocket = lib.hasPrefix "/" (toString cfg.dbhost);
81 dbHost = lib.optionalString (cfg.dbhost != null) (if
83 if dbType == "postgresql" then "?host=${cfg.dbhost}" else
84 if dbType == "mysql" then "?socket=${cfg.dbhost}" else throw "unsupported dbtype"
87 dbName = lib.optionalString (cfg.dbname != null) "/${cfg.dbname}";
88 dbUrl = "${dbType}://${dbUser}${dbPass}${lib.optionalString (!isSocket) dbHost}${dbName}${lib.optionalString isSocket dbHost}";
89 in lib.optionalString (dbPass != "") ''
90 export DATABASE_PASSWORD="$(<"${cfg.dbpassFile}")"
92 export DATABASE_URL="${dbUrl}"
93 exec ${cfg.package}/bin/notify_push '${cfgN.datadir}/config/config.php'
98 RuntimeDirectory = [ "nextcloud-notify_push" ];
99 Restart = "on-failure";
105 networking.hosts = lib.mkIf cfg.bendDomainToLocalhost {
106 "127.0.0.1" = [ cfgN.hostName ];
107 "::1" = [ cfgN.hostName ];
110 services = lib.mkMerge [
112 nginx.virtualHosts.${cfgN.hostName}.locations."^~ /push/" = {
113 proxyPass = "http://unix:${cfg.socketPath}";
114 proxyWebsockets = true;
115 recommendedProxySettings = true;
119 (lib.mkIf cfg.bendDomainToLocalhost {
120 nextcloud.settings.trusted_proxies = [ "127.0.0.1" "::1" ];