nixpkgs/nixos/modules/services/networking/shout.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
3.0 KiB
Nix
Raw Normal View History

{ pkgs, lib, config, ... }:
2015-07-31 23:15:18 +00:00
with lib;
let
cfg = config.services.shout;
shoutHome = "/var/lib/shout";
defaultConfig = pkgs.runCommand "config.js" { preferLocalBuild = true; } ''
2016-04-09 21:18:23 +00:00
EDITOR=true ${pkgs.shout}/bin/shout config --home $PWD
mv config.js $out
'';
finalConfigFile = if (cfg.configFile != null) then cfg.configFile else ''
2016-04-09 21:18:23 +00:00
var _ = require('${pkgs.shout}/lib/node_modules/shout/node_modules/lodash')
module.exports = _.merge(
{},
require('${defaultConfig}'),
${builtins.toJSON cfg.config}
)
'';
2015-07-31 23:15:18 +00:00
in {
options.services.shout = {
enable = mkEnableOption "Shout web IRC client";
2015-07-31 23:15:18 +00:00
private = mkOption {
type = types.bool;
default = false;
description = ''
2015-07-31 23:15:18 +00:00
Make your shout instance private. You will need to configure user
accounts by adding entries in {file}`${shoutHome}/users`.
'';
};
listenAddress = mkOption {
type = types.str;
2015-07-31 23:15:18 +00:00
default = "0.0.0.0";
description = "IP interface to listen on for http connections.";
2015-07-31 23:15:18 +00:00
};
port = mkOption {
2021-08-01 11:09:26 +00:00
type = types.port;
2015-07-31 23:15:18 +00:00
default = 9000;
description = "TCP port to listen on for http connections.";
2015-07-31 23:15:18 +00:00
};
configFile = mkOption {
type = types.nullOr types.lines;
default = null;
description = ''
2016-04-09 21:18:23 +00:00
Contents of Shout's {file}`config.js` file.
Used for backward compatibility, recommended way is now to use
the `config` 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;
};
};
description = ''
2016-04-09 21:18:23 +00:00
Shout {file}`config.js` 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-07-31 23:15:18 +00:00
Documentation: http://shout-irc.com/docs/server/configuration.html
'';
};
};
config = mkIf cfg.enable {
users.users.shout = {
isSystemUser = true;
group = "shout";
2015-07-31 23:15:18 +00:00
description = "Shout daemon user";
home = shoutHome;
createHome = true;
};
users.groups.shout = {};
2015-07-31 23:15:18 +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";
2015-07-31 23:15:18 +00:00
script = concatStringsSep " " [
"${pkgs.shout}/bin/shout"
(if cfg.private then "--private" else "--public")
"--port" (toString cfg.port)
"--host" (toString cfg.listenAddress)
2015-07-31 23:15:18 +00:00
"--home" shoutHome
];
serviceConfig = {
User = "shout";
ProtectHome = "true";
ProtectSystem = "full";
PrivateTmp = "true";
};
};
};
}