Skip to content

fix(write-flake): warn when flake.lock keeps a stale flake attribute (#114) - #142

Merged
vic merged 1 commit into
mainfrom
fix/stale-lock-flake-attr
Oct 12, 2026
Merged

vic merged 1 commit into
mainfrom
fix/stale-lock-flake-attr

Conversation

@sini

@sini sini commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses #114.

As @mightyiam suspected, flake-file isn't what keeps the old value. Nix and Lix both keep an existing lock node when only an input's flake attribute changes, even when flake = true is written out explicitly. Reproduced with a local git+file: input:

step flake.nix input nodes.dep.flake after nix flake lock
A flake = false; false
B attribute omitted false (stale)
C flake = true; false (stale)
D nix flake update dep absent (correct)

Same result on Nix 2.34.8 and Lix 2.95.3 (A and C). So writing flake = true into the generated flake.nix would not fix it.

What flake-file can do is notice. After write-flake writes flake.nix, it compares each declared top-level input's flake value with the matching node in an existing flake.lock. If they differ, it prints the stale input names and the command that refreshes them:

flake-file: flake.lock records a different `flake` attribute for: dep
flake-file: nix flake lock keeps the old value; refresh with: nix flake update dep

It only warns; it never touches the lock. Inputs that follows another input are skipped. A missing, empty or malformed flake.lock is ignored, so the existing write-lock path (which seeds flake.lock with { }) is unaffected.

The underlying Nix behaviour is probably worth an upstream report.

Validation

  • New test-flake-stale-lock-flake-attr: a lock recording "flake": false for a declared flake input produces the warning naming the input; a matching lock produces none. It fails on main.
  • test-flake, test-flake-public and test-write-lock-flake pass.
  • The rest of test-all was not run locally.

#114)

Nix and Lix keep an existing lock node when only an input's `flake`
attribute changes, so flipping `flake` never reaches flake.lock.
write-flake now compares declared top-level inputs with an existing
lock and prints the stale names with the `nix flake update` command.

Adds test-flake-stale-lock-flake-attr.

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

lgtm, detecting and having a warning is good for UX in the time being. Maybe someone can report these stale values to be fixed at cppnix and lix.

@vic
vic merged commit 8e45363 into main Oct 12, 2026
12 checks passed
@vic
vic deleted the fix/stale-lock-flake-attr branch October 12, 2026 19:16
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