jtojnar / nixpkgs-hammering

Beat your package expressions into a shape
MIT License
245 stars 14 forks source link

tool: simplify extraction of filename associated with each attr #43

Closed rmcgibbo closed 3 years ago

rmcgibbo commented 3 years ago

EDITOR=echo nix edit is rather ridiculous. It turns out it's implemented by calling meta.position (https://github.com/NixOS/nix/blob/master/src/nix/edit.cc#L34 and https://github.com/NixOS/nix/blob/master/src/libexpr/attr-path.cc#L108), so why not do that ourselves and avoid starting up an extra 2 processes.

jtojnar commented 3 years ago

And we could probably deduplicate this with namePositions attribute in the top of the expression.

And even replace getDrvSourceLocation args with originalDrv.meta.position now that we have access to originalDrv in the overlays.

rmcgibbo commented 3 years ago

Yeah, there are a few calls to getDrvSourceLocation, both there and in namePositions at the top of the nix-instantiate expression but I wasn't yet sure if they could all be integrated into one.

jtojnar commented 3 years ago

Yeah, it would be nice if we could just do

diff --git a/tools/nixpkgs-hammer b/tools/nixpkgs-hammer
index 406d72f..4aae624 100755
--- a/tools/nixpkgs-hammer
+++ b/tools/nixpkgs-hammer
@@ -208,12 +208,15 @@ def main(args):
             builtAttrs = [ {" ".join(attrs_nix)} ];
             packageSet = {args.nix_file};
             cleanPkgs = import {args.nix_file} {{ }};
-            namePositions = builtins.filter (p: p != null) {indent(name_positions_nix, 2 + 1).strip()};
+            namePositions = builtins.filter (p: p != null) (builtins.map ({{ position }}: position) (builtins.attrValues report));

             pkgs = import {args.nix_file} {{
                 overlays = {indent(overlays_nix, 2 + 2).strip()};
             }};
-        in {indent(attr_messages_nix, 2 + 0).strip()}
+
+            report = {indent(attr_messages_nix, 2 + 1).strip()};
+        in
+            report
         '''
     )

but Nix is not lazy enough for that. We really need namePositions defined in terms of cleanPkgs.