diff --git a/profiles/web/docs/default.nix b/profiles/web/docs/default.nix
index 9a49d6d..86f9506 100644
--- a/profiles/web/docs/default.nix
+++ b/profiles/web/docs/default.nix
@@ -1,7 +1,55 @@
-{ config, pkgs, lib, mkDomain, ... }:
+{ config, pkgs, lib, mkDomain, flakes, ... }:
+
+let
+ cfg = config.services.docs-to-host;
+
+ # https://pagefind.app/docs/ui-usage/
+ pagefind-default-ui = ''
+
+
+
+
+ '';
+ # 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
+
{
options = with lib; {
- #services.docs-to-host.enable = mkEnable "docs-to-host";
+ 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" { };
+ };
services.docs-to-host.docs = mkOption {
type = types.listOf (types.submodule {
options = {
@@ -14,7 +62,7 @@
type = types.str;
example = "foobar.html";
default = "";
- description = lib.mdDoc "The basename at which the documentation will be linked";
+ description = lib.mdDoc "The basename to which the documentation entry will be linked. Not needed if index.html exists.";
};
path = mkOption {
type = types.path;
@@ -36,21 +84,35 @@
# TODO: host man pages (man -H)
config = let
- cfg = config.services.docs-to-host;
- mkRow = {dirname, basename, path, desc}: ''${dirname} | ${desc}'';
- mkEntry = {dirname, basename, path, desc}: { name = dirname; path = path; };
+ mkLinkFarmEntry = {dirname, path, ...}: {
+ name = dirname;
+ path = path;
+ };
+ mkRow = {dirname, basename, path, desc}:
+ '' |
${dirname} | ${desc}'';
+ root = pkgs.linkFarm "docs-html" ([{name = "index.html"; path = pkgs.writeText "docs-index.html" ''
+
+ ${lib.optionalString cfg.pagefind.enable
+ pagefind-default-ui
+ }
+
+ URL | Desc
+ ${lib.concatStringsSep "\n" ( builtins.map mkRow cfg.docs ) }
+ |
---|
+ '';
+ }] ++ (builtins.map mkLinkFarmEntry cfg.docs));
in {
- services.nginx.virtualHosts.${mkDomain "docs"} = {
+
+ # 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 {
forceSSL = true; # addSSL = true;
enableACME = true; #useACMEHost = acmeDomain;
- root = pkgs.linkFarm "docs-html" ([{name = "index.html"; path = pkgs.writeText "docs-index.html" ''
-
-
- URL | Desc
- ${lib.concatStringsSep "\n" ( builtins.map mkRow cfg.docs ) }
- |
---|
- '';
- }] ++ (builtins.map mkEntry cfg.docs));
+ root = if cfg.pagefind.enable
+ then addPagefindIndex root
+ else root;
};
};
}
|