Skip to content

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

Merged
cole-h merged 1 commit into
mainfrom
no-update-lock-file
Nov 7, 2023
Merged

cole-h merged 1 commit into
mainfrom
no-update-lock-file

Conversation

@cole-h

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

Copy link
Copy Markdown
Member

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 force-pushed the no-update-lock-file branch from 55ab445 to 8b56f4d Compare November 6, 2023 21:51
@cole-h
cole-h requested a review from colemickens November 6, 2023 21:51
@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

cole-h commented Nov 6, 2023 •

Copy link
Copy Markdown
Member Author

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

Comment thread src/cli/mod.rs
.arg("flake")
.arg("metadata")
.arg("--json")
.arg("--no-update-lock-file")

Copy link
Copy Markdown
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).

@colemickens colemickens left a comment

Copy link
Copy Markdown
Member

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
@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