Skip to content

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Oct 30, 2025

Motivation

In particular, this gets rid of the narHash query parameter and shortens the Git revision in GitHub flakerefs. So instead of

   … from call site
     at «github:NixOS/nixpkgs/3bea86e918d8b54aa49780505d2d4cd9261413be?narHash=sha256-Ica%2B%2BSXFuLyxX9Q7YxhfZulUif6/gwM8AEQYlUxqSgE%3D»/lib/customisation.nix:69:16:
       68|     let
       69|       result = f origArgs;
         |                ^
       70|

we get

   … from call site
     at «github:NixOS/nixpkgs/3bea86e»/lib/customisation.nix:69:16:
       68|     let
       69|       result = f origArgs;
         |                ^
       70|

Context

Summary by CodeRabbit

  • New Features

    • Inputs now support abbreviated representations in diagnostics and error messages, displaying shortened revision hashes and omitting unnecessary parameters for cleaner, more concise output.
  • Tests

    • Updated test expectations to reflect the new abbreviated URL display format.

In particular, this gets rid of the `narHash` query parameter and
shortens the Git revision in GitHub flakerefs. So instead of

       … from call site
         at «github:NixOS/nixpkgs/3bea86e918d8b54aa49780505d2d4cd9261413be?narHash=sha256-Ica%2B%2BSXFuLyxX9Q7YxhfZulUif6/gwM8AEQYlUxqSgE%3D»/lib/customisation.nix:69:16:
           68|     let
           69|       result = f origArgs;
             |                ^
           70|

we get

       … from call site
         at «github:NixOS/nixpkgs/3bea86e»/lib/customisation.nix:69:16:
           68|     let
           69|       result = f origArgs;
             |                ^
           70|
@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Walkthrough

This PR extends the fetchers system with an abbreviate parameter to URL conversion methods. When enabled, certain fields—such as narHash, reference branches, and revision hashes—are conditionally omitted from URLs. The parameter propagates through the public API and is implemented across all input scheme classes to control which fields appear in abbreviated representations.

Changes

Cohort / File(s) Summary
API Definition
src/libfetchers/include/nix/fetchers/fetchers.hh
Added optional bool abbreviate = false parameter to Input::toURL(), Input::to_string(), and InputScheme::toURL(); defaults preserve existing behavior.
Base Fetchers Implementation
src/libfetchers/fetchers.cc
Implemented abbreviate logic in Input::toURL() to remove narHash from query when abbreviated; updated to_string() to propagate flag; path display now uses to_string(true) for abbreviated representations.
Git Implementation
src/libfetchers/git.cc
Updated GitInputScheme::toURL() to conditionally include ref only when it is not "master" or "main" during abbreviation; updated path display calls to use to_string(true).
GitHub/Archive Implementation
src/libfetchers/github.cc
Revised GitArchiveInputScheme::toURL() to select gitShortRev() when abbreviated or gitRev() otherwise; adjusted GetDownloadUrl implementations and accessor path formatting across GitHub, GitLab, and SourceHut services.
Other Scheme Implementations
src/libfetchers/indirect.cc, src/libfetchers/mercurial.cc, src/libfetchers/path.cc, src/libfetchers/tarball.cc
Added abbreviate parameter to toURL() overrides; updated relevant path display calls to use to_string(true); implementations mostly unchanged.
Test Expectations
tests/functional/flakes/source-paths.sh
Updated grep patterns to reflect abbreviated URLs without ref parameter in git+file URLs.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Input
    participant InputScheme
    
    Caller->>Input: to_string(abbreviate=true)
    Input->>Input: toURL(abbreviate=true)
    Input->>InputScheme: toURL(*this, abbreviate=true)
    
    alt abbreviate = true
        InputScheme->>InputScheme: Omit narHash, ref (if default),<br/>use gitShortRev()
    else abbreviate = false
        InputScheme->>InputScheme: Include all fields,<br/>use gitRev()
    end
    
    InputScheme-->>Input: ParsedURL (abbreviated or full)
    Input-->>Input: Convert to string
    Input-->>Caller: Abbreviated/full URL string
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • github.cc requires careful review of revision handling logic across multiple services (GitHub, GitLab, SourceHut); verify gitShortRev() vs gitRev() selection is correct in each context
  • Consistency check: Ensure all InputScheme subclasses implement abbreviate behavior consistently, particularly what fields are omitted in each scheme
  • Test alignment: Verify updated test expectations correctly match the new abbreviated URL format across all git+file scenarios
  • Path display propagation: Confirm all accessor/display path construction properly uses to_string(true) where abbreviated output is intended

Possibly related PRs

  • #202: Modifies fetchers.cc accessor and substitution path-display logic; directly related through Input URL conversion and display formatting.

Suggested reviewers

  • cole-h

Poem

🐰 With abbreviate flags we dance and play,
Shortening URLs in every way,
No narHash cluttering the git-file view,
Master and main stay nicely through,
Cleaner paths, a fetcher's delight—
The input schemes now shine so bright! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Abbreviate flakerefs in error messages" directly and accurately summarizes the main objective of the changeset. The PR introduces a new abbreviate parameter across the fetcher API that enables shortened representations of flakerefs (removing narHash and truncating Git revisions), with the primary use case being their display in error messages. The title is concise, clear, and uses specific terminology that conveys the essential change without vague language or noise. A developer reviewing the git history would immediately understand that this PR is about making flakerefs more readable in error output.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eelcodolstra/fh-699-abbreviate-flakerefs-in-nix-error-messages

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

