about summary refs log tree commit diff
path: root/nixpkgs/doc/doc-support/lib-function-locations.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-07-14 15:50:11 +0000
committerAlyssa Ross <hi@alyssa.is>2019-08-14 00:01:17 +0000
commit69a15dd2dc85051ba1436613805f9286850e0596 (patch)
treed53cec2bb5b8d07df1d1919b212cb2deb3628cd6 /nixpkgs/doc/doc-support/lib-function-locations.nix
parent6941276da135c3eb3b50e0be33d92e7d01ccba9a (diff)
parentbeff2f8d75ef2c65017fb25e251337c6bb2e950d (diff)
downloadnixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar.gz
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar.bz2
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar.lz
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar.xz
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.tar.zst
nixlib-69a15dd2dc85051ba1436613805f9286850e0596.zip
Merge commit 'beff2f8d75ef2c65017fb25e251337c6bb2e950d'
v#	modified:   nixpkgs/pkgs/tools/networking/dhcpcd/default.nix
Diffstat (limited to 'nixpkgs/doc/doc-support/lib-function-locations.nix')
-rw-r--r--nixpkgs/doc/doc-support/lib-function-locations.nix85
1 files changed, 85 insertions, 0 deletions
diff --git a/nixpkgs/doc/doc-support/lib-function-locations.nix b/nixpkgs/doc/doc-support/lib-function-locations.nix
new file mode 100644
index 000000000000..ae7036e46264
--- /dev/null
+++ b/nixpkgs/doc/doc-support/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>&lt;nixpkgs&gt;</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>
+    ''