diff --git a/nixos/modules/services/networking/znc.nix b/nixos/modules/services/networking/znc.nix index 56946f37aaf..4d53cd0750f 100644 --- a/nixos/modules/services/networking/znc.nix +++ b/nixos/modules/services/networking/znc.nix @@ -20,10 +20,15 @@ let "; + modules = pkgs.buildEnv { + name = "znc-modules"; + paths = cfg.modulePackages; + }; + confOptions = { ... }: { options = { modules = mkOption { - type = types.listOf types.str; + type = types.listOf types.string; default = [ "partyline" "webadmin" "adminlog" "log" ]; example = [ "partyline" "webadmin" "adminlog" "log" ]; 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 { default = defaultUserName; example = "johntron"; - type = types.str; + type = types.string; description = '' 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. @@ -44,7 +58,7 @@ let nick = mkOption { default = "znc-user"; example = "john"; - type = types.str; + type = types.string; description = '' The IRC nick to use when generating the `znc.conf` file. ''; @@ -53,7 +67,7 @@ let passBlock = mkOption { default = defaultPassBlock; example = "Must be the block generated by the `znc --makepass` command."; - type = types.str; + type = types.string; description = '' 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. @@ -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 RealName = ${confOpts.nick} TimestampFormat = [%H:%M:%S] + ${concatMapStrings (n: "LoadModule = ${n}\n") confOpts.userModules} ${confOpts.passBlock} + ${confOpts.extraZncConf} ''; zncConfFile = pkgs.writeTextFile { @@ -160,7 +183,7 @@ in user = mkOption { default = "znc"; example = "john"; - type = types.str; + type = types.string; description = '' 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. @@ -168,8 +191,8 @@ in }; dataDir = mkOption { - default = "/home/${cfg.user}/.znc"; - example = "/home/john/.znc"; + default = "/var/lib/znc/"; + example = "/home/john/.znc/"; type = types.path; description = '' The data directory. Used for configuration files and modules. @@ -201,6 +224,15 @@ in ''; 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 { default = false; @@ -233,25 +265,22 @@ in config = mkIf cfg.enable { - systemd.services."znc-${cfg.user}" = { - description = "ZNC Server of ${cfg.user}."; + systemd.services.znc = { + description = "ZNC Server"; wantedBy = [ "multi-user.target" ]; after = [ "network.service" ]; - path = [ pkgs.znc ]; serviceConfig = { - User = "${cfg.user}"; + User = cfg.user; Restart = "always"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID"; }; 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 # If mutable, regenerate conf file every time. ${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 ''} @@ -259,7 +288,7 @@ in if [[ ! -f ${cfg.dataDir}/configs/znc.conf ]]; then ${pkgs.coreutils}/bin/echo "No znc.conf file found in ${cfg.dataDir}. Creating one now." ${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 '' ${pkgs.coreutils}/bin/cp --no-clobber ${zncConfFile} ${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 ${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 + + # 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}"; }; @@ -280,6 +313,7 @@ in description = "ZNC server daemon owner"; group = defaultUser; uid = config.ids.uids.znc; + home = cfg.dataDir; createHome = true; createUser = true; };