at 17.09-beta 3.1 kB view raw
1{ pkgs, lib, config, options, ... }: 2 3with lib; 4 5let 6 cfg = config.services.shout; 7 shoutHome = "/var/lib/shout"; 8 9 defaultConfig = pkgs.runCommand "config.js" {} '' 10 EDITOR=true ${pkgs.shout}/bin/shout config --home $PWD 11 mv config.js $out 12 ''; 13 14 finalConfigFile = if (cfg.configFile != null) then cfg.configFile else '' 15 var _ = require('${pkgs.shout}/lib/node_modules/shout/node_modules/lodash') 16 17 module.exports = _.merge( 18 {}, 19 require('${defaultConfig}'), 20 ${builtins.toJSON cfg.config} 21 ) 22 ''; 23 24in { 25 options.services.shout = { 26 enable = mkEnableOption "Shout web IRC client"; 27 28 private = mkOption { 29 type = types.bool; 30 default = false; 31 description = '' 32 Make your shout instance private. You will need to configure user 33 accounts by adding entries in <filename>${shoutHome}/users</filename>. 34 ''; 35 }; 36 37 listenAddress = mkOption { 38 type = types.string; 39 default = "0.0.0.0"; 40 description = "IP interface to listen on for http connections."; 41 }; 42 43 port = mkOption { 44 type = types.int; 45 default = 9000; 46 description = "TCP port to listen on for http connections."; 47 }; 48 49 configFile = mkOption { 50 type = types.nullOr types.lines; 51 default = null; 52 description = '' 53 Contents of Shout's <filename>config.js</filename> file. 54 55 Used for backward compatibility, recommended way is now to use 56 the <literal>config</literal> option. 57 58 Documentation: http://shout-irc.com/docs/server/configuration.html 59 ''; 60 }; 61 62 config = mkOption { 63 default = {}; 64 type = types.attrs; 65 example = { 66 displayNetwork = false; 67 defaults = { 68 name = "Your Network"; 69 host = "localhost"; 70 port = 6697; 71 }; 72 }; 73 description = '' 74 Shout <filename>config.js</filename> contents as attribute set (will be 75 converted to JSON to generate the configuration file). 76 77 The options defined here will be merged to the default configuration file. 78 79 Documentation: http://shout-irc.com/docs/server/configuration.html 80 ''; 81 }; 82 }; 83 84 config = mkIf cfg.enable { 85 users.extraUsers = singleton { 86 name = "shout"; 87 uid = config.ids.uids.shout; 88 description = "Shout daemon user"; 89 home = shoutHome; 90 createHome = true; 91 }; 92 93 systemd.services.shout = { 94 description = "Shout web IRC client"; 95 wantedBy = [ "multi-user.target" ]; 96 wants = [ "network-online.target" ]; 97 after = [ "network-online.target" ]; 98 preStart = "ln -sf ${pkgs.writeText "config.js" finalConfigFile} ${shoutHome}/config.js"; 99 script = concatStringsSep " " [ 100 "${pkgs.shout}/bin/shout" 101 (if cfg.private then "--private" else "--public") 102 "--port" (toString cfg.port) 103 "--host" (toString cfg.listenAddress) 104 "--home" shoutHome 105 ]; 106 serviceConfig = { 107 User = "shout"; 108 ProtectHome = "true"; 109 ProtectSystem = "full"; 110 PrivateTmp = "true"; 111 }; 112 }; 113 }; 114}