at 23.11-pre 3.4 kB view raw
1{ options, config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.matterbridge; 8 9 matterbridgeConfToml = 10 if cfg.configPath == null then 11 pkgs.writeText "matterbridge.toml" (cfg.configFile) 12 else 13 cfg.configPath; 14 15in 16 17{ 18 options = { 19 services.matterbridge = { 20 enable = mkEnableOption (lib.mdDoc "Matterbridge chat platform bridge"); 21 22 configPath = mkOption { 23 type = with types; nullOr str; 24 default = null; 25 example = "/etc/nixos/matterbridge.toml"; 26 description = lib.mdDoc '' 27 The path to the matterbridge configuration file. 28 ''; 29 }; 30 31 configFile = mkOption { 32 type = types.str; 33 example = '' 34 # WARNING: as this file contains credentials, do not use this option! 35 # It is kept only for backwards compatibility, and would cause your 36 # credentials to be in the nix-store, thus with the world-readable 37 # permission bits. 38 # Use services.matterbridge.configPath instead. 39 40 [irc] 41 [irc.libera] 42 Server="irc.libera.chat:6667" 43 Nick="matterbot" 44 45 [mattermost] 46 [mattermost.work] 47 # Do not prefix it with http:// or https:// 48 Server="yourmattermostserver.domain" 49 Team="yourteam" 50 Login="yourlogin" 51 Password="yourpass" 52 PrefixMessagesWithNick=true 53 54 [[gateway]] 55 name="gateway1" 56 enable=true 57 [[gateway.inout]] 58 account="irc.libera" 59 channel="#testing" 60 61 [[gateway.inout]] 62 account="mattermost.work" 63 channel="off-topic" 64 ''; 65 description = lib.mdDoc '' 66 WARNING: THIS IS INSECURE, as your password will end up in 67 {file}`/nix/store`, thus publicly readable. Use 68 `services.matterbridge.configPath` instead. 69 70 The matterbridge configuration file in the TOML file format. 71 ''; 72 }; 73 user = mkOption { 74 type = types.str; 75 default = "matterbridge"; 76 description = lib.mdDoc '' 77 User which runs the matterbridge service. 78 ''; 79 }; 80 81 group = mkOption { 82 type = types.str; 83 default = "matterbridge"; 84 description = lib.mdDoc '' 85 Group which runs the matterbridge service. 86 ''; 87 }; 88 }; 89 }; 90 91 config = mkIf cfg.enable { 92 warnings = optional options.services.matterbridge.configFile.isDefined 93 "The option services.matterbridge.configFile is insecure and should be replaced with services.matterbridge.configPath"; 94 95 users.users = optionalAttrs (cfg.user == "matterbridge") 96 { matterbridge = { 97 group = "matterbridge"; 98 isSystemUser = true; 99 }; 100 }; 101 102 users.groups = optionalAttrs (cfg.group == "matterbridge") 103 { matterbridge = { }; 104 }; 105 106 systemd.services.matterbridge = { 107 description = "Matterbridge chat platform bridge"; 108 wantedBy = [ "multi-user.target" ]; 109 after = [ "network.target" ]; 110 111 serviceConfig = { 112 User = cfg.user; 113 Group = cfg.group; 114 ExecStart = "${pkgs.matterbridge}/bin/matterbridge -conf ${matterbridgeConfToml}"; 115 Restart = "always"; 116 RestartSec = "10"; 117 }; 118 }; 119 }; 120}