2020-04-24 23:36:52 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.shout;
|
|
|
|
shoutHome = "/var/lib/shout";
|
|
|
|
|
|
|
|
defaultConfig = pkgs.runCommand "config.js" { preferLocalBuild = true; } ''
|
|
|
|
EDITOR=true ${pkgs.shout}/bin/shout config --home $PWD
|
|
|
|
mv config.js $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
finalConfigFile = if (cfg.configFile != null) then cfg.configFile else ''
|
|
|
|
var _ = require('${pkgs.shout}/lib/node_modules/shout/node_modules/lodash')
|
|
|
|
|
|
|
|
module.exports = _.merge(
|
|
|
|
{},
|
|
|
|
require('${defaultConfig}'),
|
|
|
|
${builtins.toJSON cfg.config}
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.shout = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Shout web IRC client");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
private = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Make your shout instance private. You will need to configure user
|
2022-08-12 12:06:08 +00:00
|
|
|
accounts by adding entries in {file}`${shoutHome}/users`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "IP interface to listen on for http connections.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-08-11 14:56:57 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 9000;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "TCP port to listen on for http connections.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.nullOr types.lines;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Contents of Shout's {file}`config.js` file.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
Used for backward compatibility, recommended way is now to use
|
2022-08-12 12:06:08 +00:00
|
|
|
the `config` option.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Shout {file}`config.js` contents as attribute set (will be
|
2020-04-24 23:36:52 +00:00
|
|
|
converted to JSON to generate the configuration file).
|
|
|
|
|
|
|
|
The options defined here will be merged to the default configuration file.
|
|
|
|
|
|
|
|
Documentation: http://shout-irc.com/docs/server/configuration.html
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.users.shout = {
|
2021-09-22 15:38:15 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "shout";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Shout daemon user";
|
|
|
|
home = shoutHome;
|
|
|
|
createHome = true;
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
users.groups.shout = {};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.shout = {
|
|
|
|
description = "Shout web IRC client";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
preStart = "ln -sf ${pkgs.writeText "config.js" finalConfigFile} ${shoutHome}/config.js";
|
|
|
|
script = concatStringsSep " " [
|
|
|
|
"${pkgs.shout}/bin/shout"
|
|
|
|
(if cfg.private then "--private" else "--public")
|
|
|
|
"--port" (toString cfg.port)
|
|
|
|
"--host" (toString cfg.listenAddress)
|
|
|
|
"--home" shoutHome
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "shout";
|
|
|
|
ProtectHome = "true";
|
|
|
|
ProtectSystem = "full";
|
|
|
|
PrivateTmp = "true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|