2022-01-06 22:04:44 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hacc.websites;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.hacc.websites = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
directory = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "all subdirectories of the given path are expected to contain a (static) website";
|
|
|
|
};
|
|
|
|
ignore = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "subdirectories that shouldn't be published";
|
|
|
|
};
|
2023-02-24 16:33:48 +00:00
|
|
|
builders = mkOption {
|
|
|
|
type = types.lazyAttrsOf types.package;
|
|
|
|
default = {};
|
|
|
|
description = "exposes website builders, for use with nix run";
|
|
|
|
};
|
2022-01-06 22:04:44 +00:00
|
|
|
};
|
|
|
|
|
2023-02-24 16:33:48 +00:00
|
|
|
config = let
|
|
|
|
subdirs =
|
|
|
|
let dirAttrs = filterAttrs
|
|
|
|
(n: v: v == "directory" || lists.elem n cfg.ignore)
|
|
|
|
(builtins.readDir cfg.directory);
|
|
|
|
in mapAttrsToList (n: v: n) dirAttrs;
|
|
|
|
mkWebsiteDrv = subdir:
|
|
|
|
pkgs.callPackage "${cfg.directory}/${subdir}" {};
|
|
|
|
mkWebsiteVHost = subdir: {
|
|
|
|
name = subdir;
|
|
|
|
# the nginx virtualhost config (for all sites) goes in here
|
|
|
|
value = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
|
|
locations."/".root =
|
|
|
|
(mkWebsiteDrv subdir).outPath;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in mkIf cfg.enable {
|
2022-01-06 22:04:44 +00:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts =
|
2023-02-24 16:33:48 +00:00
|
|
|
listToAttrs (map mkWebsiteVHost subdirs);
|
2022-01-06 22:04:44 +00:00
|
|
|
};
|
2023-02-24 16:33:48 +00:00
|
|
|
hacc.websites.builders =
|
|
|
|
listToAttrs (map (subdir: {
|
|
|
|
name = subdir;
|
|
|
|
value = if (mkWebsiteDrv subdir) ? watch then (mkWebsiteDrv subdir).watch else null;
|
|
|
|
}) subdirs);
|
2022-01-06 22:04:44 +00:00
|
|
|
};
|
|
|
|
}
|