2023-09-22 14:47:39 +02:00
|
|
|
{ config, pkgs, lib, mkDomain, flakes, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.docs-to-host;
|
|
|
|
|
|
|
|
# https://pagefind.app/docs/ui-usage/
|
|
|
|
pagefind-default-ui = ''
|
|
|
|
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
|
|
|
|
<script src="/pagefind/pagefind-ui.js"></script>
|
|
|
|
<div id="search"></div>
|
|
|
|
<script>
|
|
|
|
window.addEventListener('DOMContentLoaded', (event) => {
|
|
|
|
new PagefindUI({ element: "#search", showSubResults: true });
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
'';
|
|
|
|
# TODO: symlink dotfiles to $out
|
|
|
|
# TODO: ability to set fallback for unknown languages, instead of --force-language en
|
|
|
|
# TODO: for some reason pagefind is not able to work with symlinks as input. is it a one-file-system restriction?
|
|
|
|
# TODO: for some reason pagefind requires write access to other files than pagefind/
|
|
|
|
addPagefindIndex = root: pkgs.runCommand "${root.name}-with-pagefind" {
|
|
|
|
nativeBuildInputs = [ cfg.pagefind.package pkgs.rsync ];
|
|
|
|
} ''
|
|
|
|
#mkdir $out
|
|
|
|
#cd $out
|
|
|
|
#ln -s ${root}/* .
|
|
|
|
|
|
|
|
# workaround pagefind shortcomings...
|
|
|
|
mkdir foobar
|
|
|
|
cd foobar
|
|
|
|
time rsync -r --chmod +rw --copy-links ${root}/ .
|
|
|
|
|
|
|
|
test ! -e pagefind || {
|
|
|
|
>&2 echo 'ERROR: `root` input has `pagefind` already in it!'
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
pagefind --site . --force-language en
|
|
|
|
|
|
|
|
mkdir $out
|
|
|
|
ln -s ${root}/* $out/
|
|
|
|
cp -a pagefind $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
2023-02-26 03:53:55 +01:00
|
|
|
{
|
|
|
|
options = with lib; {
|
2023-09-22 14:47:39 +02:00
|
|
|
services.docs-to-host.enable = mkEnableOption (lib.mdDoc "docs-to-host");
|
|
|
|
services.docs-to-host.pagefind = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "pagefind default on index of docs");
|
|
|
|
package = mkPackageOptionMD flakes.unstable.pkgs "pagefind" { };
|
|
|
|
};
|
2023-02-26 03:53:55 +01:00
|
|
|
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 = "";
|
2023-09-22 14:47:39 +02:00
|
|
|
description = lib.mdDoc "The basename to which the documentation entry will be linked. Not needed if index.html exists.";
|
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'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-21 02:25:43 +02:00
|
|
|
# TODO: host man pages (man -H)
|
|
|
|
|
2023-02-26 03:53:55 +01:00
|
|
|
config = let
|
2023-09-22 14:47:39 +02:00
|
|
|
mkLinkFarmEntry = {dirname, path, ...}: {
|
|
|
|
name = dirname;
|
|
|
|
path = path;
|
|
|
|
};
|
|
|
|
mkRow = {dirname, basename, path, desc}:
|
|
|
|
''<tr><td><a href="${dirname}/${basename}">${dirname}</a><td>${desc}'';
|
|
|
|
root = pkgs.linkFarm "docs-html" ([{name = "index.html"; path = pkgs.writeText "docs-index.html" ''
|
|
|
|
<!DOCTYPE html>
|
|
|
|
${lib.optionalString cfg.pagefind.enable
|
|
|
|
pagefind-default-ui
|
|
|
|
}
|
|
|
|
<table>
|
|
|
|
<tr><th>URL<th>Desc
|
|
|
|
${lib.concatStringsSep "\n" ( builtins.map mkRow cfg.docs ) }
|
|
|
|
</table>
|
|
|
|
'';
|
|
|
|
}] ++ (builtins.map mkLinkFarmEntry cfg.docs));
|
2023-02-26 03:53:55 +01:00
|
|
|
in {
|
2023-09-22 14:47:39 +02:00
|
|
|
|
|
|
|
# i assume we import this if needed
|
|
|
|
services.docs-to-host.enable = lib.mkDefault true;
|
|
|
|
services.docs-to-host.pagefind.enable = lib.mkDefault true;
|
|
|
|
|
|
|
|
services.nginx.virtualHosts.${mkDomain "docs"} = lib.mkIf cfg.enable {
|
2023-02-26 03:53:55 +01:00
|
|
|
forceSSL = true; # addSSL = true;
|
|
|
|
enableACME = true; #useACMEHost = acmeDomain;
|
2023-09-22 14:47:39 +02:00
|
|
|
root = if cfg.pagefind.enable
|
|
|
|
then addPagefindIndex root
|
|
|
|
else root;
|
2023-02-26 03:53:55 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|