Include "original" and "locked" in nix flake prefetch --json #8994
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
For 3rd party tools, it is important to be able to follow the same basic mechanisms behind
nix flake
. In particular, two things I have struggled with in the past are:Efforts like rime make me think I am not the only one trying to do this.
Context
I tried to twist the cli into giving me the right information but the only way seems to be creating an ad-hoc temporary flake with a single input and read the lock file, which is not something I am comfortable building on top of.
With
nix flake prefect --json
gets us very close:But its structured output does not include the locked url just printed above!
This (minimal) change adds two fields to the output of
nix flake prefetch --json
: the original url as parsed bynix flake
and its locked version.Note: doing this introduces a duplication of the
hash
field, now represented both at the top-level and insidelocked
. I agree this is unoptimal but I didn't want to make start with a breaking change (let me say this glossing over the experimental/unstable discussion). I can remove the top-level hash field if it's deemed acceptable.Another solution could be obtained by changing
builtins.fetchTree
to interpret strings as flake uris. Currently it is not possible to callbuiltins.fetchTree "github:input-output-hk/haskell.nix"
but if the uri gets parsed asnix flake
would do, then it would turn intowhich exposes all the information I am looking for. This could even be preferable as the information exposed be reused in nix logic while still being accessible from the command line.
I think this make it a great feature for third party tooling since it (almost?) allows one to reimplement flake-locking externally.
Priorities
Add 👍 to pull requests you find important.