diff --git a/doc/default.nix b/doc/default.nix index 76aba1a03eaf2..a1a696a863ee6 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -5,8 +5,12 @@ let common = import ./common.nix; - lib-docs = import ./doc-support/lib-function-docs.nix { + lib-docs = import ./doc-support/generate-function-docs.nix { inherit pkgs nixpkgs; + library = pkgs.lib; + src = ../lib; + name = "nixpkgs-lib-docs"; + prefix = "lib"; libsets = [ { name = "asserts"; description = "assertion functions"; } { name = "attrsets"; description = "attribute set functions"; } diff --git a/doc/doc-support/lib-function-docs.nix b/doc/doc-support/generate-function-docs.nix similarity index 53% rename from doc/doc-support/lib-function-docs.nix rename to doc/doc-support/generate-function-docs.nix index 5faa99b3e89e0..4d090cd68bdf1 100644 --- a/doc/doc-support/lib-function-docs.nix +++ b/doc/doc-support/generate-function-docs.nix @@ -1,27 +1,31 @@ # Generates the documentation for library functions via nixdoc. -{ pkgs, nixpkgs, libsets }: +{ pkgs, nixpkgs, libsets, library, src, name, prefix }: with pkgs; let - locationsJSON = import ./lib-function-locations.nix { inherit pkgs nixpkgs libsets; }; + locationsJSON = import ./lib-function-locations.nix { inherit pkgs nixpkgs libsets library prefix; }; in stdenv.mkDerivation { - name = "nixpkgs-lib-docs"; - src = ../../lib; + inherit src name; buildInputs = [ nixdoc ]; + env = { + # lower case $prefix is written by setup.sh for ./configure when empty + PREFIX = prefix; + PREFIXDOT = if prefix == "" then "" else "${prefix}."; + }; installPhase = '' function docgen { name=$1 baseName=$2 description=$3 - # TODO: wrap lib.$name in , make nixdoc not escape it + # TODO: wrap ${prefix}$name in , make nixdoc not escape it if [[ -e "../lib/$baseName.nix" ]]; then - nixdoc -c "$name" -d "lib.$name: $description" -l ${locationsJSON} -f "$baseName.nix" > "$out/$name.md" + nixdoc -c "$name" -d "$PREFIXDOT$name: $description" -l ${locationsJSON} -f "$baseName.nix" --prefix "$PREFIX" > "$out/$name.md" else - nixdoc -c "$name" -d "lib.$name: $description" -l ${locationsJSON} -f "$baseName/default.nix" > "$out/$name.md" + nixdoc -c "$name" -d "$PREFIXDOT$name: $description" -l ${locationsJSON} -f "$baseName/default.nix" --prefix "$PREFIX" > "$out/$name.md" fi echo "$out/$name.md" >> "$out/index.md" } diff --git a/doc/doc-support/lib-function-locations.nix b/doc/doc-support/lib-function-locations.nix index e6794617fdd89..98a10d865226d 100644 --- a/doc/doc-support/lib-function-locations.nix +++ b/doc/doc-support/lib-function-locations.nix @@ -1,4 +1,11 @@ -{ pkgs, nixpkgs ? { }, libsets }: +{ pkgs, + nixpkgs ? { }, + # Metadata about the structure of the library in the form of a list of sub-libraries + libsets, + # An instance of the library, as one may use it. This is used for retrieving the locations with `builtins.unsafeGetAttrPos`. + library, + prefix, +}: let revision = pkgs.lib.trivial.revisionWithDefault (nixpkgs.rev or "master"); @@ -22,10 +29,12 @@ let nixpkgsLib = pkgs.lib; + prefixDot = if prefix == "" then "" else prefix + "."; + flattenedLibSubset = { subsetname, functions }: builtins.map (fn: { - name = "lib.${subsetname}.${fn.name}"; + name = "${prefixDot}${subsetname}.${fn.name}"; value = fn.location; }) functions; @@ -44,7 +53,7 @@ let builtins.filter (elem: elem.value != null) (nixpkgsLib.lists.flatten - (locatedlibsets nixpkgsLib)); + (locatedlibsets library)); fnLocationRelative = { name, value }: {