{ inputs, flake, self, }: { pkgs, lib, config, ... }: let cfg = config.hectic.services.element; nonEmptyStr = lib.types.strMatching ".+"; generatedSettings = { default_server_config = { "m.homeserver".base_url = cfg.homeserverBaseUrl; "m.homeserver".server_name = cfg.homeserverServerName; "m.identity_server".base_url = "https://vector.im"; }; room_directory.servers = [ cfg.homeserverServerName ]; jitsi = lib.optionalAttrs (cfg.jitsiPreferredDomain != null) { preferred_domain = cfg.jitsiPreferredDomain; }; default_theme = "dark"; show_labs_settings = true; }; in { options.hectic.services.element = { enable = lib.mkEnableOption "Element web client"; hostName = lib.mkOption { type = nonEmptyStr; description = "FQDN serving the Element web client."; }; homeserverBaseUrl = lib.mkOption { type = nonEmptyStr; description = "Public Matrix homeserver base URL used by Element."; }; homeserverServerName = lib.mkOption { type = nonEmptyStr; description = "Matrix server name presented by Element."; }; jitsiPreferredDomain = lib.mkOption { type = lib.types.nullOr nonEmptyStr; default = null; description = "Preferred Jitsi domain, or null to leave it unset."; }; settings = lib.mkOption { type = lib.types.attrsOf (pkgs.formats.json {}).type; default = {}; description = '' Extra Element config recursively merged over generated defaults. Values here may override generated keys. Settings are PUBLIC in the Nix store and served config.json; do not put secrets here. ''; }; }; config = lib.mkIf cfg.enable { services.nginx.enable = true; services.nginx.virtualHosts.${cfg.hostName} = { enableACME = true; forceSSL = true; locations."= /config.${cfg.hostName}.json".return = "302 /config.json"; root = pkgs.hectic.element-web.override { conf = lib.recursiveUpdate generatedSettings cfg.settings; }; }; }; }