Skip to content
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

Try parse installables as store paths first #4569

Closed
wants to merge 2 commits into from

Conversation

stephank
Copy link
Contributor

Potential fix for #4568.

This simply flips the order of tests for flake / store path in SourceExprCommand::parseInstallables. There was some extra logic to prioritise the parseFlake exception, but I don't believe we need it anymore.

I was a little surprised this passed all tests. I'm not sure how much confidence that gives us, but figured I'd open a PR to discuss. Please consider I'm not very familiar with this code or the impact of this change.

@stephank
Copy link
Contributor Author

For what it's worth, we do flake builds exclusively, and have a moderately complex Node.js / PHP application that we build with Nix. I deployed stephank:master to our build server, which is a little behind NixOS:master but includes this patch, and was able to successfully build and deploy just now.

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. That makes a lot of sense IMHO. Just left a couple suggestions to make things cleaner

if (s.find('/') != std::string::npos) {
try {
result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
continue;
} catch (BadStorePath &) {
} catch (...) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn’t drop every exception like that, but rather keep the old logic of storing the exception (unless it’s a BadStorePath) and eventually throwing it if both parsing methods failed

@@ -722,3 +723,8 @@ git -C $flakeB commit -a -m 'Foo'

# Test list-inputs with circular dependencies
nix flake metadata $flakeA

# Test flake in store does not evaluate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment probably isn’t really clear out-of-context. Something like below might be clearer

Suggested change
# Test flake in store does not evaluate
# A store path containing a `flake.nix` should be treated as a store path, and not a flake

Also it might be worth adding a test to ensure that for example file:/nix/store/foobar will be treated as a flake url and not a store path

@edolstra
Copy link
Member

edolstra commented Sep 2, 2021

Thanks, I've added the test from this PR, flipped the order of parsing as suggested by @regnat, and added a test that you can use path:/path to force evaluating a store path as a flake.

@edolstra edolstra closed this Sep 2, 2021
@stephank stephank deleted the store-flake branch September 2, 2021 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants