Compare commits
6 commits
703ff26742
...
69c741e87a
| Author | SHA1 | Date | |
|---|---|---|---|
| 69c741e87a | |||
| e0270ad028 | |||
| 4b91758f07 | |||
| 403cd57c21 | |||
| 7d3133cc3c | |||
| 645fa542ee |
1 changed files with 39 additions and 25 deletions
|
|
@ -2,50 +2,43 @@
|
||||||
stdenvNoCC,
|
stdenvNoCC,
|
||||||
mdbook,
|
mdbook,
|
||||||
nixdoc,
|
nixdoc,
|
||||||
|
nixosOptionsDoc,
|
||||||
lib,
|
lib,
|
||||||
|
excluded ? [
|
||||||
|
".*flake\\.nix$"
|
||||||
|
|
||||||
|
"^docs/.*"
|
||||||
|
],
|
||||||
}:
|
}:
|
||||||
|
|
||||||
stdenvNoCC.mkDerivation {
|
stdenvNoCC.mkDerivation {
|
||||||
name = "SkyOS-book";
|
name = "SkyOS-book";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
mdbook
|
mdbook
|
||||||
nixdoc
|
nixdoc
|
||||||
];
|
];
|
||||||
|
|
||||||
patchPhase =
|
patchPhase =
|
||||||
let
|
let
|
||||||
excluded = [
|
relPath = file: lib.removePrefix (toString ../. + "/") (toString file);
|
||||||
".*flake\\.nix$"
|
|
||||||
|
|
||||||
"^docs/.*"
|
|
||||||
];
|
|
||||||
|
|
||||||
shouldExclude = relPath: lib.any (pattern: builtins.match pattern relPath != null) excluded;
|
|
||||||
|
|
||||||
nixFiles =
|
nixFiles =
|
||||||
with lib.fileset;
|
with lib.fileset;
|
||||||
let
|
lib.filter (file: !(lib.any (pattern: builtins.match pattern (relPath file) != null) excluded)) (
|
||||||
allFiles = toList (fileFilter (f: f.hasExt "nix") ../.);
|
toList (fileFilter (f: f.hasExt "nix") ../.)
|
||||||
in
|
);
|
||||||
lib.filter (
|
|
||||||
file:
|
|
||||||
let
|
|
||||||
relPath = lib.removePrefix (toString ../. + "/") (toString file);
|
|
||||||
in
|
|
||||||
!shouldExclude relPath
|
|
||||||
) allFiles;
|
|
||||||
|
|
||||||
chapters = lib.sort (a: b: a.sortKey < b.sortKey) (
|
chapters = lib.sort (a: b: a.sortKey < b.sortKey) (
|
||||||
map (
|
map (
|
||||||
file:
|
file:
|
||||||
let
|
let
|
||||||
|
|
||||||
relPath = lib.removePrefix (toString ../. + "/") (toString file);
|
|
||||||
mdPath =
|
mdPath =
|
||||||
(
|
(
|
||||||
if baseNameOf file == "default.nix" then
|
if baseNameOf file == "default.nix" then
|
||||||
lib.removeSuffix "/" (dirOf relPath)
|
lib.removeSuffix "/" (dirOf (relPath file))
|
||||||
else
|
else
|
||||||
lib.removeSuffix ".nix" relPath
|
lib.removeSuffix ".nix" (relPath file)
|
||||||
)
|
)
|
||||||
+ ".md";
|
+ ".md";
|
||||||
|
|
||||||
|
|
@ -53,10 +46,11 @@ stdenvNoCC.mkDerivation {
|
||||||
docs = 0;
|
docs = 0;
|
||||||
flake = 1;
|
flake = 1;
|
||||||
devShells = 2;
|
devShells = 2;
|
||||||
hosts = 3;
|
modules = 3;
|
||||||
users = 4;
|
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);
|
category = lib.removeSuffix ".md" (lib.replaceStrings [ "/" ] [ "." ] mdPath);
|
||||||
title =
|
title =
|
||||||
|
|
@ -74,16 +68,36 @@ stdenvNoCC.mkDerivation {
|
||||||
in
|
in
|
||||||
if dirPart == "." then 0 else lib.length (lib.splitString "/" dirPart);
|
if dirPart == "." then 0 else lib.length (lib.splitString "/" dirPart);
|
||||||
indent = lib.concatStringsSep "" (lib.genList (x: " ") depth);
|
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
|
in
|
||||||
{
|
{
|
||||||
script = ''
|
script = ''
|
||||||
mkdir -p "src/${dirOf mdPath}"
|
mkdir -p "src/${dirOf mdPath}"
|
||||||
|
echo "Documenting ${file} > src/${mdPath}"
|
||||||
nixdoc \
|
nixdoc \
|
||||||
--prefix "" \
|
--prefix "" \
|
||||||
--category "${category}" \
|
--category "${category}" \
|
||||||
--description "${title}" \
|
--description "${title}" \
|
||||||
--anchor-prefix "" \
|
--anchor-prefix "" \
|
||||||
--file "${file}" > "src/${mdPath}"
|
--file "${file}" > "src/${mdPath}"
|
||||||
|
''
|
||||||
|
+ lib.optionalString isModule ''
|
||||||
|
echo "Adding modules documentation for ${file} > src/${mdPath}"
|
||||||
|
{
|
||||||
|
echo
|
||||||
|
cat ${moduleOptionsDoc}
|
||||||
|
} >> src/${mdPath}
|
||||||
'';
|
'';
|
||||||
summaryLine = "${indent}- [${title}](${mdPath})";
|
summaryLine = "${indent}- [${title}](${mdPath})";
|
||||||
sortKey = toString order + mdPath;
|
sortKey = toString order + mdPath;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue