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 = lib.literalExpression "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 dbHostHasPrefix = prefix: lib.hasPrefix prefix (toString cfg.dbhost);
81 isPostgresql = dbType == "postgresql";
82 isMysql = dbType == "mysql";
83 isSocket = (isPostgresql && dbHostHasPrefix "/") || (isMysql && dbHostHasPrefix "localhost:/");
84 dbHost = lib.optionalString (cfg.dbhost != null) (if
86 lib.optionalString isMysql "@localhost"
89 dbOpts = lib.optionalString (cfg.dbhost != null && isSocket) (
90 if isPostgresql then "?host=${cfg.dbhost}" else
91 if isMysql then "?socket=${lib.removePrefix "localhost:" cfg.dbhost}" else throw "unsupported dbtype"
93 dbName = lib.optionalString (cfg.dbname != null) "/${cfg.dbname}";
94 dbUrl = "${dbType}://${dbUser}${dbPass}${dbHost}${dbName}${dbOpts}";
95 in lib.optionalString (dbPass != "") ''
96 export DATABASE_PASSWORD="$(<"${cfg.dbpassFile}")"
98 export DATABASE_URL="${dbUrl}"
99 exec ${cfg.package}/bin/notify_push '${cfgN.datadir}/config/config.php'
104 RuntimeDirectory = [ "nextcloud-notify_push" ];
105 Restart = "on-failure";
111 networking.hosts = lib.mkIf cfg.bendDomainToLocalhost {
112 "127.0.0.1" = [ cfgN.hostName ];
113 "::1" = [ cfgN.hostName ];
116 services = lib.mkMerge [
118 nginx.virtualHosts.${cfgN.hostName}.locations."^~ /push/" = {
119 proxyPass = "http://unix:${cfg.socketPath}";
120 proxyWebsockets = true;
121 recommendedProxySettings = true;
125 (lib.mkIf cfg.bendDomainToLocalhost {
126 nextcloud.settings.trusted_proxies = [ "127.0.0.1" "::1" ];