Skip to content

Improve path display#469

Merged
cole-h merged 12 commits into
mainfrom
improve-show-path
May 22, 2026
Merged

Improve path display#469
cole-h merged 12 commits into
mainfrom
improve-show-path

Conversation

@edolstra
Copy link
Copy Markdown
Collaborator

@edolstra edolstra commented May 22, 2026

Motivation

This fixes various cases where Nix would show store paths instead of source trees in error messages, e.g.

error: path '/nix/store/v57qvdsi3n14hlzdrxkbv3dxj8781818-source/READMEE.md' does not exist

instead of

error: path '«file:///home/eelco/Dev/nix/nixpkgs.tar.gz»/READMEE.md' does not exist

It also removes now unnecessary substitution code in fetchTarball as a followup to #468.

Context

Summary by CodeRabbit

  • Bug Fixes

    • Better distinction of missing-file errors (throws FileNotFound vs other system errors) and clearer "path … does not exist" messages.
    • Improved path display for substituted/impure sources so missing-file errors reference original source paths.
  • New Features

    • Tarball inputs now set explicit type/name and mark content-addressed inputs as final to enable later substitution.
  • Tests

    • Added/updated unit and functional tests covering impure vs pure fetch/read behavior and new utility helpers.

Review Change Stack

edolstra added 11 commits May 22, 2026 11:51
Changes error messages like

  error: path '/nix/store/v57qvdsi3n14hlzdrxkbv3dxj8781818-source/READMEE.md' does not exist

to

  error: path '«file:///home/eelco/Dev/nix/nixpkgs.tar.gz»/READMEE.md' does not exist

In impure mode, the showPath() from the UnionSourceAccessor's first element was preventing the use of the more accurate showPath() from storeFS.
…cessor

There may be more informative than the generate "path does not
exist". In any case it makes --impure more consistent because the
UnionSourceAccessor now produces the same exceptions from storeFS.
This is necessary if the path has an overriden display (e.g. if it's a
substituted source tree).
This was actually preventing display of correct paths, since the
exception is thrown by PosixSourceAccessor(), so
SubstitutedSourceAccessor::showPath() was never called. (This was
previously masked in some cases by UnionSourceAccessor.)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a311a954-605c-41db-a44e-2574a3291548

📥 Commits

Reviewing files that changed from the base of the PR and between 468a7cd and e99f276.

📒 Files selected for processing (1)
  • tests/functional/flakes/source-paths.sh

📝 Walkthrough

Walkthrough

This PR adds a mark-last range adaptor, standardizes FileNotFound errors across source accessors, extends UnionSourceAccessor to accept a separate display accessor, updates callers to use the new factory signature, removes the SubstitutedSourceAccessor wrapper, and enables tarball fetch substitution with tests.

Changes

Source Accessor Display and Error Handling

Layer / File(s) Summary
Range utility and exception standardization
src/libutil/include/nix/util/util.hh, src/libutil-tests/util.cc, src/libutil/posix-source-accessor.cc, src/libutil/memory-source-accessor.cc, src/libfetchers/git-utils.cc, src/libutil-tests/source-accessor.cc
markLast range adaptor pairs each element with a boolean indicating if it is last. POSIX accessor now distinguishes ENOENT from other open errors to throw FileNotFound. Memory and Git accessors updated to throw FileNotFound consistently with "path does not exist" message. Test expectations adjusted.
Union accessor display support
src/libutil/include/nix/util/source-accessor.hh, src/libutil/union-source-accessor.cc
UnionSourceAccessor constructor accepts displayAccessor parameter; readFile and readLink iterate with markLast and return early on final accessor; showPath conditionally delegates to displayAccessor; factory signature updated to require displayAccessor.
Consumer integration and cleanup
src/libexpr/eval.cc, src/libfetchers/fetchers.cc
EvalState passes displayAccessor to new union accessor factory. SubstitutedSourceAccessor wrapper struct removed; accessor creation uses store.requireStoreObjectAccessor directly.
Tarball fetch substitution and test coverage
src/libexpr/primops/fetchTree.cc, tests/functional/flakes/source-paths.sh
Tarball fetch unpack path sets __final = true and narHash when expectedHash is provided, enabling store substitution. Functional tests expanded to verify impure-mode error messages reference original Git paths and test narHash behavior in pure vs. impure modes.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant UnionSourceAccessor
  participant displayAccessor
  participant accessors as accessors vector
  Caller->>UnionSourceAccessor: readFile(path)
  UnionSourceAccessor->>accessors: iterate with markLast
  loop for each accessor until last
    accessors->>UnionSourceAccessor: maybeLstat result
  end
  Note over UnionSourceAccessor: early return on last accessor
  Caller->>UnionSourceAccessor: showPath(path)
  alt displayAccessor present
    UnionSourceAccessor->>displayAccessor: showPath(path)
  else
    UnionSourceAccessor->>UnionSourceAccessor: fallback SourceAccessor::showPath
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • DeterminateSystems/nix-src#468: Updates tarball fetch unpack behavior and substitution logic in src/libexpr/primops/fetchTree.cc alongside this PR's changes.

Suggested reviewers

  • cole-h

Poem

🐰 I hopped through code and tuned each path,

FileNotFound now speaks with a clearer math;
Union shows the source it means to say,
markLast whispers which step ends the play,
Tarballs mark final, tests confirm the way.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve path display' directly relates to the main objective of fixing error message path displays to show original source trees instead of store paths, which is the core change across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 improve-show-path

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

@github-actions github-actions Bot temporarily deployed to pull request May 22, 2026 11:45 Inactive
@github-actions github-actions Bot temporarily deployed to pull request May 22, 2026 13:16 Inactive
@cole-h cole-h added this pull request to the merge queue May 22, 2026
Merged via the queue into main with commit 8c450d4 May 22, 2026
29 checks passed
@cole-h cole-h deleted the improve-show-path branch May 22, 2026 15:38
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