hackens-org-configurations/hosts/hackens-org/modules/staticWebsite.nix
2022-03-31 08:19:43 +00:00

38 lines
979 B
Nix

{ lib, config , ... }:
with lib;
let
eachSite = config.services.staticWebsite;
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";
};
};
};
debug = config.my.debug;
in
{
options.services.staticWebsite = lib.mkOption {
type = types.attrsOf (types.submodule website);
description = "Specification of one or more static-websites to serve";
};
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;
};
};
}