Nix repl: best way to inspect an item in a list?

I’m using nix repl more frequently to inspect derivations / parts of my configuration.

I’m frequently running into long-ish lists (like environment.systemPackages, or in this case config.isoImage.contents) in which I’d like to drill down and inspect a specific item (or perhaps continue to tab-tab and drill down in that item’s own contents).

So far, I’ve tried:

  • elemAt, downside is having to guess indices until I get the right one
  • filter, downside is having to make an appropriate custom filter function each time, and still having to builtins.head to get to the item itself.

Is there a better way people are usually doing this? EDIT: Perhaps create a custom enumerate function to make using elemAt a little more convenient?

For example, trying to look at some of the grub / EFI configuration:

nix-repl> (builtins.head (builtins.filter (item: builtins.match ".*EFI.*" item.target != null) outputs.packages.x86_64-linux.rescue.config.isoImage.contents))
{ source = "/nix/store/v1lp4bcb3y7fbz9jlxv9j9phnclfszan-efi-directory/EFI"; target = "/EFI"; }
2 Likes

lib.findSingle seems handy for this.

nix-repl> lib.findSingle (item: builtins.match "/EFI" item.target != null) (abort "no matches") (abort "multiple matches") outputs.packages.x86_64-linux.rescue.config.isoImage.contents
{ source = "/nix/store/ppdfmxlnan5bk4g9r0q4w8kfaz5qrjqb-efi-directory/EFI"; target = "/EFI"; }