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

Require flake.lock to be up-to-date if it exists #96

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

cole-h
Copy link
Member

@cole-h cole-h commented Nov 6, 2023

This will prevent uploading of flakes that need to be re-locked.

colemickens
colemickens previously approved these changes Nov 6, 2023
@cole-h cole-h marked this pull request as draft November 6, 2023 21:38
We allow flakes without a flake.lock checked in (similar to how, in
the Rust ecosystem, sometimes library authors don't commit their
Cargo.lock), but we require flakes that do have a flake.lock to be
up-to-date.
@cole-h cole-h marked this pull request as ready for review November 6, 2023 21:51
@cole-h cole-h changed the title Use --no-update-lock-file instead of --no-write-lock-file Require flake.lock to be up-to-date if it exists Nov 6, 2023
@cole-h
Copy link
Member Author

cole-h commented Nov 6, 2023

Tested with:

  • No flake.lock: still works
  • With up-to-date flake.lock: still works
  • With out-of-date flake.lock: no longer works

(Looks similar to below)

Error:
   0: Checking flake evaluates
   1: Failed to execute command `nix flake show --all-systems --json --no-update-lock-file /home/vin/workspace/detsys/flakehub/docs-test-thing/test-repo/` with status 1
      stdout:
      stderr: warning: Git tree '/home/vin/workspace/detsys/flakehub/docs-test-thing/test-repo' is dirty
      error:
             … while updating the lock file of flake 'git+file:///home/vin/workspace/detsys/flakehub/docs-test-thing/test-repo'

             error: flake 'git+file:///home/vin/workspace/detsys/flakehub/docs-test-thing/test-repo' requires lock file changes but they're not allowed due to '--no-update-lock-file'

   1:

Location:
   src/flake_info.rs:96

.arg("flake")
.arg("metadata")
.arg("--json")
.arg("--no-update-lock-file")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the special sauce right here: if nix flake metadata --json would have updated the flake.lock, this causes Nix (and thus the entire upload) to fail (which we want).

Copy link
Member

@colemickens colemickens left a comment

Choose a reason for hiding this comment

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

super nit: constuct vec of args, use (Command).args() to add it to the command, then you can re-use the args for the error message instead of repeating it. (Just in case we change the command again later, so we don't to change error strings too). But this is mostly just golfing.

but LGTM

@cole-h cole-h merged commit 44fa52f into main Nov 7, 2023
5 checks passed
@cole-h cole-h deleted the no-update-lock-file branch November 7, 2023 15:51
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.

2 participants