base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / nixos / modules / services / matrix / pantalaimon.nix
blob28fcdcee973f2827e208311fa03ae225689b3525
1 { config, lib, pkgs, ... }:
2 let
3   cfg = config.services.pantalaimon-headless;
5   iniFmt = pkgs.formats.ini { };
7   mkConfigFile = name: instanceConfig: iniFmt.generate "pantalaimon.conf" {
8     Default = {
9       LogLevel = instanceConfig.logLevel;
10       Notifications = false;
11     };
13     ${name} = (lib.recursiveUpdate
14       {
15         Homeserver = instanceConfig.homeserver;
16         ListenAddress = instanceConfig.listenAddress;
17         ListenPort = instanceConfig.listenPort;
18         SSL = instanceConfig.ssl;
20         # Set some settings to prevent user interaction for headless operation
21         IgnoreVerification = true;
22         UseKeyring = false;
23       }
24       instanceConfig.extraSettings
25     );
26   };
28   mkPantalaimonService = name: instanceConfig:
29     lib.nameValuePair "pantalaimon-${name}" {
30       description = "pantalaimon instance ${name} - E2EE aware proxy daemon for matrix clients";
31       wants = [ "network-online.target" ];
32       after = [ "network-online.target" ];
33       wantedBy = [ "multi-user.target" ];
35       serviceConfig = {
36         ExecStart = ''${pkgs.pantalaimon-headless}/bin/pantalaimon --config ${mkConfigFile name instanceConfig} --data-path ${instanceConfig.dataPath}'';
37         Restart = "on-failure";
38         DynamicUser = true;
39         NoNewPrivileges = true;
40         PrivateDevices = true;
41         PrivateTmp = true;
42         ProtectHome = true;
43         ProtectSystem = "strict";
44         StateDirectory = "pantalaimon-${name}";
45       };
46     };
49   options.services.pantalaimon-headless.instances = lib.mkOption {
50     default = { };
51     type = lib.types.attrsOf (lib.types.submodule (import ./pantalaimon-options.nix));
52     description = ''
53       Declarative instance config.
55       Note: to use pantalaimon interactively, e.g. for a Matrix client which does not
56       support End-to-end encryption (like `fractal`), refer to the home-manager module.
57     '';
58   };
60   config = lib.mkIf (config.services.pantalaimon-headless.instances != { })
61     {
62       systemd.services = lib.mapAttrs' mkPantalaimonService config.services.pantalaimon-headless.instances;
63     };
65   meta = {
66     maintainers = with lib.maintainers; [ jojosch ];
67   };