nix-tree icon indicating copy to clipboard operation
nix-tree copied to clipboard

Feature request: Show store path for each drv file

Open DavHau opened this issue 6 months ago • 3 comments

Thank you so much for this tool. This is by far one of the very best tools in the ecosystem and a daily driver for me since years. Often when I use nix-tree to look at .drv files, I find myself jumping back an forth between nix-tree and nix show-derivation to find the store path of the derivation and then looking again at the store path via nix-tree.

It would be great if nix-tree would show the store path for each drv directly. Optimally color coded red/green signaling if the store path exists on my local system or not. If I could then directly navigate to the nix-tree view of that store path, that would be insane!

Then the same would make sense vice versa. Jumping from any store path viewed in nix-tree, to the nix-tree view of its derivation.

DavHau avatar May 14 '25 02:05 DavHau

Thank you for the kind words :).

I agree that this would be a great feature.

Random thoughts: I have a vague recollection of finding some issues with going across .drv files and actual store paths but if nix show-derivation shows it there has to be a way. Right now all nix-tree has access to is output from nix path-info --recursive - so if the information is found there it'll be an easy change. If not - we'll need to somehow obtain the information that doesn't require executing a separate command for every single store path.

With https://github.com/utdemir/nix-tree/issues/119, I think there's two useful features on nix-tree backlog. I'll try to spend some time to implement them and cut a new release, hopefully within a week or so :).

utdemir avatar May 14 '25 23:05 utdemir

Here's what I found:

  • nix path-info on a store path does show the deriver:
$ nix path-info --json /nix/store/yj2lqydpqynnhazkb8rp2cwfjrh4wl6y-nix-tree-0.6.2 | jq .
{
  "/nix/store/yj2lqydpqynnhazkb8rp2cwfjrh4wl6y-nix-tree-0.6.2": {
    "ca": null,
    "deriver": "/nix/store/ash1invxj6y8parsdrbvjkq29jwix5c1-nix-tree-0.6.2.drv",
    "narHash": "sha256-uIaM4o38D74v+5+2nbsRGtt7BytWoWd1XKc1NprL7+M=",
    "narSize": 53159736,
    "references": [
      "/nix/store/0ccvgwg4cpgf9jwwc98rz7wxafsmsf44-libiconv-109",
      "/nix/store/mv1p9jvca4b2vr9aj1m96kzf117zs8r6-libffi-39",
      ...
    ],
    "registrationTime": 1747388417,
    "signatures": [...],
    "ultimate": false
  }
}
  • nix path-info on derivation does not show the store path:
$ nix path-info --json --derivation /nix/store/yj2lqydpqynnhazkb8rp2cwfjrh4wl6y-nix-tree-0.6.2 | jq .
{
  "/nix/store/ash1invxj6y8parsdrbvjkq29jwix5c1-nix-tree-0.6.2.drv": {
    "ca": "text:sha256:06j0pq2nkr4d0djxwa6sfbw31rm1ly8mwc7vqq11ab0zg1pbrwll",
    "deriver": null,
    "narHash": "sha256-FgFETX6TNB7GmDnov6i33s8X95/dxbHqIjpN26WMDv8=",
    "narSize": 11528,
    "references": [
      "/nix/store/218l65n3a138jmkfnpvd399vrxlvgi40-remove-references-to.drv",
      "/nix/store/2vy23mcr874qbprdjc6w7xrwx61wwz0w-clock-0.8.4.drv",
      ...
    ],
    "registrationTime": 1747388255,
    "signatures": [],
    "ultimate": false
  }
}
  • nix derivation show on derivation does show the store path:
$ nix derivation show
{
  "/nix/store/ash1invxj6y8parsdrbvjkq29jwix5c1-nix-tree-0.6.2.drv": {
    "args": [
      "-e",
      "/nix/store/vj1c3wf9c11a0qs6p3ymfvrnsdgsdcbq-source-stdenv.sh",
      "/nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh"
    ],
    "builder": "/nix/store/xhcgnphdwfg81j79nhspm0876cxglyj3-bash-5.2p37/bin/bash",
    "env": { ... },
    "inputDrvs": {
      "/nix/store/218l65n3a138jmkfnpvd399vrxlvgi40-remove-references-to.drv": {
        "dynamicOutputs": {},
        "outputs": [
          "out"
        ]
      },
      ...
    },
    "inputSrcs": [
      "/nix/store/4mdp8nhyfddh7bllbi7xszz7k9955n79-Setup.hs",
      "/nix/store/907d7wf2d113vlv8dlhi1i3d683gc1rs-unpretty-cabal-conf.awk",
     ..
    ],
    "name": "nix-tree-0.6.2",
    "outputs": {
      "out": {
        "path": "/nix/store/yj2lqydpqynnhazkb8rp2cwfjrh4wl6y-nix-tree-0.6.2"
      }
    },
    "system": "aarch64-darwin"
  }
}

--

So, with the current path-info method, I can go from the store path to derivation, but not the other way around. I'll quickly make the change to show the deriver field on the bottom pane for output paths.

For showing the output path when browsing the derivations, the options are:

  • Using nix derivation show instead of nix path-info --derivation when --derivation flag is passed. I am not 100% sure about the repercussions on this.
  • Running an additional command/commands after nix path-info --derivation to get the output of the derivations we have. This is safer, but feels redundant.

Once we have one of those - we can also add a shortcut to switch to/from and derivation and the store path. However what to use as the root path when switching to/from a derivation needs some thinking as well.

I'll sleep on it :). But let me know what you think!

utdemir avatar May 16 '25 09:05 utdemir

I think switching between DRV <> store-path and switching the root to the currently selected node both make sense as separate features independent of each other.

Often, for example when looking at a store path I want to do a search only on all its children. Therefore switching the root might be one way to achieve that.

DavHau avatar May 17 '25 04:05 DavHau