stuebinm
eb07f34672
idea is to have a directory `websites/` which contains all our static sites, with the name of each subdirectory also being their domain. Then Nix can just read that directory during build-time and automatically generate nginx virtualHosts for all of them (note that the subdirectories have to contain a `default.nix` specifying how to build the site for that to work). Thus we could avoid the dependency on gitlab pages.
53 lines
1.4 KiB
Nix
53 lines
1.4 KiB
Nix
{ 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";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
services.nginx = {
|
|
enable = true;
|
|
virtualHosts =
|
|
let
|
|
subdirs =
|
|
let dirAttrs = filterAttrs
|
|
(n: v: v == "directory" || lists.elem n cfg.ignore)
|
|
(builtins.readDir cfg.directory);
|
|
in mapAttrsToList (n: v: n) dirAttrs;
|
|
|
|
mkWebsite = subdir: {
|
|
name = subdir;
|
|
# the nginx virtualhost config (for all sites) goes in here
|
|
value = {
|
|
enableACME = true;
|
|
forceSSL = true;
|
|
|
|
# naive string interpolation is safe here since nix will always immediately
|
|
# resolve relative paths to absolute paths; it's not lazy about that.
|
|
locations."/".root =
|
|
(pkgs.callPackage "${cfg.directory}/${subdir}" {}).outPath;
|
|
};
|
|
};
|
|
in listToAttrs (map mkWebsite subdirs);
|
|
};
|
|
};
|
|
}
|