znc module: refactor

This commit is contained in:
schneefux 2016-08-01 17:24:13 +02:00
parent c106c47d86
commit ee42e000dd
No known key found for this signature in database
GPG Key ID: 50F2BF336737C2F0
1 changed files with 114 additions and 64 deletions

View File

@ -26,53 +26,35 @@ let
}; };
# Keep znc.conf in nix store, then symlink or copy into `dataDir`, depending on `mutable`. # Keep znc.conf in nix store, then symlink or copy into `dataDir`, depending on `mutable`.
notNull = a: ! isNull a;
mkZncConf = confOpts: '' mkZncConf = confOpts: ''
// Also check http://en.znc.in/wiki/Configuration Version = 1.6.3
AnonIPLimit = 10
ConnectDelay = 5
# Add `LoadModule = x` for each module...
${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.modules} ${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.modules}
MaxBufferSize = 500
ProtectWebSessions = true
SSLCertFile = ${cfg.dataDir}/znc.pem
ServerThrottle = 30
Skin = dark-clouds
StatusPrefix = *
Version = 1.2
<Listener listener0> <Listener l>
AllowIRC = true Port = ${toString confOpts.port}
AllowWeb = true
IPv4 = true IPv4 = true
IPv6 = false IPv6 = true
Port = ${if confOpts.useSSL then "+" else ""}${toString confOpts.port}
SSL = ${if confOpts.useSSL then "true" else "false"} SSL = ${if confOpts.useSSL then "true" else "false"}
</Listener> </Listener>
<User ${confOpts.userName}> <User ${confOpts.userName}>
Admin = true
Allow = *
AltNick = ${confOpts.nick}_
AppendTimestamp = false
AutoClearChanBuffer = false
Buffer = 150
ChanModes = +stn
DenyLoadMod = false
DenySetBindHost = false
Ident = ident
JoinTries = 10
MaxJoins = 0
MaxNetworks = 1
MultiClients = true
Nick = ${confOpts.nick}
PrependTimestamp = true
QuitMsg = Quit
RealName = ${confOpts.nick}
TimestampFormat = [%H:%M:%S]
${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.userModules}
${confOpts.passBlock} ${confOpts.passBlock}
Admin = true
Nick = ${confOpts.nick}
AltNick = ${confOpts.nick}_
Ident = ${confOpts.nick}
RealName = ${confOpts.nick}
${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.userModules}
${ lib.concatStringsSep "\n" (lib.mapAttrsToList (name: net: ''
<Network ${name}>
${concatMapStrings (m: "LoadModule = ${m}\n") net.modules}
Server = ${net.server} ${if net.useSSL then "+" else ""}${toString net.port}
${concatMapStrings (c: "<Chan #${c}>\n</Chan>\n") net.channels}
</Network>
'') confOpts.networks) }
</User> </User>
${confOpts.extraZncConf} ${confOpts.extraZncConf}
''; '';
@ -84,6 +66,62 @@ let
else mkZncConf cfg.confOptions; else mkZncConf cfg.confOptions;
}; };
networkOpts = { ... }: {
options = {
server = mkOption {
type = types.str;
example = "chat.freenode.net";
description = ''
IRC server address.
'';
};
port = mkOption {
type = types.int;
default = 6697;
example = 6697;
description = ''
IRC server port.
'';
};
useSSL = mkOption {
type = types.bool;
default = true;
description = ''
Whether to use SSL to connect to the IRC server.
'';
};
modulePackages = mkOption {
type = types.listOf types.package;
default = [];
example = [ "pkgs.zncModules.push" "pkgs.zncModules.fish" ];
description = ''
External ZNC modules to build.
'';
};
modules = mkOption {
type = types.listOf types.str;
default = [ "simple_away" ];
example = literalExample "[ simple_away sasl ]";
description = ''
ZNC modules to load.
'';
};
channels = mkOption {
type = types.listOf types.str;
default = [];
example = [ "nixos" ];
description = ''
IRC channels to join.
'';
};
};
};
in in
{ {
@ -111,6 +149,15 @@ in
''; '';
}; };
group = mkOption {
default = "";
example = "users";
type = types.string;
description = ''
Group to own the ZNCserver process.
'';
};
dataDir = mkOption { dataDir = mkOption {
default = "/var/lib/znc/"; default = "/var/lib/znc/";
example = "/home/john/.znc/"; example = "/home/john/.znc/";
@ -125,27 +172,16 @@ in
example = "See: http://wiki.znc.in/Configuration"; example = "See: http://wiki.znc.in/Configuration";
type = types.lines; type = types.lines;
description = '' description = ''
The contents of the `znc.conf` file to use when creating it. Config file as generated with `znc --makeconf` to use for the whole ZNC configuration.
If specified, `confOptions` will be ignored, and this value, as-is, will be used. If specified, `confOptions` will be ignored, and this value, as-is, will be used.
If left empty, a conf file with default values will be used. If left empty, a conf file with default values will be used.
Recommended to generate with `znc --makeconf` command.
''; '';
}; };
/* TODO: add to the documentation of the current module:
Values to use when creating a `znc.conf` file.
confOptions = {
modules = [ "log" ];
userName = "john";
nick = "johntron";
};
*/
confOptions = { confOptions = {
modules = mkOption { modules = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = [ "partyline" "webadmin" "adminlog" "log" ]; default = [ "webadmin" "adminlog" ];
example = [ "partyline" "webadmin" "adminlog" "log" ]; example = [ "partyline" "webadmin" "adminlog" "log" ];
description = '' description = ''
A list of modules to include in the `znc.conf` file. A list of modules to include in the `znc.conf` file.
@ -154,8 +190,8 @@ in
userModules = mkOption { userModules = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = [ ]; default = [ "chansaver" "controlpanel" ];
example = [ "fish" "push" ]; example = [ "chansaver" "controlpanel" "fish" "push" ];
description = '' description = ''
A list of user modules to include in the `znc.conf` file. A list of user modules to include in the `znc.conf` file.
''; '';
@ -166,29 +202,42 @@ in
example = "johntron"; example = "johntron";
type = types.string; type = types.string;
description = '' description = ''
The user name to use when generating the `znc.conf` file. The user name used to log in to the ZNC web admin interface.
This is the user name used by the user logging into the ZNC web admin.
''; '';
}; };
networks = mkOption {
default = { };
type = types.loaOf types.optionSet;
description = ''
IRC networks to connect the user to.
'';
options = [ networkOpts ];
example = {
"freenode" = {
server = "chat.freenode.net";
port = 6697;
ssl = true;
modules = [ "simple_away" ];
};
};
};
nick = mkOption { nick = mkOption {
default = "znc-user"; default = "znc-user";
example = "john"; example = "john";
type = types.string; type = types.string;
description = '' description = ''
The IRC nick to use when generating the `znc.conf` file. The IRC nick.
''; '';
}; };
passBlock = mkOption { passBlock = mkOption {
default = defaultPassBlock; example = defaultPassBlock;
example = "Must be the block generated by the `znc --makepass` command.";
type = types.string; type = types.string;
description = '' description = ''
The pass block to use when generating the `znc.conf` file. Generate with znc --makepass.
This is the password used by the user logging into the ZNC web admin. This is the password used to log in to the ZNC web admin interface.
This is the block generated by the `znc --makepass` command.
!!! If not specified, please change this after starting the service. !!!
''; '';
}; };
@ -206,7 +255,7 @@ in
example = true; example = true;
type = types.bool; type = types.bool;
description = '' description = ''
Indicates whether the ZNC server should use SSL when listening on the specified port. Indicates whether the ZNC server should use SSL when listening on the specified port. A self-signed certificate will be generated.
''; '';
}; };
@ -214,7 +263,7 @@ in
default = ""; default = "";
type = types.lines; type = types.lines;
description = '' description = ''
Extra config to `znc.conf` file Extra config to `znc.conf` file.
''; '';
}; };
}; };
@ -265,6 +314,7 @@ in
after = [ "network.service" ]; after = [ "network.service" ];
serviceConfig = { serviceConfig = {
User = cfg.user; User = cfg.user;
Group = cfg.group;
Restart = "always"; Restart = "always";
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID"; ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";