Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 57 lines 1.6 kB view raw
1{ 2 lib, 3 writers, 4 nixdoc, 5 runCommand, 6 treefmt, 7}: 8let 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; 23in 24{ 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 43 markdown = 44 runCommand "treefmt-functions-doc" 45 { 46 nativeBuildInputs = [ nixdoc ]; 47 } 48 '' 49 nixdoc --file ${./lib.nix} \ 50 --locs ${treefmt.functionsDoc.locations} \ 51 --description "Functions Reference" \ 52 --prefix "pkgs" \ 53 --category "treefmt" \ 54 --anchor-prefix "" \ 55 > $out 56 ''; 57}