Repository navigation
Conversation
c014f07 to
330cdd8
Compare
|
Hi, thanks for contributing! Taking a look at your PR, there is a divergence between the behavior inside The proposed patch calls Instead of duplicating logic in the std::filesystem::path path = match[1].str();
auto query = decodeQuery(match[3].str(), /*lenient=*/true);
auto fragment = percentDecode(match[5].str());
// Path normalization
if (baseDir) {
path = absPath(path, get(baseDir), true);
} else {
if (!preserveRelativePaths && !path.is_absolute())
throw BadURL("flake reference '%s' is not an absolute path", url);
}
if (isFlake && path.is_absolute() && pathExists(path)) {
// Existing logic: directory checks, searching up for flake.nix, walking up to find repo root and setting `subdir`...
}
// Fallback to path: scheme
return fromParsedURL({ .scheme = "path", ... }, isFlake);This would:
What do you think? |
|
Thank you for the guidance! I didn't understand that subtlety of the subdirectory mechanism and favored minimal change. I really like your approach, I'll be amending my pull request |
|
This happens for examples if This means unit tests can still be made to fail based on the system. The unit tests expect Disabling this in code would require the tests to explicitly opt out of repo detection, which is (to me) out of scope |
path urls had detection for repos and the flake root, but only when a baseDir was set. These detections are now attempted regardless of baseDir
Giving a filepath to CLI as a flake url would correctly infer git+path only within an expression (with a baseDir set).
This adds the same functionality to bare absolute paths
Motivation
doing
nix registry add myFlake /path/to/flakehas unexpected behavior when the flake is part of a git repository.It converts the file path to a
path://url, regardless of if the flake is part of a repository. It does not infergit+file://as would be expected.This is especially problematic because this distinction changes the semantics of
src = ./.This aligns such CLI uses with expression evaluation, where the url scheme is inferred based on the contents/presence of a repository
Implementation
When a 'baseDir' is set, there is already an implementation in place.
A section of that code is copied into the alternate case where no such baseDir is set
This makes behavior more consistent.
Considerations:
when resolving the path, the actual filesystem path is checked with repo fetchers
/foo/barwhich is not guaranteed to be absent, accessible, nor empty of a contained repo.gitdirectories are forbiddenthe case where
baseDiris set also has other features. Enabling them for the other case would be a larger departure from current behavior but could be valuable. To taste.flake.nixfilename to the bare directory and emits a warningflake.nixCloses: #5836
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.