File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 11{
2+ lib ,
3+ writers ,
24 nixdoc ,
35 runCommand ,
6+ treefmt ,
47} :
8+ let
9+ root = toString ./. ;
10+ revision = lib . trivial . revisionWithDefault "master" ;
11+ removeRoot = file : lib . removePrefix "/" ( lib . removePrefix root file ) ;
12+
13+ # Import and apply `./lib.nix`, which contains treefmt's public functions
14+ #
15+ # NOTE: we cannot access them via `treefmt.passthru` or `callPackages ./lib.nix { }`,
16+ # because that would be opaque to `unsafeGetAttrPos`.
17+ attrs =
18+ let
19+ fn = import ./lib.nix ;
20+ args = builtins . mapAttrs ( _ : _ : null ) ( builtins . functionArgs fn ) ;
21+ in
22+ fn args ;
23+ in
524{
25+ locations = lib . pipe attrs [
26+ builtins . attrNames
27+ ( builtins . map (
28+ name :
29+ let
30+ pos = builtins . unsafeGetAttrPos name attrs ;
31+ file = removeRoot pos . file ;
32+ line = toString pos . line ;
33+ subpath = "pkgs/by-name/tr/treefmt/${ file } " ;
34+ url = "https://github.com/NixOS/nixpkgs/blob/${ revision } /${ subpath } #L${ line } " ;
35+ in
36+ assert lib . hasPrefix root pos . file ;
37+ lib . nameValuePair "pkgs.treefmt.${ name } " "[${ subpath } :${ line } ](${ url } ) in `<nixpkgs>`"
38+ ) )
39+ builtins . listToAttrs
40+ ( writers . writeJSON "treefmt-function-locations" )
41+ ] ;
42+
643 markdown =
744 runCommand "treefmt-functions-doc"
845 {
946 nativeBuildInputs = [ nixdoc ] ;
1047 }
1148 ''
1249 nixdoc --file ${ ./lib.nix } \
50+ --locs ${ treefmt . functionsDoc . locations } \
1351 --description "Functions Reference" \
1452 --prefix "pkgs" \
1553 --category "treefmt" \
You can’t perform that action at this time.
0 commit comments