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

43 lines
1 KiB
Nix
Raw Normal View History

2022-03-31 10:19:43 +02:00
{ lib, config , ... }:
2022-03-31 09:36:51 +02:00
with lib;
let
2022-04-03 01:27:30 +02:00
eachSite = config.services.staticWebsites;
2022-03-31 10:19:43 +02:00
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 10:19:43 +02:00
type = types.str;
2022-03-31 09:36:51 +02:00
default = name;
description = "Website hostname";
};
};
};
in
{
2022-04-03 01:27:30 +02:00
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;
};
2022-03-31 09:36:51 +02:00
};
2022-03-31 10:19:43 +02: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
};
}