nixpkgs/nixos/modules/services/networking/shout.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

116 lines
3.1 KiB
Nix

{ 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 = {
enable = mkEnableOption "Shout web IRC client";
private = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Make your shout instance private. You will need to configure user
accounts by adding entries in {file}`${shoutHome}/users`.
'';
};
listenAddress = mkOption {
type = types.str;
default = "0.0.0.0";
description = lib.mdDoc "IP interface to listen on for http connections.";
};
port = mkOption {
type = types.port;
default = 9000;
description = lib.mdDoc "TCP port to listen on for http connections.";
};
configFile = mkOption {
type = types.nullOr types.lines;
default = null;
description = lib.mdDoc ''
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 = lib.mdDoc ''
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.
Documentation: http://shout-irc.com/docs/server/configuration.html
'';
};
};
config = mkIf cfg.enable {
users.users.shout = {
isSystemUser = true;
group = "shout";
description = "Shout daemon user";
home = shoutHome;
createHome = true;
};
users.groups.shout = {};
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";
};
};
};
}