hackens-org-configurations/hosts/hackens-org/modules/staticWebsite.nix

39 lines
979 B
Nix
Raw Normal View History

2022-03-31 08:19:43 +00:00
{ lib, config , ... }:
2022-03-31 09:36:51 +02:00
with lib;
let
2022-03-31 08:19:43 +00:00
eachSite = config.services.staticWebsite;
website = { name, ... }: {
2022-03-31 09:36:51 +02:00
options = {
root = mkOption {
type = types.path;
default = "/var/lib/nginx/static/${name}";
description = "Static files path for the website";
};
hostname = mkOption {
2022-03-31 08:19:43 +00:00
type = types.str;
2022-03-31 09:36:51 +02:00
default = name;
description = "Website hostname";
};
};
};
debug = config.my.debug;
in
{
2022-03-31 08:19:43 +00:00
options.services.staticWebsite = lib.mkOption {
type = types.attrsOf (types.submodule website);
2022-03-31 09:36:51 +02:00
description = "Specification of one or more static-websites to serve";
};
2022-03-31 08:19:43 +00:00
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;
};
2022-03-31 09:36:51 +02:00
};
}