Allow relative paths in flakerefs
Also allow "." as an installable to refer to the flake in the current directory. E.g. $ nix build . will build 'provides.defaultPackage' in the flake in the current directory.
This commit is contained in:
parent
507da65900
commit
c996e04aca
4 changed files with 15 additions and 8 deletions
|
@ -14,5 +14,6 @@
|
||||||
|
|
||||||
packages.nix = hydraJobs.build.x86_64-linux;
|
packages.nix = hydraJobs.build.x86_64-linux;
|
||||||
|
|
||||||
|
defaultPackage = packages.nix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ const static std::string segmentRegex = "[a-zA-Z0-9._~-]+";
|
||||||
const static std::string pathRegex = "/?" + segmentRegex + "(?:/" + segmentRegex + ")*";
|
const static std::string pathRegex = "/?" + segmentRegex + "(?:/" + segmentRegex + ")*";
|
||||||
const static std::string paramRegex = "[a-z]+=[a-zA-Z0-9._-]*";
|
const static std::string paramRegex = "[a-z]+=[a-zA-Z0-9._-]*";
|
||||||
|
|
||||||
FlakeRef::FlakeRef(const std::string & uri)
|
FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
||||||
{
|
{
|
||||||
// FIXME: could combine this into one regex.
|
// FIXME: could combine this into one regex.
|
||||||
|
|
||||||
|
@ -106,9 +106,9 @@ FlakeRef::FlakeRef(const std::string & uri)
|
||||||
data = d;
|
data = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (hasPrefix(uri, "/")) {
|
else if (hasPrefix(uri, "/") || (allowRelative && (hasPrefix(uri, "./") || uri == "."))) {
|
||||||
IsPath d;
|
IsPath d;
|
||||||
d.path = canonPath(uri);
|
d.path = allowRelative ? absPath(uri) : canonPath(uri);
|
||||||
data = d;
|
data = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ struct FlakeRef
|
||||||
std::variant<IsFlakeId, IsGitHub, IsGit, IsPath> data;
|
std::variant<IsFlakeId, IsGitHub, IsGit, IsPath> data;
|
||||||
|
|
||||||
// Parse a flake URI.
|
// Parse a flake URI.
|
||||||
FlakeRef(const std::string & uri);
|
FlakeRef(const std::string & uri, bool allowRelative = false);
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
FlakeRef(const FlakeRef & flakeRef) : data(flakeRef.data) {};
|
FlakeRef(const FlakeRef & flakeRef) : data(flakeRef.data) {};
|
||||||
|
|
|
@ -219,12 +219,18 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
else if ((colon = s.rfind(':')) != std::string::npos) {
|
else if ((colon = s.rfind(':')) != std::string::npos) {
|
||||||
auto flakeRef = std::string(s, 0, colon);
|
auto flakeRef = std::string(s, 0, colon);
|
||||||
auto attrPath = std::string(s, colon + 1);
|
auto attrPath = std::string(s, colon + 1);
|
||||||
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(flakeRef), attrPath));
|
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(flakeRef, true), attrPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (s.find('/') != std::string::npos) {
|
else if (s.find('/') != std::string::npos || s == ".") {
|
||||||
auto path = store->toStorePath(store->followLinksToStore(s));
|
Path storePath;
|
||||||
result.push_back(std::make_shared<InstallableStorePath>(path));
|
try {
|
||||||
|
storePath = store->toStorePath(store->followLinksToStore(s));
|
||||||
|
} catch (Error) { }
|
||||||
|
if (storePath != "")
|
||||||
|
result.push_back(std::make_shared<InstallableStorePath>(storePath));
|
||||||
|
else
|
||||||
|
result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(s, true), "defaultPackage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue