Compare commits

...

6 commits

View file

@ -2,50 +2,43 @@
stdenvNoCC,
mdbook,
nixdoc,
nixosOptionsDoc,
lib,
excluded ? [
".*flake\\.nix$"
"^docs/.*"
],
}:
stdenvNoCC.mkDerivation {
name = "SkyOS-book";
src = ./.;
nativeBuildInputs = [
mdbook
nixdoc
];
patchPhase =
let
excluded = [
".*flake\\.nix$"
"^docs/.*"
];
shouldExclude = relPath: lib.any (pattern: builtins.match pattern relPath != null) excluded;
relPath = file: lib.removePrefix (toString ../. + "/") (toString file);
nixFiles =
with lib.fileset;
let
allFiles = toList (fileFilter (f: f.hasExt "nix") ../.);
in
lib.filter (
file:
let
relPath = lib.removePrefix (toString ../. + "/") (toString file);
in
!shouldExclude relPath
) allFiles;
lib.filter (file: !(lib.any (pattern: builtins.match pattern (relPath file) != null) excluded)) (
toList (fileFilter (f: f.hasExt "nix") ../.)
);
chapters = lib.sort (a: b: a.sortKey < b.sortKey) (
map (
file:
let
relPath = lib.removePrefix (toString ../. + "/") (toString file);
mdPath =
(
if baseNameOf file == "default.nix" then
lib.removeSuffix "/" (dirOf relPath)
lib.removeSuffix "/" (dirOf (relPath file))
else
lib.removeSuffix ".nix" relPath
lib.removeSuffix ".nix" (relPath file)
)
+ ".md";
@ -53,10 +46,11 @@ stdenvNoCC.mkDerivation {
docs = 0;
flake = 1;
devShells = 2;
hosts = 3;
users = 4;
modules = 3;
hosts = 4;
users = 5;
};
order = orderMap.${lib.head (lib.splitString "/" relPath)};
order = orderMap.${lib.head (lib.splitString "/" (relPath file))};
category = lib.removeSuffix ".md" (lib.replaceStrings [ "/" ] [ "." ] mdPath);
title =
@ -74,16 +68,36 @@ stdenvNoCC.mkDerivation {
in
if dirPart == "." then 0 else lib.length (lib.splitString "/" dirPart);
indent = lib.concatStringsSep "" (lib.genList (x: " ") depth);
isModule = (r: lib.hasPrefix "modules/os" r || lib.hasPrefix "modules/home" r) (relPath file);
modulesEval = lib.evalModules {
modules = [
file
{ _module.check = false; }
];
};
moduleOptionsDoc =
(nixosOptionsDoc {
options = lib.removeAttrs modulesEval.options [ "_module" ];
}).optionsCommonMark;
in
{
script = ''
mkdir -p "src/${dirOf mdPath}"
echo "Documenting ${file} > src/${mdPath}"
nixdoc \
--prefix "" \
--category "${category}" \
--description "${title}" \
--anchor-prefix "" \
--file "${file}" > "src/${mdPath}"
''
+ lib.optionalString isModule ''
echo "Adding modules documentation for ${file} > src/${mdPath}"
{
echo
cat ${moduleOptionsDoc}
} >> src/${mdPath}
'';
summaryLine = "${indent}- [${title}](${mdPath})";
sortKey = toString order + mdPath;