hackens-org-configurations/hosts/hackens-org/modules/staticWebsites.nix
2022-04-03 01:27:30 +02:00

42 lines
1 KiB
Nix

{ 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;
};
};
}