diff options
author | Graham Christensen <graham@grahamc.com> | 2018-10-05 10:46:58 -0400 |
---|---|---|
committer | Graham Christensen <graham@grahamc.com> | 2018-10-05 11:20:46 -0400 |
commit | 5daee73ce41652d21743a7304b4fd3f9da926c35 (patch) | |
tree | 7a799a32287d88d9435855bcdd64437b14efa33a /doc/lib-function-locations.nix | |
parent | 4312cfdbda1855088905a3d9959a4fac362fd051 (diff) | |
download | nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar.gz nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar.bz2 nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar.lz nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar.xz nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.tar.zst nixpkgs-5daee73ce41652d21743a7304b4fd3f9da926c35.zip |
Generate links to function definitions
Hydra passes the full revision in to the input, which we pass through. If we don't get this ,we try to get it from other sources, or default to master which should have the definition in a close-ish location. All published docs should have theURL resolve properly, only local hackers will have the link break.
Diffstat (limited to 'doc/lib-function-locations.nix')
-rw-r--r-- | doc/lib-function-locations.nix | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/doc/lib-function-locations.nix b/doc/lib-function-locations.nix new file mode 100644 index 00000000000..ae7036e4626 --- /dev/null +++ b/doc/lib-function-locations.nix @@ -0,0 +1,85 @@ +{ pkgs ? (import ./.. { }), nixpkgs ? { }}: +let + revision = pkgs.lib.trivial.revisionWithDefault (nixpkgs.revision or "master"); + + libDefPos = set: + builtins.map + (name: { + name = name; + location = builtins.unsafeGetAttrPos name set; + }) + (builtins.attrNames set); + + libset = toplib: + builtins.map + (subsetname: { + subsetname = subsetname; + functions = libDefPos toplib."${subsetname}"; + }) + (builtins.filter + (name: builtins.isAttrs toplib."${name}") + (builtins.attrNames toplib)); + + nixpkgsLib = pkgs.lib; + + flattenedLibSubset = { subsetname, functions }: + builtins.map + (fn: { + name = "lib.${subsetname}.${fn.name}"; + value = fn.location; + }) + functions; + + locatedlibsets = libs: builtins.map flattenedLibSubset (libset libs); + removeFilenamePrefix = prefix: filename: + let + prefixLen = (builtins.stringLength prefix) + 1; # +1 to remove the leading / + filenameLen = builtins.stringLength filename; + substr = builtins.substring prefixLen filenameLen filename; + in substr; + + removeNixpkgs = removeFilenamePrefix (builtins.toString pkgs.path); + + liblocations = + builtins.filter + (elem: elem.value != null) + (nixpkgsLib.lists.flatten + (locatedlibsets nixpkgsLib)); + + fnLocationRelative = { name, value }: + { + inherit name; + value = value // { file = removeNixpkgs value.file; }; + }; + + relativeLocs = (builtins.map fnLocationRelative liblocations); + sanitizeId = builtins.replaceStrings + [ "'" ] + [ "-prime" ]; + + urlPrefix = "https://github.com/NixOS/nixpkgs/blob/${revision}"; + xmlstrings = (nixpkgsLib.strings.concatMapStrings + ({ name, value }: + '' + <section><title>${name}</title> + <para xml:id="${sanitizeId name}"> + Located at + <link + xlink:href="${urlPrefix}/${value.file}#L${builtins.toString value.line}">${value.file}:${builtins.toString value.line}</link> + in <literal><nixpkgs></literal>. + </para> + </section> + '') + relativeLocs); + +in pkgs.writeText + "locations.xml" + '' + <section xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="5"> + <title>All the locations for every lib function</title> + <para>This file is only for inclusion by other files.</para> + ${xmlstrings} + </section> + '' |