Skip to content

Backward compatibility hack for getFlake applied to unsafeDiscardStringContext - #422

Merged
edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-371
Apr 10, 2026
Merged

edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-371

Conversation

@edolstra

@edolstra edolstra commented Apr 10, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Similar to #402 but with a different kind of string context.

Context

Summary by CodeRabbit

  • Bug Fixes

    • Improved backward-compatibility handling for builtins.getFlake with path flake references, using a more direct store filesystem lookup approach.
  • Tests

    • Added functional test verifying getFlake backward compatibility when applied to store-path string contexts.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR refactors builtins.getFlake's backward-compatibility handling for path flake references, replacing NixStringContext element scanning with direct store filesystem mount lookup. A functional test is added to verify the revised logic for discarded string contexts.

Changes

Cohort / File(s) Summary
Flake Path Resolution Refactoring
src/libflake/flake-primops.cc
Changed backward-compatibility logic from iterating NixStringContext elements to identify store paths, to directly querying the store filesystem via state.store->printStorePath wrapped in CanonPath. The refactored approach constructs the final flake path (including subdir) before invoking callFlake.
Backward-Compatibility Test
tests/functional/flakes/get-flake.sh
Added functional test verifying getFlake works correctly with path:... ?narHash=... flake references that have had their string context discarded via builtins.unsafeDiscardStringContext.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

flake-regression-test

Suggested reviewers

  • cole-h

Poem

🐰 With store paths now mounted and queries quite bright,
The flakes are found swiftly—no context in sight!
We test the old paths with new clever ways,
The backward-compat dance deserves of our praise! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing a backward compatibility hack for getFlake when applied to unsafeDiscardStringContext, which aligns with the code modifications in both the implementation and test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch eelcodolstra/nix-371

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/functional/flakes/get-flake.sh (1)

29-46: Consider adding a nested-path regression case.

This only exercises the empty subPath / empty dir case. Since the new branch now composes both the store subpath and flakeRef.subdir, a /subflake or ?dir=subflake variant would give much better coverage for path-joining regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/functional/flakes/get-flake.sh` around lines 29 - 46, Add a nested-path
regression case that exercises composing a store subpath with flakeRef.subdir:
create a subdirectory (e.g., "$flake1Dir/subflake") containing a flake.nix that
mirrors the original but uses builtins.unsafeDiscardStringContext with a path
that includes the subpath (e.g.,
"path:/subflake:${self.sourceInfo}?narHash=${self.narHash}") or use the query
form "?dir=subflake", then evaluate the nested flake (e.g., nix eval --raw
"$flake1Dir/subflake#flakeOutputs.foo" or nix eval --raw
"$flake1Dir?dir=subflake#flakeOutputs.foo") and assert it equals "bar" to cover
the /subflake / ?dir=subflake variants alongside the existing empty-subPath
case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/functional/flakes/get-flake.sh`:
- Around line 29-46: Add a nested-path regression case that exercises composing
a store subpath with flakeRef.subdir: create a subdirectory (e.g.,
"$flake1Dir/subflake") containing a flake.nix that mirrors the original but uses
builtins.unsafeDiscardStringContext with a path that includes the subpath (e.g.,
"path:/subflake:${self.sourceInfo}?narHash=${self.narHash}") or use the query
form "?dir=subflake", then evaluate the nested flake (e.g., nix eval --raw
"$flake1Dir/subflake#flakeOutputs.foo" or nix eval --raw
"$flake1Dir?dir=subflake#flakeOutputs.foo") and assert it equals "bar" to cover
the /subflake / ?dir=subflake variants alongside the existing empty-subPath
case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04063b19-a31e-4b47-8911-c78283c724df

📥 Commits

Reviewing files that changed from the base of the PR and between 0b5c51a and 274cc81.

📒 Files selected for processing (2)
  • src/libflake/flake-primops.cc
  • tests/functional/flakes/get-flake.sh

@edolstra
edolstra enabled auto-merge April 10, 2026 15:17
@github-actions

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request April 10, 2026 15:47 Inactive
@edolstra
edolstra added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 65c5723 Apr 10, 2026
31 checks passed
@edolstra
edolstra deleted the eelcodolstra/nix-371 branch April 10, 2026 16:41
xokdvium added a commit to NixOS/nix that referenced this pull request Apr 19, 2026
This builds on top of #14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach that
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
xokdvium added a commit to NixOS/nix that referenced this pull request Apr 19, 2026
This builds on top of #14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach than
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
xokdvium added a commit to NixOS/nix that referenced this pull request Apr 25, 2026
This builds on top of #14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach than
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
xokdvium added a commit to NixOS/nix that referenced this pull request Apr 25, 2026
This builds on top of #14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach than
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
xokdvium added a commit to NixOS/nix that referenced this pull request Apr 25, 2026
This builds on top of #14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach than
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Mic92 pushed a commit to Mic92/nix-1 that referenced this pull request Apr 26, 2026
This builds on top of NixOS#14050 to
actually make flakes get lazily copied to the store. This repurposes
a slightly less lazy (but also more deterministic) approach than
determinate nix has taken. We do still pay to cost of hashing an input
once to compute the store path and narHash daemon-client-side. This
could be improved in follow-ups in case we don't actually need to check
the narHash (like during local development).

We need certain backwards compatibility hacks for getFlake with a discarded string
context, those are similar to what detnix does.

See: DeterminateSystems#422
See: DeterminateSystems#402

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>

This branch was previously deployed

1 inactive deployment
pull request — 274cc812 Deployed Apr 10, 2026 by github-actions[bot]
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