config/profiles/web/docs/default.nix

55 lines
1.9 KiB
Nix
Raw Normal View History

2023-02-26 03:53:55 +01:00
{ config, pkgs, lib, mkDomain, ... }:
{
options = with lib; {
#services.docs-to-host.enable = mkEnable "docs-to-host";
services.docs-to-host.docs = mkOption {
type = types.listOf (types.submodule {
options = {
2023-02-26 06:11:55 +01:00
dirname = mkOption {
2023-02-26 03:53:55 +01:00
type = types.str;
2023-02-26 06:11:55 +01:00
example = "linux-doc";
description = lib.mdDoc "The relative dirname at which the documentation will be linked";
};
basename = mkOption {
type = types.str;
example = "foobar.html";
default = "";
description = lib.mdDoc "The basename at which the documentation will be linked";
2023-02-26 03:53:55 +01:00
};
path = mkOption {
type = types.path;
example = lib.literalExpression "pkgs.fetchzip {...}";
description = lib.mdDoc "The static html documentation to host";
};
desc = mkOption {
type = types.str;
#description = "A short decription about the hosted documentation in markdown.";
description = "A short decription about the hosted documentation.";
};
};
});
default = [ ];
#description = lib.mdDoc ''TODO'';
};
};
config = let
cfg = config.services.docs-to-host;
2023-02-26 06:11:55 +01:00
mkRow = {dirname, basename, path, desc}: ''<tr><td><a href="${dirname}/${basename}">${dirname}</a><td>${desc}'';
mkEntry = {dirname, basename, path, desc}: { name = dirname; path = path; };
2023-02-26 03:53:55 +01:00
in {
services.nginx.virtualHosts.${mkDomain "docs"} = {
forceSSL = true; # addSSL = true;
enableACME = true; #useACMEHost = acmeDomain;
root = pkgs.linkFarm "docs-html" ([{name = "index.html"; path = pkgs.writeText "docs-index.html" ''
<!DOCTYPE html>
<table>
<tr><th>URL<th>Desc
${lib.concatStringsSep "\n" ( builtins.map mkRow cfg.docs ) }
</table>
'';
}] ++ (builtins.map mkEntry cfg.docs));
};
};
}