{ config, pkgs, ... }: let domain = "push.${config.customOps.domain.fqdn}"; port = 8082; redisPort = 6369; endpointPort = 443; autopush = pkgs.autopush-rs; in { sops.secrets = { "autopush/autoconnect" = {}; "autopush/autoendpoint" = {}; }; environment.systemPackages = [autopush]; services.redis.servers."autopush" = { enable = true; port = redisPort; }; systemd.services = { autopush-autoconnect = { environment = { AUTOCONNECT__DB_DSN = "redis://127.0.0.1:${builtins.toString redisPort}"; AUTOCONNECT__ENDPOINT_SCHEME = "https"; AUTOCONNECT__ENDPOINT_HOSTNAME = "updates.${domain}"; AUTOCONNECT__ENDPOINT_PORT = builtins.toString endpointPort; AUTOCONNECT__ROUTER_HOSTNAME = "localhost"; }; wantedBy = ["multi-user.target"]; serviceConfig = { EnvironmentFile = config.sops.secrets."autopush/autoconnect".path; ExecStart = "${autopush}/bin/autoconnect"; }; }; autopush-autoendpoint = { environment = { AUTOEND__DB_DSN = "redis://127.0.0.1:${builtins.toString redisPort}"; AUTOEND__HOST = "127.0.0.1"; AUTOEND__PORT = builtins.toString port; AUTOEND__ENDPOINT_URL = "https://updates.${domain}"; AUTOEND__HUMAN_LOGS = true; }; wantedBy = ["multi-user.target"]; serviceConfig = { EnvironmentFile = config.sops.secrets."autopush/autoendpoint".path; ExecStart = "${autopush}/bin/autoendpoint"; }; }; }; services.nginx.virtualHosts.${domain} = { forceSSL = true; enableACME = true; locations."/".proxyPass = "http://127.0.0.1:8080"; }; services.nginx.virtualHosts."updates.${domain}" = { forceSSL = true; enableACME = true; locations."/".proxyPass = "http://127.0.0.1:${builtins.toString port}"; }; }