Skip to content

libfetchers: let input schemes resolve path-like flake references - #16507

Open
zimbatm wants to merge 1 commit into
NixOS:masterfrom
zimbatm:local-root-detection
Open

zimbatm wants to merge 1 commit into
NixOS:masterfrom
zimbatm:local-root-detection

Conversation

@zimbatm

@zimbatm zimbatm commented Sep 23, 2026

Copy link
Copy Markdown
Member

Motivation

Add support for jj flake inputs down the line.

Context

When loading a local flake directory, Nix would only detect .git repositories as a hard-coded logic, and fallback on copying whole directories for other inputs.

This change introduces InputScheme::localRepoURL(). Ports the Git and logic to its input. And adds the Mercurial support for it.

After this change, I can write a jj plugin, and other SCMs can do the same thing.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@zimbatm
zimbatm requested a review from edolstra as a code owner September 23, 2026 14:15
@github-actions github-actions Bot added documentation with-tests Issues related to testing. PRs with tests have some priority fetching Networking with the outside (non-Nix) world, input locking labels Sep 23, 2026
}
if (is_directory(localPath)) {
if (exists(localPath / ".git")) {
if (auto repoURL = getLocalRepoURL(localPath)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One thing to be wary of is that previously we followed symlinks here, but no longer do. So a mere presence of .git in the repo is enough. I guess it's fine, .git pointing outside the repo is absolutely cursed and probably isn't allowed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, I'm not sure what use-cases there are for .git symlinks. worktrees use a file.

if (auto * localPathP = std::get_if<std::filesystem::path>(&actualUrl_)) {
auto & localPath = *localPathP;
auto unlocked = !input.getRef() && !input.getRev();
auto isValidLocalRepo = pathExists(localPath / ".hg");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't need to change though?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good catch

Such a reference now resolves to `hg+file:`, so only tracked files are copied.
This needs the `hg` executable, as `hg+file:` inputs always did.

Input schemes, including ones from [`plugin-files`](@docroot@/command-ref/conf-file.md#conf-plugin-files), can claim a directory by implementing `InputScheme::localRepoURL()`.

@xokdvium xokdvium Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claim seems like the wrong word to describe the thing. It's more about hooking into cli path-like flakeref shorthands.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

agreed, switched it to "resolve path-like"

Motivation: add support for `jj` down the line.

When loading a local flake directory, Nix would only detect `.git`
repositories, and fallback on copying whole directories for other
inputs.

This change introduces `InputScheme::localRepoURL()`. Ports the Git and
logics to its input. And adds the Mercurial support for it.

After this change, I can write a jj plugin, and other SCMs can do
the same thing.

Assisted-by: Claude Code (claude-opus-5)
@zimbatm
zimbatm force-pushed the local-root-detection branch from 8e07e95 to 77aac4e Compare September 25, 2026 14:30
@zimbatm zimbatm changed the title libfetchers: let inputs claim local repositories libfetchers: let input schemes resolve path-like flake references Sep 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation fetching Networking with the outside (non-Nix) world, input locking with-tests Issues related to testing. PRs with tests have some priority

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants