-
Notifications
You must be signed in to change notification settings - Fork 249
devpkg: better flake references and installable parsing #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6ddb25a
to
c008d5a
Compare
In anticipation of adding support for non-default package outputs, I wanted to clean up some of the flakeref parsing in `devpkg`. This will make it easier to handle Nix's `flakeref#attrpath^outputs` installable syntax. The `ParseFlakeRef` function is able to parse the more common flakerefs that devbox currently supports ("path", "flake", "indirect", etc.). It doesn't support mercurial, gitlab, and sourcehuthut for now. The tests were validated using the nix expression `builtins.parseFlakeRef "ref"` and the `nix flake metadata <ref>` CLI. The goal isn't to perfectly replicate Nix's parsing of flake references (which itself is sometimes inconsistent), but to make it good enough to handle flakerefs in devbox.json.
Add a `ParseFlakeInstallable` to parse Nix flake installables. An installable is a superset of a flake reference. It allows an attribute path and/or outputs to be specified using the `flake#attrpath^outputs` syntax.
Signed-off-by: Greg Curtis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! What is the plan to integrate it with the rest of the code?
I wanted to clean up some of the flakeref parsing in devpkg. This will make it easier to handle Nix's flakeref#attrpath^outputs installable syntax. This PR is broken up into two commits: one that handles flakeref parsing and one that handles installable parsing.
Is the expectation that users would directly run devbox add flakeref#attrpath^outputs
? If so, I worry that is a complicated string for our users. We can find a simpler way.
On the other hand, if we're saying the user's commands will get translated by Devbox CLI code into being of the form flakeref#attrpath^outputs
and then this makes sense to me.
This product discussion is probably better in a different forum than this PR. Happy to chat elsewhere more :)
internal/devpkg/flakeref.go
Outdated
"go.jetpack.io/devbox/internal/redact" | ||
) | ||
|
||
// FlakeRef is a parsed Nix flake reference. A flake reference is as subset of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...is a subset of...
internal/devpkg/flakeref.go
Outdated
Rev string `json:"rev,omitempty"` | ||
Ref string `json:"ref,omitempty"` | ||
|
||
// Dir is non-empty when the directory containinig the flake.nix file is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: containing
func parseFlakeURLRef(ref string) (parsed FlakeRef, fragment string, err error) { | ||
// A good way to test how Nix parses a flake reference is to run: | ||
// | ||
// nix eval --json --expr 'builtins.parseFlakeRef "ref"' | jq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good pro-tip 👍🏾
It's the second one. For handling the flake-like syntax supported in devbox.json (which users have to add manually). |
c008d5a
to
b22db30
Compare
In anticipation of adding support for non-default package outputs, I wanted to clean up some of the flakeref parsing in
devpkg
. This will make it easier to handle Nix'sflakeref#attrpath^outputs
installable syntax. This PR is broken up into two commits: one that handles flakeref parsing and one that handles installable parsing.The
ParseFlakeRef
function is able to parse the more common flakerefs that devbox currently supports ("path", "flake", "indirect", etc.). It doesn't support mercurial, gitlab, and sourcehuthut for now. TheParseFlakeInstallable
function parses Nix flake installables, which are a superset of the flake reference syntax. It allows an attribute path and/or outputs to be specified using theflake#attrpath^outputs
syntax. The tests were validated using the nix expressionbuiltins.parseFlakeRef "ref"
and thenix flake metadata <ref>
CLI.The goal isn't to perfectly replicate Nix's parsing of flake references (which itself is sometimes inconsistent), but to make it good enough to handle flakerefs in devbox.json.