Files
nixpkgs/pkgs/by-name/tr/treefmt/functions-doc.nix
NAHO c8d4dabc43 pkgs: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --type file \
      . \
      pkgs \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2025-10-04 19:02:37 +02:00

58 lines
1.5 KiB
Nix

{
lib,
writers,
nixdoc,
runCommand,
treefmt,
}:
let
root = toString ./.;
revision = lib.trivial.revisionWithDefault "master";
removeRoot = file: lib.removePrefix "/" (lib.removePrefix root file);
# Import and apply `./lib.nix`, which contains treefmt's public functions
#
# NOTE: we cannot access them via `treefmt.passthru` or `callPackages ./lib.nix { }`,
# because that would be opaque to `unsafeGetAttrPos`.
attrs =
let
fn = import ./lib.nix;
args = builtins.mapAttrs (_: _: null) (builtins.functionArgs fn);
in
fn args;
in
{
locations = lib.pipe attrs [
builtins.attrNames
(map (
name:
let
pos = builtins.unsafeGetAttrPos name attrs;
file = removeRoot pos.file;
line = toString pos.line;
subpath = "pkgs/by-name/tr/treefmt/${file}";
url = "https://github.com/NixOS/nixpkgs/blob/${revision}/${subpath}#L${line}";
in
assert lib.hasPrefix root pos.file;
lib.nameValuePair "pkgs.treefmt.${name}" "[${subpath}:${line}](${url}) in `<nixpkgs>`"
))
builtins.listToAttrs
(writers.writeJSON "treefmt-function-locations")
];
markdown =
runCommand "treefmt-functions-doc"
{
nativeBuildInputs = [ nixdoc ];
}
''
nixdoc --file ${./lib.nix} \
--locs ${treefmt.functionsDoc.locations} \
--description "Functions Reference" \
--prefix "pkgs" \
--category "treefmt" \
--anchor-prefix "" \
> $out
'';
}