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