2022-12-11 14:56:09 +00:00
|
|
|
{ pkgs, nixpkgs ? { }, libsets }:
|
2018-10-05 15:46:58 +01:00
|
|
|
let
|
2023-04-13 19:33:39 +01:00
|
|
|
revision = pkgs.lib.trivial.revisionWithDefault (nixpkgs.rev or "master");
|
2018-10-05 15:46:58 +01:00
|
|
|
|
2022-12-23 19:57:19 +00:00
|
|
|
libDefPos = prefix: set:
|
|
|
|
builtins.concatMap
|
|
|
|
(name: [{
|
|
|
|
name = builtins.concatStringsSep "." (prefix ++ [name]);
|
2018-10-05 15:46:58 +01:00
|
|
|
location = builtins.unsafeGetAttrPos name set;
|
2022-12-23 19:57:19 +00:00
|
|
|
}] ++ nixpkgsLib.optionals
|
|
|
|
(builtins.length prefix == 0 && builtins.isAttrs set.${name})
|
|
|
|
(libDefPos (prefix ++ [name]) set.${name})
|
|
|
|
) (builtins.attrNames set);
|
2018-10-05 15:46:58 +01:00
|
|
|
|
|
|
|
libset = toplib:
|
|
|
|
builtins.map
|
|
|
|
(subsetname: {
|
|
|
|
subsetname = subsetname;
|
2022-12-23 19:57:19 +00:00
|
|
|
functions = libDefPos [] toplib.${subsetname};
|
2018-10-05 15:46:58 +01:00
|
|
|
})
|
2022-12-12 11:21:59 +00:00
|
|
|
(builtins.map (x: x.name) libsets);
|
2018-10-05 15:46:58 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-11-06 00:57:23 +00:00
|
|
|
removeNixpkgs = removeFilenamePrefix (builtins.toString pkgs.path);
|
2018-10-05 15:46:58 +01:00
|
|
|
|
|
|
|
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>
|
|
|
|
''
|