url-name: prefer fragment over dir= when deriving the install name#15901
Open
danfry1 wants to merge 12 commits into
Open
url-name: prefer fragment over dir= when deriving the install name#15901danfry1 wants to merge 12 commits into
dir= when deriving the install name#15901danfry1 wants to merge 12 commits into
Conversation
`getNameFromURL` checked the `dir=` query argument before the fragment
and returned early, so a URL like `github:org/repo?dir=ai#my-tool` was
named "ai" instead of "my-tool". This caused `nix profile install` to
generate collision-suffixed names ("ai-1", ...) when installing several
attributes from the same `?dir=` flake.
The fragment names a specific attribute the user asked for, while `dir=`
only tells Nix where the flake.nix lives in the repo, so the fragment
should win. Swap the order and keep `dir=` as a fallback when the
fragment is absent, empty, or `default`.
Closes: NixOS#15900
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #15900.
nix profile install github:org/repo?dir=ai#my-toolwas incorrectly namedaiinstead ofmy-tool, becausegetNameFromURLchecked thedir=query argument before the fragment and returned early. Installing multiple attributes from the same?dir=flake therefore produced collision-suffixed names (ai,ai-1, ...).Context
The fragment names a specific attribute the user asked for;
dir=only tells Nix where theflake.nixlives inside the repository. The fragment is the more specific signal and should win.This PR swaps the order of the two checks in
getNameFromURLand keepsdir=as a fallback when the fragment is absent, empty, or evaluates todefault(the case where the existing code already chose to fall through).Tests
The existing test cases in
src/libflake-tests/url-name.cccovered?dir=alone and#fragmentalone but never the combination, so the buggy branch was untested. Added cases for:?dir=ai#my-tool→my-tool(the regression test)?dir=ai#packages.x86_64-linux.my-tool→my-tool?dir=ai#→ai(empty fragment falls back to dir)?dir=ai#packages.x86_64-linux.default→ai(default fragment falls back to dir)All existing assertions continue to pass under the new ordering — none of the existing
?dir=cases set a fragment.Checklist
src/libflake-tests/url-name.cc)doc/manual/rl-next/