at 18.09-beta 3.3 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 "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 = '' 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.freenode] 42 Server="irc.freenode.net: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.freenode" 59 channel="#testing" 60 61 [[gateway.inout]] 62 account="mattermost.work" 63 channel="off-topic" 64 ''; 65 description = '' 66 WARNING: THIS IS INSECURE, as your password will end up in 67 <filename>/nix/store</filename>, thus publicly readable. Use 68 <literal>services.matterbridge.configPath</literal> 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 = '' 77 User which runs the matterbridge service. 78 ''; 79 }; 80 81 group = mkOption { 82 type = types.str; 83 default = "matterbridge"; 84 description = '' 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 = optional (cfg.user == "matterbridge") 96 { name = "matterbridge"; 97 group = "matterbridge"; 98 }; 99 100 users.groups = optional (cfg.group == "matterbridge") 101 { name = "matterbridge"; 102 }; 103 104 systemd.services.matterbridge = { 105 description = "Matterbridge chat platform bridge"; 106 wantedBy = [ "multi-user.target" ]; 107 after = [ "network.target" ]; 108 109 serviceConfig = { 110 User = cfg.user; 111 Group = cfg.group; 112 ExecStart = "${pkgs.matterbridge.bin}/bin/matterbridge -conf ${matterbridgeConfToml}"; 113 Restart = "always"; 114 RestartSec = "10"; 115 }; 116 }; 117 }; 118}