diff --git a/docs/docgen.nix b/docs/docgen.nix index b63b181..227bd56 100644 --- a/docs/docgen.nix +++ b/docs/docgen.nix @@ -2,43 +2,50 @@ stdenvNoCC, mdbook, nixdoc, - nixosOptionsDoc, lib, - excluded ? [ - ".*flake\\.nix$" - - "^docs/.*" - ], }: - stdenvNoCC.mkDerivation { name = "SkyOS-book"; src = ./.; - nativeBuildInputs = [ mdbook nixdoc ]; - patchPhase = let - relPath = file: lib.removePrefix (toString ../. + "/") (toString file); + excluded = [ + ".*flake\\.nix$" + + "^docs/.*" + ]; + + shouldExclude = relPath: lib.any (pattern: builtins.match pattern relPath != null) excluded; + nixFiles = with lib.fileset; - lib.filter (file: !(lib.any (pattern: builtins.match pattern (relPath file) != null) excluded)) ( - toList (fileFilter (f: f.hasExt "nix") ../.) - ); + let + allFiles = 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) ( map ( file: let + + relPath = lib.removePrefix (toString ../. + "/") (toString file); mdPath = ( if baseNameOf file == "default.nix" then - lib.removeSuffix "/" (dirOf (relPath file)) + lib.removeSuffix "/" (dirOf relPath) else - lib.removeSuffix ".nix" (relPath file) + lib.removeSuffix ".nix" relPath ) + ".md"; @@ -46,11 +53,10 @@ stdenvNoCC.mkDerivation { docs = 0; flake = 1; devShells = 2; - modules = 3; - hosts = 4; - users = 5; + hosts = 3; + users = 4; }; - order = orderMap.${lib.head (lib.splitString "/" (relPath file))}; + order = orderMap.${lib.head (lib.splitString "/" relPath)}; category = lib.removeSuffix ".md" (lib.replaceStrings [ "/" ] [ "." ] mdPath); title = @@ -68,36 +74,16 @@ 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;