mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2025-03-15 21:08:26 +00:00
74 lines
2.3 KiB
Nix
74 lines
2.3 KiB
Nix
{ ... }: {
|
|
perSystem = { config, self', inputs', pkgs, lib, ... }:
|
|
let
|
|
inherit (lib) filter any hasPrefix concatMap removePrefix;
|
|
|
|
libNix = import ../lib.nix { inherit lib; };
|
|
eval = libNix.evalFlakeModule { self = { }; } { };
|
|
opts = eval.options;
|
|
|
|
filterTransformOptions = { sourceName, sourcePath, baseUrl }:
|
|
let sourcePathStr = toString sourcePath;
|
|
in
|
|
opt:
|
|
let declarations = concatMap
|
|
(decl:
|
|
if hasPrefix sourcePathStr (toString decl)
|
|
then
|
|
let subpath = removePrefix sourcePathStr (toString decl);
|
|
in [{ url = baseUrl + subpath; name = sourceName + subpath; }]
|
|
else [ ]
|
|
)
|
|
opt.declarations;
|
|
in
|
|
if declarations == [ ]
|
|
then opt // { visible = false; }
|
|
else opt // { inherit declarations; };
|
|
|
|
optionsDoc = { sourceName, baseUrl, sourcePath, title }: pkgs.runCommand "${sourceName}-doc"
|
|
{
|
|
nativeBuildInputs = [ pkgs.libxslt.bin ];
|
|
inputDoc = (pkgs.nixosOptionsDoc {
|
|
options = opts;
|
|
documentType = "none";
|
|
transformOptions = filterTransformOptions {
|
|
inherit sourceName baseUrl sourcePath;
|
|
};
|
|
}).optionsDocBook;
|
|
inherit title;
|
|
} ''
|
|
xsltproc --stringparam title "$title" \
|
|
-o $out ${./options.xsl} \
|
|
"$inputDoc"
|
|
'';
|
|
in
|
|
{
|
|
|
|
packages = {
|
|
|
|
siteContent = pkgs.stdenvNoCC.mkDerivation {
|
|
name = "site";
|
|
nativeBuildInputs = [ pkgs.pandoc pkgs.libxslt.bin ];
|
|
src = lib.cleanSourceWith {
|
|
filter = path: type:
|
|
path == ./.
|
|
|| baseNameOf path == "index.html";
|
|
src = ./.;
|
|
};
|
|
coreOptions = optionsDoc {
|
|
title = "Core Options";
|
|
sourceName = "flake-parts";
|
|
baseUrl = "https://github.com/hercules-ci/flake-parts/blob/main";
|
|
sourcePath = ../.;
|
|
};
|
|
buildPhase = ''
|
|
pandoc --verbose --from docbook --to html5 $coreOptions >options.html
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p $out
|
|
cp *.html $out/
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|