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

Input: Replace 'locked' bool by isLocked() method #10024

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Feb 16, 2024

Motivation

It's better to just check whether the input has all the attributes needed to consider itself locked (e.g. whether a Git input has an rev attribute).

Also, the locked field was actually incorrect for Git inputs: it would be set to true even for dirty worktrees. As a result, we got away with using fetchTree() internally even though fetchTree() requires a locked input in pure mode. In particular, this allowed --override-input to work by accident.

The fix is to pass a set of "overrides" to call-flake.nix for all the unlocked inputs (i.e. the top-level flake and any --override-inputs). This is more efficient anyway since it avoids refetching inputs that lockFlake() already fetched.

Backported from the lazy-trees branch.

Context

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority fetching Networking with the outside (non-Nix) world, input locking labels Feb 16, 2024
It's better to just check whether the input has all the attributes
needed to consider itself locked (e.g. whether a Git input has an
'rev' attribute).

Also, the 'locked' field was actually incorrect for Git inputs: it
would be set to true even for dirty worktrees. As a result, we got
away with using fetchTree() internally even though fetchTree()
requires a locked input in pure mode. In particular, this allowed
'--override-input' to work by accident.

The fix is to pass a set of "overrides" to call-flake.nix for all the
unlocked inputs (i.e. the top-level flake and any --override-inputs).
@Ericson2314
Copy link
Member

I reviewed the libfetchers part of this. Definitely +1 to the idea, but don't we need to consider the nar hash too (at least until git tree hash based store paths are merged)?

@edolstra
Copy link
Member Author

@Ericson2314 Good point. We don't need a NAR hash for Git/Mercurial for an input to be considered locked, but we do for GitHub, since we can't verify the tarball from the rev alone. So I've changed the GitHub fetcher to require a NAR hash.

@Ericson2314
Copy link
Member

OK I see. Ideally there would be something a bit more "constructive" e.g. isLocked would return std::option of some sort of content-address, but that is a preexisting issue that is not this PR's fault or responsibility.

@edolstra
Copy link
Member Author

Yeah, right now the callers only care whether an input is locked, not how it is locked.

@edolstra edolstra merged commit 3f5d7af into NixOS:master Feb 21, 2024
8 checks passed
@edolstra edolstra deleted the remove-locked-flag branch February 21, 2024 15:19
@Ericson2314
Copy link
Member

(N.B. I didn't review the rest, but I guess it is closer to that sort of evidence-passing thing I envisioned.)

Comment on lines +283 to +291
bool isLocked(const Input & input) const override
{
/* Since we can't verify the integrity of the tarball from the
Git revision alone, we also require a NAR hash for
locking. FIXME: in the future, we may want to require a Git
tree hash instead of a NAR hash. */
return input.getRev().has_value() && input.getNarHash().has_value();
}

Copy link
Member

Choose a reason for hiding this comment

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

This is quite a breaking change (and it also breaks the githubFlakes test, although that was hidden behind other breakages)

Copy link
Member

Choose a reason for hiding this comment

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

(not to say that we necessarily shouldn't have it, but it should at the very least get a release note)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetching Networking with the outside (non-Nix) world, input locking flakes new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants