{ config, pkgs, lib, ... }: let inherit (lib) mkEnableOption mkOption types; cfg = config.services.wa2k; in { options.services.wa2k = { enable = mkEnableOption "webserver for wa2k.com"; port = mkOption { type = types.port; default = 8080; example = 8080; description = '' The listening port on localhost to bind the wa2k.com server to. ''; }; openFirewall = mkOption { type = types.bool; default = false; example = true; description = '' Whether the wa2k listening port should be automatically opened in the system's firewall. ''; }; }; config = { networking.firewall.allowedTCPPorts = lib.optional (cfg.enable && cfg.openFirewall) cfg.port; # REF: https://nixos.wiki/wiki/Static_Web_Server services.static-web-server = { enable = cfg.enable; listen = "[::]:${builtins.toString cfg.port}"; root = "${pkgs.wa2k-website}/www"; configuration = { general = { directory-listing = false; }; }; }; }; }