1{ pkgs, lib, config, ... }:
2
3with lib;
4
5let
6 cfg = config.services.shout;
7 shoutHome = "/var/lib/shout";
8
9 defaultConfig = pkgs.runCommand "config.js" { preferLocalBuild = true; } ''
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 (lib.mdDoc "Shout web IRC client");
27
28 private = mkOption {
29 type = types.bool;
30 default = false;
31 description = lib.mdDoc ''
32 Make your shout instance private. You will need to configure user
33 accounts by adding entries in {file}`${shoutHome}/users`.
34 '';
35 };
36
37 listenAddress = mkOption {
38 type = types.str;
39 default = "0.0.0.0";
40 description = lib.mdDoc "IP interface to listen on for http connections.";
41 };
42
43 port = mkOption {
44 type = types.port;
45 default = 9000;
46 description = lib.mdDoc "TCP port to listen on for http connections.";
47 };
48
49 configFile = mkOption {
50 type = types.nullOr types.lines;
51 default = null;
52 description = lib.mdDoc ''
53 Contents of Shout's {file}`config.js` file.
54
55 Used for backward compatibility, recommended way is now to use
56 the `config` 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 = lib.mdDoc ''
74 Shout {file}`config.js` 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.users.shout = {
86 isSystemUser = true;
87 group = "shout";
88 description = "Shout daemon user";
89 home = shoutHome;
90 createHome = true;
91 };
92 users.groups.shout = {};
93
94 systemd.services.shout = {
95 description = "Shout web IRC client";
96 wantedBy = [ "multi-user.target" ];
97 wants = [ "network-online.target" ];
98 after = [ "network-online.target" ];
99 preStart = "ln -sf ${pkgs.writeText "config.js" finalConfigFile} ${shoutHome}/config.js";
100 script = concatStringsSep " " [
101 "${pkgs.shout}/bin/shout"
102 (if cfg.private then "--private" else "--public")
103 "--port" (toString cfg.port)
104 "--host" (toString cfg.listenAddress)
105 "--home" shoutHome
106 ];
107 serviceConfig = {
108 User = "shout";
109 ProtectHome = "true";
110 ProtectSystem = "full";
111 PrivateTmp = "true";
112 };
113 };
114 };
115}