diff options
author | Silvan Mosberger <infinisil@icloud.com> | 2018-08-21 21:05:20 +0200 |
---|---|---|
committer | Silvan Mosberger <infinisil@icloud.com> | 2018-10-13 15:04:53 +0200 |
commit | 4eee2cd0e03657dfb39e3e7c93460442e3d2d86c (patch) | |
tree | 16510e4d397f9b20853bae0626dc944dc8f3d14b /nixos/modules/services/networking/znc/default.nix | |
parent | ac6f4851480e3a7016a2257a62c34ed46dcea789 (diff) | |
download | nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar.gz nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar.bz2 nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar.lz nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar.xz nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.tar.zst nixpkgs-4eee2cd0e03657dfb39e3e7c93460442e3d2d86c.zip |
nixos/znc: move to own folder
Move legacy options to separate file
Diffstat (limited to 'nixos/modules/services/networking/znc/default.nix')
-rw-r--r-- | nixos/modules/services/networking/znc/default.nix | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/nixos/modules/services/networking/znc/default.nix b/nixos/modules/services/networking/znc/default.nix new file mode 100644 index 00000000000..e2526550caf --- /dev/null +++ b/nixos/modules/services/networking/znc/default.nix @@ -0,0 +1,170 @@ +{ config, lib, pkgs, ...}: + +with lib; + +let + cfg = config.services.znc; + + defaultUser = "znc"; # Default user to own process. + + modules = pkgs.buildEnv { + name = "znc-modules"; + paths = cfg.modulePackages; + }; + +in + +{ + + imports = [ + ./options.nix + ]; + + ###### Interface + + options = { + services.znc = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Enable a ZNC service for a user. + ''; + }; + + user = mkOption { + default = "znc"; + example = "john"; + 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. + ''; + }; + + group = mkOption { + default = ""; + example = "users"; + type = types.string; + description = '' + Group to own the ZNCserver process. + ''; + }; + + dataDir = mkOption { + default = "/var/lib/znc/"; + example = "/home/john/.znc/"; + type = types.path; + description = '' + The data directory. Used for configuration files and modules. + ''; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = '' + Whether to open ports in the firewall for ZNC. + ''; + }; + + modulePackages = mkOption { + type = types.listOf types.package; + default = [ ]; + example = literalExample "[ pkgs.zncModules.fish pkgs.zncModules.push ]"; + description = '' + A list of global znc module packages to add to znc. + ''; + }; + + mutable = mkOption { + default = true; + type = types.bool; + description = '' + Indicates whether to allow the contents of the `dataDir` directory to be changed + by the user at run-time. + If true, modifications to the ZNC configuration after its initial creation are not + overwritten by a NixOS system rebuild. + If false, the ZNC configuration is rebuilt by every system rebuild. + If the user wants to manage the ZNC service using the web admin interface, this value + should be set to true. + ''; + }; + + extraFlags = mkOption { + default = [ ]; + example = [ "--debug" ]; + type = types.listOf types.str; + description = '' + Extra flags to use when executing znc command. + ''; + }; + }; + }; + + + ###### Implementation + + config = mkIf cfg.enable { + + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ ]; # TODO: Add port + }; + + systemd.services.znc = { + description = "ZNC Server"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.service" ]; + serviceConfig = { + User = cfg.user; + Group = cfg.group; + Restart = "always"; + ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID"; + }; + preStart = '' + ${pkgs.coreutils}/bin/mkdir -p ${cfg.dataDir}/configs + + # If mutable, regenerate conf file every time. + ${optionalString (!cfg.mutable) '' + ${pkgs.coreutils}/bin/echo "znc is set to be system-managed. Now deleting old znc.conf file to be regenerated." + ${pkgs.coreutils}/bin/rm -f ${cfg.dataDir}/configs/znc.conf + ''} + + # Ensure essential files exist. + 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/cp --no-clobber ${/* TODO */"zncConfFile"} ${cfg.dataDir}/configs/znc.conf + ${pkgs.coreutils}/bin/chmod u+rw ${cfg.dataDir}/configs/znc.conf + ${pkgs.coreutils}/bin/chown ${cfg.user} ${cfg.dataDir}/configs/znc.conf + fi + + 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 --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}"; + }; + + users.users = optional (cfg.user == defaultUser) + { name = defaultUser; + description = "ZNC server daemon owner"; + group = defaultUser; + uid = config.ids.uids.znc; + home = cfg.dataDir; + createHome = true; + }; + + users.groups = optional (cfg.user == defaultUser) + { name = defaultUser; + gid = config.ids.gids.znc; + members = [ defaultUser ]; + }; + + }; +} |