at 18.03-beta 2.4 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.matterbridge; 8 9 matterbridgeConfToml = pkgs.writeText "matterbridge.toml" (cfg.configFile); 10 11in 12 13{ 14 options = { 15 services.matterbridge = { 16 enable = mkEnableOption "Matterbridge chat platform bridge"; 17 18 configFile = mkOption { 19 type = types.str; 20 example = '' 21 #WARNING: as this file contains credentials, be sure to set correct file permissions [irc] 22 [irc.freenode] 23 Server="irc.freenode.net:6667" 24 Nick="matterbot" 25 26 [mattermost] 27 [mattermost.work] 28 #do not prefix it wit http:// or https:// 29 Server="yourmattermostserver.domain" 30 Team="yourteam" 31 Login="yourlogin" 32 Password="yourpass" 33 PrefixMessagesWithNick=true 34 35 [[gateway]] 36 name="gateway1" 37 enable=true 38 [[gateway.inout]] 39 account="irc.freenode" 40 channel="#testing" 41 42 [[gateway.inout]] 43 account="mattermost.work" 44 channel="off-topic" 45 ''; 46 description = '' 47 The matterbridge configuration file in the TOML file format. 48 ''; 49 }; 50 user = mkOption { 51 type = types.str; 52 default = "matterbridge"; 53 description = '' 54 User which runs the matterbridge service. 55 ''; 56 }; 57 58 group = mkOption { 59 type = types.str; 60 default = "matterbridge"; 61 description = '' 62 Group which runs the matterbridge service. 63 ''; 64 }; 65 }; 66 }; 67 68 config = mkMerge [ 69 (mkIf cfg.enable { 70 71 users.extraUsers = mkIf (cfg.user == "matterbridge") [ 72 { name = "matterbridge"; 73 group = "matterbridge"; 74 } ]; 75 76 users.extraGroups = mkIf (cfg.group == "matterbridge") [ 77 { name = "matterbridge"; 78 } ]; 79 80 systemd.services.matterbridge = { 81 description = "Matterbridge chat platform bridge"; 82 wantedBy = [ "multi-user.target" ]; 83 after = [ "network.target" ]; 84 85 serviceConfig = { 86 User = cfg.user; 87 Group = cfg.group; 88 ExecStart = "${pkgs.matterbridge.bin}/bin/matterbridge -conf ${matterbridgeConfToml}"; 89 Restart = "always"; 90 RestartSec = "10"; 91 }; 92 }; 93 }) 94 ]; 95} 96