2024-07-18 21:33:29 +00:00
|
|
|
{ nixpkgsPath, revision, libsetsJSON }:
|
2018-10-05 14:46:58 +00:00
|
|
|
let
|
2024-07-18 21:33:29 +00:00
|
|
|
lib = import (nixpkgsPath + "/lib");
|
|
|
|
libsets = builtins.fromJSON libsetsJSON;
|
2018-10-05 14:46:58 +00:00
|
|
|
|
2022-12-23 19:57:19 +00:00
|
|
|
libDefPos = prefix: set:
|
|
|
|
builtins.concatMap
|
|
|
|
(name: [{
|
|
|
|
name = builtins.concatStringsSep "." (prefix ++ [name]);
|
2018-10-05 14:46:58 +00:00
|
|
|
location = builtins.unsafeGetAttrPos name set;
|
2024-07-18 21:33:29 +00:00
|
|
|
}] ++ lib.optionals
|
2022-12-23 19:57:19 +00:00
|
|
|
(builtins.length prefix == 0 && builtins.isAttrs set.${name})
|
|
|
|
(libDefPos (prefix ++ [name]) set.${name})
|
|
|
|
) (builtins.attrNames set);
|
2018-10-05 14:46:58 +00:00
|
|
|
|
|
|
|
libset = toplib:
|
|
|
|
builtins.map
|
|
|
|
(subsetname: {
|
|
|
|
subsetname = subsetname;
|
2022-12-23 19:57:19 +00:00
|
|
|
functions = libDefPos [] toplib.${subsetname};
|
2018-10-05 14:46:58 +00:00
|
|
|
})
|
2022-12-12 11:21:59 +00:00
|
|
|
(builtins.map (x: x.name) libsets);
|
2018-10-05 14:46:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-07-18 21:33:29 +00:00
|
|
|
removeNixpkgs = removeFilenamePrefix (builtins.toString nixpkgsPath);
|
2018-10-05 14:46:58 +00:00
|
|
|
|
|
|
|
liblocations =
|
|
|
|
builtins.filter
|
|
|
|
(elem: elem.value != null)
|
2024-07-18 21:33:29 +00:00
|
|
|
(lib.lists.flatten
|
|
|
|
(locatedlibsets lib));
|
2018-10-05 14:46:58 +00:00
|
|
|
|
|
|
|
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}";
|
2023-03-25 20:38:26 +00:00
|
|
|
jsonLocs = builtins.listToAttrs
|
|
|
|
(builtins.map
|
|
|
|
({ name, value }: {
|
|
|
|
name = sanitizeId name;
|
|
|
|
value =
|
|
|
|
let
|
|
|
|
text = "${value.file}:${builtins.toString value.line}";
|
|
|
|
target = "${urlPrefix}/${value.file}#L${builtins.toString value.line}";
|
|
|
|
in
|
|
|
|
"[${text}](${target}) in `<nixpkgs>`";
|
|
|
|
})
|
|
|
|
relativeLocs);
|
2018-10-05 14:46:58 +00:00
|
|
|
|
2023-03-25 20:38:26 +00:00
|
|
|
in
|
2024-07-18 21:33:29 +00:00
|
|
|
jsonLocs
|