I recall @Srid mentioning this before, but I don’t seem to recollect. For example, if I have a flake in project-a
and this has project-b
in its inputs
, project-b
in turn depends on project-c
in its flake. My question is, how can I find if project-a
depends on project-c
without having to go through each of the flake. I want something like nix why-depends
but for flake inputs.
Unsure, but there is nix flake metadata
which dumps the tree of inputs. It takes --json
to produce a JSON output, so something can be built off it. Also nix-browser can (be made to) do this too, but a CLI would be nice.
fwiw, for quickly traversing inputs in the flake you can simply load the flake in a repl, and a top-level inputs
attribute exists for quickly traversing the inputs of a flake
Hey Tim, thanks for that, I am aware that I can traverse through the entire graph of the inputs, i.e if I know the path to whatever input I am looking for. I was looking for a solution, that given an input, gives me the pinned version for that input in the dependency graph and the path to reach to that node in the graph.
This is what worked for me:
To find the pinned revision:
$ nix flake metadata --json | jq '.. | ."hedis"? | select( . != null )'
Which gives me the following output:
{
"flake": false,
"locked": {
"lastModified": 1689234100,
"narHash": "sha256-J4mqtraMzLJguL0BwMUETeBpNJXRf86E2ZaP9xx+4tY=",
"owner": "juspay",
"repo": "hedis",
"rev": "77bf501da57639a60728b577e1c3780f70ddb418",
"type": "github"
},
"original": {
"owner": "juspay",
"repo": "hedis",
"rev": "77bf501da57639a60728b577e1c3780f70ddb418",
"type": "github"
}
}
"hedis"
Now, what if I want to get the path to reach this node, I can still use jq to do this, thanks to this solution from stackoverflow:
nix flake metadata --json | jq -c 'paths | select(.[-1] == "hedis")'
This gives me the output:
["locks","nodes","euler-hs","inputs","hedis"]
["locks","nodes","hedis"]
Now I know hedis comes from euler-hs’s flake.
Nice one; here's another example (shared-kernel is transitively used by two other flakes, in addition to direct reference by the root flake; though the output doesn't say whether they all are pinned at same rev):
❯ nix flake metadata --json github:nammayatri/nammayatri | jq -c 'paths | select(.[-1] == "shared-kernel")'
["locks","nodes","beckn-gateway","inputs","shared-kernel"]
["locks","nodes","namma-dsl","inputs","shared-kernel"]
["locks","nodes","root","inputs","shared-kernel"]
["locks","nodes","shared-kernel"]
That shouldn’t be hard to solve, I will have a look tomorrow
You could wrap all of this in a pkgs.writeShellApplication
and make it a flake-app runnable as, for instance, nix run github:shivaraj-bh/search-flake-inputs github:nammayatri/nammayatri shared-kernel
Probably an overkill, unless it is going to do more / act general.
I will probably come up with a more prettified output for this along with displaying a correspond short rev for the node in question, then making a flake-app around it would make sense
Stretch goal: can it also search flake output tree?
https://github.com/shivaraj-bh/search-flake-inputs
Screenshot-2024-01-15-at-7.58.02PM.png
announce it!
this is really useful. thanks
I was planning to announce it but was wondering if I could make a general purpose search application in rust. It will be able to search outputs, inputs and can be made extensible to search much more.
tgunnoe said:
this is really useful. thanks
Maybe I should announce it at its current state and then later launch a successor that will deprecate this.
Last updated: Nov 15 2024 at 12:33 UTC