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

Do not attempt to write a lock file in builtins.getFlake #6544

Merged
merged 1 commit into from
May 18, 2022

Conversation

ncfavier
Copy link
Member

Fixes #6541

@thufschmitt
Copy link
Member

I don’t think we can just do that, because that would break purity (since getFlake can be used in pure eval mode, and locking a flake is inherently impure). But it’s probably fine to set writeLockFile to !evalSettings.pureEval, so that it’s only available in impure mode.

For the pure use-case, maybe the interface of getFlake could be extended (to allow passing an external lockfile for example). Alternatively/in the meantime, fetchTree+callLocklessFlake might do the job too

@ncfavier
Copy link
Member Author

This should be covered by the lines above:

if (evalSettings.pureEval && !flakeRef.input.isLocked())
throw Error("cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", flakeRefS, state.positions[pos]);

@edolstra
Copy link
Member

@ncfavier That only checks whether the flake reference is locked (e.g. github:nix-community/home-manager/32a7da69dc53c9eb5ad0675eb7fdc58f7fe35272 vs github:nix-community/home-manager). A locked flake reference can refer to a flake that doesn't have a flake.lock, which would be non-reproducible (e.g. its flake.nix can reference an unlocked nixpkgs).

@thufschmitt
Copy link
Member

Ah I should have looked better. The line you point to isn’t enough (it only checks whether the ref passed to getFlake is a locked reference, not that it contains a lockfile), but as @edolstra mentionned in #6541 (comment), passing .allowMutable = !evalSettings.pureEval prevents it from updating the lockfile in pure mode. So it’s all right :)

@thufschmitt
Copy link
Member

So it’s all right :)

Well, it’s all right, bit given how non-trivial it is, I think it’s definitely worth a test to ensure that it doesn’t get accidentally broken ;)

The whole thing actually deserves some tests imho

@ncfavier
Copy link
Member Author

There seems to already be one:

nix/tests/flakes.sh

Lines 158 to 161 in 51d13c4

# Building a flake with an unlocked dependency should fail in pure mode.
(! nix build -o $TEST_ROOT/result flake2#bar --no-registries)
(! nix build -o $TEST_ROOT/result flake2#bar --no-use-registries)
(! nix eval --expr "builtins.getFlake \"$flake2Dir\"")

Can you think of other scenarios to test?

@ncfavier ncfavier force-pushed the getFlake-no-write-lock-file branch from 681fc3c to 169384a Compare May 18, 2022 13:45
@ncfavier
Copy link
Member Author

Added a test for the case that this PR fixes

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.

Added a test for the case that this PR fixes

Thanks :)

Can you think of other scenarios to test?

Nope, should be good since the impure case is already tested :)

Thanks for that then!

@thufschmitt thufschmitt merged commit 78dc64e into NixOS:master May 18, 2022
@ncfavier ncfavier deleted the getFlake-no-write-lock-file branch May 18, 2022 14:41
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.

builtins.getFlake fails with "cannot write modified lock file"
3 participants