nixos/znc: add option to add module packages to znc
Besides that add option for extra znc config and fix a lot of stuff
This commit is contained in:
parent
6c5186cf9b
commit
675d76b00c
|
@ -20,10 +20,15 @@ let
|
||||||
</Pass>
|
</Pass>
|
||||||
";
|
";
|
||||||
|
|
||||||
|
modules = pkgs.buildEnv {
|
||||||
|
name = "znc-modules";
|
||||||
|
paths = cfg.modulePackages;
|
||||||
|
};
|
||||||
|
|
||||||
confOptions = { ... }: {
|
confOptions = { ... }: {
|
||||||
options = {
|
options = {
|
||||||
modules = mkOption {
|
modules = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.string;
|
||||||
default = [ "partyline" "webadmin" "adminlog" "log" ];
|
default = [ "partyline" "webadmin" "adminlog" "log" ];
|
||||||
example = [ "partyline" "webadmin" "adminlog" "log" ];
|
example = [ "partyline" "webadmin" "adminlog" "log" ];
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -31,10 +36,19 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
userModules = mkOption {
|
||||||
|
type = types.listOf types.string;
|
||||||
|
default = [ ];
|
||||||
|
example = [ "fish" "push" ];
|
||||||
|
description = ''
|
||||||
|
A list of user modules to include in the `znc.conf` file.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
userName = mkOption {
|
userName = mkOption {
|
||||||
default = defaultUserName;
|
default = defaultUserName;
|
||||||
example = "johntron";
|
example = "johntron";
|
||||||
type = types.str;
|
type = types.string;
|
||||||
description = ''
|
description = ''
|
||||||
The user name to use when generating the `znc.conf` file.
|
The user name to use when generating the `znc.conf` file.
|
||||||
This is the user name used by the user logging into the ZNC web admin.
|
This is the user name used by the user logging into the ZNC web admin.
|
||||||
|
@ -44,7 +58,7 @@ let
|
||||||
nick = mkOption {
|
nick = mkOption {
|
||||||
default = "znc-user";
|
default = "znc-user";
|
||||||
example = "john";
|
example = "john";
|
||||||
type = types.str;
|
type = types.string;
|
||||||
description = ''
|
description = ''
|
||||||
The IRC nick to use when generating the `znc.conf` file.
|
The IRC nick to use when generating the `znc.conf` file.
|
||||||
'';
|
'';
|
||||||
|
@ -53,7 +67,7 @@ let
|
||||||
passBlock = mkOption {
|
passBlock = mkOption {
|
||||||
default = defaultPassBlock;
|
default = defaultPassBlock;
|
||||||
example = "Must be the block generated by the `znc --makepass` command.";
|
example = "Must be the block generated by the `znc --makepass` command.";
|
||||||
type = types.str;
|
type = types.string;
|
||||||
description = ''
|
description = ''
|
||||||
The pass block to use when generating the `znc.conf` file.
|
The pass block to use when generating the `znc.conf` file.
|
||||||
This is the password used by the user logging into the ZNC web admin.
|
This is the password used by the user logging into the ZNC web admin.
|
||||||
|
@ -80,6 +94,13 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extraZncConf = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.lines;
|
||||||
|
description = ''
|
||||||
|
Extra config to `znc.conf` file
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,9 +149,11 @@ let
|
||||||
QuitMsg = Quit
|
QuitMsg = Quit
|
||||||
RealName = ${confOpts.nick}
|
RealName = ${confOpts.nick}
|
||||||
TimestampFormat = [%H:%M:%S]
|
TimestampFormat = [%H:%M:%S]
|
||||||
|
${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.userModules}
|
||||||
|
|
||||||
${confOpts.passBlock}
|
${confOpts.passBlock}
|
||||||
</User>
|
</User>
|
||||||
|
${confOpts.extraZncConf}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
zncConfFile = pkgs.writeTextFile {
|
zncConfFile = pkgs.writeTextFile {
|
||||||
|
@ -160,7 +183,7 @@ in
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
default = "znc";
|
default = "znc";
|
||||||
example = "john";
|
example = "john";
|
||||||
type = types.str;
|
type = types.string;
|
||||||
description = ''
|
description = ''
|
||||||
The name of an existing user account to use to own the ZNC server process.
|
The name of an existing user account to use to own the ZNC server process.
|
||||||
If not specified, a default user will be created to own the process.
|
If not specified, a default user will be created to own the process.
|
||||||
|
@ -168,8 +191,8 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
dataDir = mkOption {
|
dataDir = mkOption {
|
||||||
default = "/home/${cfg.user}/.znc";
|
default = "/var/lib/znc/";
|
||||||
example = "/home/john/.znc";
|
example = "/home/john/.znc/";
|
||||||
type = types.path;
|
type = types.path;
|
||||||
description = ''
|
description = ''
|
||||||
The data directory. Used for configuration files and modules.
|
The data directory. Used for configuration files and modules.
|
||||||
|
@ -201,6 +224,15 @@ in
|
||||||
'';
|
'';
|
||||||
options = confOptions;
|
options = confOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
modulePackages = mkOption {
|
||||||
|
type = types.listOf types.package;
|
||||||
|
default = [ ];
|
||||||
|
example = [ pkgs.zncModules.fish pkgs.zncModules.push ];
|
||||||
|
description = ''
|
||||||
|
A list of global znc module packages to add to znc.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
mutable = mkOption {
|
mutable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
|
@ -233,25 +265,22 @@ in
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
systemd.services."znc-${cfg.user}" = {
|
systemd.services.znc = {
|
||||||
description = "ZNC Server of ${cfg.user}.";
|
description = "ZNC Server";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.service" ];
|
after = [ "network.service" ];
|
||||||
path = [ pkgs.znc ];
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = "${cfg.user}";
|
User = cfg.user;
|
||||||
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";
|
||||||
};
|
};
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${pkgs.coreutils}/bin/mkdir -p ${cfg.dataDir}
|
|
||||||
${pkgs.coreutils}/bin/chown ${cfg.user} ${cfg.dataDir} -R
|
|
||||||
${pkgs.coreutils}/bin/mkdir -p ${cfg.dataDir}/configs
|
${pkgs.coreutils}/bin/mkdir -p ${cfg.dataDir}/configs
|
||||||
|
|
||||||
# If mutable, regenerate conf file every time.
|
# If mutable, regenerate conf file every time.
|
||||||
${optionalString (!cfg.mutable) ''
|
${optionalString (!cfg.mutable) ''
|
||||||
${pkgs.coreutils}/echo "znc-${cfg.user} is set to be system-managed. Now deleting old znc.conf file to be regenerated."
|
${pkgs.coreutils}/echo "znc is set to be system-managed. Now deleting old znc.conf file to be regenerated."
|
||||||
${pkgs.coreutils}/rm -f ${cfg.dataDir}/configs/znc.conf
|
${pkgs.coreutils}/rm -f ${cfg.dataDir}/configs/znc.conf
|
||||||
''}
|
''}
|
||||||
|
|
||||||
|
@ -259,7 +288,7 @@ in
|
||||||
if [[ ! -f ${cfg.dataDir}/configs/znc.conf ]]; then
|
if [[ ! -f ${cfg.dataDir}/configs/znc.conf ]]; then
|
||||||
${pkgs.coreutils}/bin/echo "No znc.conf file found in ${cfg.dataDir}. Creating one now."
|
${pkgs.coreutils}/bin/echo "No znc.conf file found in ${cfg.dataDir}. Creating one now."
|
||||||
${if (!cfg.mutable)
|
${if (!cfg.mutable)
|
||||||
then "${pkgs.coreutils}/bin/ln --force -s ${zncConfFile} ${cfg.dataDir}/configs/znc.conf"
|
then "${pkgs.coreutils}/bin/ln --force -s ${zncConfFile} ${cfg.dataDir}/.znc/configs/znc.conf"
|
||||||
else ''
|
else ''
|
||||||
${pkgs.coreutils}/bin/cp --no-clobber ${zncConfFile} ${cfg.dataDir}/configs/znc.conf
|
${pkgs.coreutils}/bin/cp --no-clobber ${zncConfFile} ${cfg.dataDir}/configs/znc.conf
|
||||||
${pkgs.coreutils}/bin/chmod u+rw ${cfg.dataDir}/configs/znc.conf
|
${pkgs.coreutils}/bin/chmod u+rw ${cfg.dataDir}/configs/znc.conf
|
||||||
|
@ -269,8 +298,12 @@ in
|
||||||
|
|
||||||
if [[ ! -f ${cfg.dataDir}/znc.pem ]]; then
|
if [[ ! -f ${cfg.dataDir}/znc.pem ]]; then
|
||||||
${pkgs.coreutils}/bin/echo "No znc.pem file found in ${cfg.dataDir}. Creating one now."
|
${pkgs.coreutils}/bin/echo "No znc.pem file found in ${cfg.dataDir}. Creating one now."
|
||||||
${pkgs.znc}/bin/znc --makepem
|
${pkgs.znc}/bin/znc --makepem --datadir ${cfg.dataDir}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Symlink modules
|
||||||
|
rm ${cfg.dataDir}/modules || true
|
||||||
|
ln -fs ${modules}/lib/znc ${cfg.dataDir}/modules
|
||||||
'';
|
'';
|
||||||
script = "${pkgs.znc}/bin/znc --foreground --datadir ${cfg.dataDir} ${toString cfg.extraFlags}";
|
script = "${pkgs.znc}/bin/znc --foreground --datadir ${cfg.dataDir} ${toString cfg.extraFlags}";
|
||||||
};
|
};
|
||||||
|
@ -280,6 +313,7 @@ in
|
||||||
description = "ZNC server daemon owner";
|
description = "ZNC server daemon owner";
|
||||||
group = defaultUser;
|
group = defaultUser;
|
||||||
uid = config.ids.uids.znc;
|
uid = config.ids.uids.znc;
|
||||||
|
home = cfg.dataDir;
|
||||||
createHome = true;
|
createHome = true;
|
||||||
createUser = true;
|
createUser = true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue