{ lib, config , ... }: with lib; let eachSite = config.services.staticWebsites; website = { name, ... }: { options = { root = mkOption { type = types.path; default = "/var/lib/nginx/static/${name}"; description = "Static files path for the website"; }; hostname = mkOption { type = types.str; default = name; description = "Website hostname"; }; }; }; in { options.services.staticWebsites = { sites = mkOption { type = types.attrsOf (types.submodule website); description = "Specification of one or more static websites to serve"; }; debug = mkOption { type = types.bool; default = false; }; }; config = mkIf (eachSite != {}) { services.nginx = { enable = true; virtualHosts = mapAttrs ( hostName: conf: { serverName = conf.hostname; root = conf.root; forceSSL = if debug then false else true; enableACME = if debug then false else true; }) eachSite; }; }; }