2018-07-20 21:56:59 +01:00
|
|
|
{ pkgs, lib, config, ... }:
|
2015-08-01 00:15:18 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.shout;
|
|
|
|
shoutHome = "/var/lib/shout";
|
|
|
|
|
2016-04-09 22:18:23 +01:00
|
|
|
defaultConfig = pkgs.runCommand "config.js" {} ''
|
|
|
|
EDITOR=true ${pkgs.shout}/bin/shout config --home $PWD
|
|
|
|
mv config.js $out
|
|
|
|
'';
|
|
|
|
|
2016-04-11 14:35:28 +01:00
|
|
|
finalConfigFile = if (cfg.configFile != null) then cfg.configFile else ''
|
2016-04-09 22:18:23 +01:00
|
|
|
var _ = require('${pkgs.shout}/lib/node_modules/shout/node_modules/lodash')
|
|
|
|
|
|
|
|
module.exports = _.merge(
|
|
|
|
{},
|
|
|
|
require('${defaultConfig}'),
|
|
|
|
${builtins.toJSON cfg.config}
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
|
2015-08-01 00:15:18 +01:00
|
|
|
in {
|
|
|
|
options.services.shout = {
|
|
|
|
enable = mkEnableOption "Shout web IRC client";
|
|
|
|
|
|
|
|
private = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Make your shout instance private. You will need to configure user
|
|
|
|
accounts by adding entries in <filename>${shoutHome}/users</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-12-23 23:22:47 +00:00
|
|
|
listenAddress = mkOption {
|
2015-08-01 00:15:18 +01:00
|
|
|
type = types.string;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = "IP interface to listen on for http connections.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 9000;
|
|
|
|
description = "TCP port to listen on for http connections.";
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.nullOr types.lines;
|
2016-04-11 14:35:28 +01:00
|
|
|
default = null;
|
2016-04-09 22:18:23 +01:00
|
|
|
description = ''
|
|
|
|
Contents of Shout's <filename>config.js</filename> file.
|
|
|
|
|
|
|
|
Used for backward compatibility, recommended way is now to use
|
|
|
|
the <literal>config</literal> option.
|
|
|
|
|
|
|
|
Documentation: http://shout-irc.com/docs/server/configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.attrs;
|
|
|
|
example = {
|
|
|
|
displayNetwork = false;
|
|
|
|
defaults = {
|
|
|
|
name = "Your Network";
|
|
|
|
host = "localhost";
|
|
|
|
port = 6697;
|
|
|
|
};
|
|
|
|
};
|
2015-08-01 00:15:18 +01:00
|
|
|
description = ''
|
2016-04-09 22:18:23 +01:00
|
|
|
Shout <filename>config.js</filename> contents as attribute set (will be
|
|
|
|
converted to JSON to generate the configuration file).
|
|
|
|
|
|
|
|
The options defined here will be merged to the default configuration file.
|
2015-08-01 00:15:18 +01:00
|
|
|
|
|
|
|
Documentation: http://shout-irc.com/docs/server/configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users = singleton {
|
2015-08-01 00:15:18 +01:00
|
|
|
name = "shout";
|
|
|
|
uid = config.ids.uids.shout;
|
|
|
|
description = "Shout daemon user";
|
|
|
|
home = shoutHome;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.shout = {
|
|
|
|
description = "Shout web IRC client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
2016-04-11 14:35:28 +01:00
|
|
|
preStart = "ln -sf ${pkgs.writeText "config.js" finalConfigFile} ${shoutHome}/config.js";
|
2015-08-01 00:15:18 +01:00
|
|
|
script = concatStringsSep " " [
|
|
|
|
"${pkgs.shout}/bin/shout"
|
|
|
|
(if cfg.private then "--private" else "--public")
|
|
|
|
"--port" (toString cfg.port)
|
2015-12-23 23:22:47 +00:00
|
|
|
"--host" (toString cfg.listenAddress)
|
2015-08-01 00:15:18 +01:00
|
|
|
"--home" shoutHome
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "shout";
|
|
|
|
ProtectHome = "true";
|
|
|
|
ProtectSystem = "full";
|
|
|
|
PrivateTmp = "true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|