@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request October 30, 2025 14:56 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 236ebef and 8f34600.

📒 Files selected for processing (9)
  • src/libfetchers/fetchers.cc (4 hunks)
  • src/libfetchers/git.cc (4 hunks)
  • src/libfetchers/github.cc (6 hunks)
  • src/libfetchers/include/nix/fetchers/fetchers.hh (2 hunks)
  • src/libfetchers/indirect.cc (1 hunks)
  • src/libfetchers/mercurial.cc (3 hunks)
  • src/libfetchers/path.cc (1 hunks)
  • src/libfetchers/tarball.cc (3 hunks)
  • tests/functional/flakes/source-paths.sh (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (8)
src/libfetchers/path.cc (2)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
src/libfetchers/github.cc (2)
src/libfetchers/git.cc (16)
  • input (244-272)
  • input (244-244)
  • input (274-284)
  • input (274-274)
  • input (307-310)
  • input (307-307)
  • input (312-377)
  • input (312-316)
  • input (420-423)
  • input (420-420)
  • input (425-428)
  • input (425-425)
  • input (430-433)
  • input (430-430)
  • input (435-438)
  • input (435-435)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
src/libfetchers/indirect.cc (2)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
src/libfetchers/tarball.cc (2)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
src/libfetchers/git.cc (2)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/include/nix/fetchers/fetchers.hh (3)
  • abbreviate (71-71)
  • abbreviate (75-75)
  • ref (151-151)
src/libfetchers/include/nix/fetchers/fetchers.hh (1)
src/libfetchers/git.cc (16)
  • input (244-272)
  • input (244-244)
  • input (274-284)
  • input (274-274)
  • input (307-310)
  • input (307-307)
  • input (312-377)
  • input (312-316)
  • input (420-423)
  • input (420-420)
  • input (425-428)
  • input (425-425)
  • input (430-433)
  • input (430-430)
  • input (435-438)
  • input (435-435)
src/libfetchers/fetchers.cc (2)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/mercurial.cc (2)
src/libfetchers/github.cc (16)
  • input (137-159)
  • input (137-137)
  • input (163-163)
  • input (238-238)
  • input (340-348)
  • input (340-340)
  • input (377-380)
  • input (377-377)
  • input (382-385)
  • input (382-382)
  • input (387-390)
  • input (387-387)
  • input (412-427)
  • input (412-412)
  • input (490-507)
  • input (490-490)
src/libfetchers/include/nix/fetchers/fetchers.hh (2)
  • abbreviate (71-71)
  • abbreviate (75-75)
🔇 Additional comments (9)
tests/functional/flakes/source-paths.sh (1)

33-37: Abbreviated rev expectation matches new URL rendering. The relaxed rev=.* pattern keeps the test resilient while aligning with the shortened error output.

src/libfetchers/include/nix/fetchers/fetchers.hh (1)

71-223: Abbreviate flag now part of the public API cleanly. Confirmed the new optional parameter is threaded through Input and InputScheme without disturbing legacy call sites.

src/libfetchers/path.cc (1)

68-79: Signature alignment looks good. The override now matches the updated interface while keeping behaviour intact.

src/libfetchers/indirect.cc (1)

84-97: Indirect scheme override updated correctly. New signature mirrors the base class, preserving existing formatting of indirect flakerefs.

src/libfetchers/git.cc (3)

244-254: Default-branch ref elision scoped to abbreviated displays. Nice touch—this keeps user-visible strings concise while leaving functional URLs unchanged.


726-769: Path-display switch to to_string(true) is spot on. The accessor labels (including submodules) now inherit the abbreviated formatting everyone expects from the new UI.


816-816: Workdir submodule displays updated consistently. Ensures mounted submodules report the same abbreviated identifier as the main accessor.

src/libfetchers/tarball.cc (2)

312-320: Curl scheme now exposes the new signature. Implementation stays the same while matching the updated virtual interface.


359-386: Tarball/file accessors now use the abbreviated identifier. Appreciated—download logs and mounted displays align with the shortened flakeref format.

path.push_back(*ref);
if (rev)
path.push_back(rev->to_string(HashFormat::Base16, false));
path.push_back(abbreviate ? rev->gitShortRev() : rev->gitRev());
Copy link
Member

Choose a reason for hiding this comment

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

minor observation: gitShortRev() hardcodes a length of 7.

I imagine this is because libgit doesn't give us a way to ask for "the shortest unique rev", but in case it's not, it would be great to fix that at some point...

@edolstra edolstra added this pull request to the merge queue Nov 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 3, 2025
@cole-h cole-h added this pull request to the merge queue Nov 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 3, 2025
@cole-h cole-h added this pull request to the merge queue Nov 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 3, 2025
@edolstra edolstra added this pull request to the merge queue Nov 4, 2025
Merged via the queue into main with commit 7f46b90 Nov 4, 2025
35 checks passed
@edolstra edolstra deleted the eelcodolstra/fh-699-abbreviate-flakerefs-in-nix-error-messages branch November 4, 2025 14:58
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.

3 participants