mirror of
https://github.com/NixOS/nix
synced 2025-06-28 22:01:15 +02:00
Merge remote-tracking branch 'tweag/flake-test' into flakes
This commit is contained in:
commit
54e54db2e2
14 changed files with 189 additions and 31 deletions
|
@ -1972,6 +1972,14 @@ std::ostream & operator << (std::ostream & str, const ExternalValueBase & v) {
|
|||
|
||||
EvalSettings evalSettings;
|
||||
|
||||
EvalSettings::EvalSettings()
|
||||
{
|
||||
if (flakeRegistry == "")
|
||||
// FIXME: static initialization order fiasco. But this will go
|
||||
// away when we switch to an online registry.
|
||||
flakeRegistry = settings.nixDataDir + "/nix/flake-registry.json";
|
||||
}
|
||||
|
||||
static GlobalConfig::Register r1(&evalSettings);
|
||||
|
||||
|
||||
|
|
|
@ -367,6 +367,11 @@ struct EvalSettings : Config
|
|||
|
||||
Setting<Strings> allowedUris{this, {}, "allowed-uris",
|
||||
"Prefixes of URIs that builtin functions such as fetchurl and fetchGit are allowed to fetch."};
|
||||
|
||||
Setting<std::string> flakeRegistry{this, "", "flake-registry",
|
||||
"Path or URI of the global flake registry."};
|
||||
|
||||
EvalSettings();
|
||||
};
|
||||
|
||||
extern EvalSettings evalSettings;
|
||||
|
|
|
@ -48,7 +48,7 @@ LockFile::FlakeEntry readFlakeEntry(nlohmann::json json)
|
|||
{
|
||||
FlakeRef flakeRef(json["uri"]);
|
||||
if (!flakeRef.isImmutable())
|
||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef);
|
||||
throw Error("cannot use mutable flake '%s' in pure mode", flakeRef);
|
||||
|
||||
LockFile::FlakeEntry entry(flakeRef);
|
||||
|
||||
|
@ -126,8 +126,7 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
|
|||
|
||||
std::shared_ptr<FlakeRegistry> getGlobalRegistry()
|
||||
{
|
||||
Path registryFile = settings.nixDataDir + "/nix/flake-registry.json";
|
||||
return readRegistry(registryFile);
|
||||
return readRegistry(evalSettings.flakeRegistry);
|
||||
}
|
||||
|
||||
Path getUserRegistryPath()
|
||||
|
@ -237,8 +236,8 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
|
|||
if (result.etag->size() != 42 || (*result.etag)[0] != '"' || (*result.etag)[41] != '"')
|
||||
throw Error("ETag header '%s' from '%s' is not a Git revision", *result.etag, url);
|
||||
|
||||
std::string rev = std::string(*result.etag, 1, result.etag->size() - 2);
|
||||
const FlakeRef ref(resolvedRef.baseRef().to_string() + "/" + rev);
|
||||
FlakeRef ref(resolvedRef.baseRef());
|
||||
ref.rev = Hash(std::string(*result.etag, 1, result.etag->size() - 2), htSHA1);
|
||||
SourceInfo info(ref);
|
||||
info.storePath = result.path;
|
||||
|
||||
|
@ -248,7 +247,9 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
|
|||
// This downloads the entire git history
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGit>(&resolvedRef.data)) {
|
||||
auto gitInfo = exportGit(state.store, refData->uri, resolvedRef.ref, resolvedRef.rev, "source");
|
||||
const FlakeRef ref(resolvedRef.baseRef().to_string() + "/" + gitInfo.ref + "/" + gitInfo.rev.to_string(Base16, false));
|
||||
FlakeRef ref(resolvedRef.baseRef());
|
||||
ref.ref = gitInfo.ref;
|
||||
ref.rev = gitInfo.rev;
|
||||
SourceInfo info(ref);
|
||||
info.storePath = gitInfo.storePath;
|
||||
info.revCount = gitInfo.revCount;
|
||||
|
@ -259,7 +260,9 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
|
|||
if (!pathExists(refData->path + "/.git"))
|
||||
throw Error("flake '%s' does not reference a Git repository", refData->path);
|
||||
auto gitInfo = exportGit(state.store, refData->path, {}, {}, "source");
|
||||
const FlakeRef ref(resolvedRef.baseRef().to_string() + "/" + gitInfo.ref + "/" + gitInfo.rev.to_string(Base16, false));
|
||||
FlakeRef ref(resolvedRef.baseRef());
|
||||
ref.ref = gitInfo.ref;
|
||||
ref.rev = gitInfo.rev;
|
||||
SourceInfo info(ref);
|
||||
info.storePath = gitInfo.storePath;
|
||||
info.revCount = gitInfo.revCount;
|
||||
|
|
|
@ -147,31 +147,53 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
|||
std::string FlakeRef::to_string() const
|
||||
{
|
||||
std::string string;
|
||||
bool first = true;
|
||||
|
||||
if (auto refData = std::get_if<FlakeRef::IsAlias>(&data))
|
||||
auto addParam =
|
||||
[&](const std::string & name, std::string value) {
|
||||
string += first ? '?' : '&';
|
||||
first = false;
|
||||
string += name;
|
||||
string += '=';
|
||||
string += value; // FIXME: escaping
|
||||
};
|
||||
|
||||
if (auto refData = std::get_if<FlakeRef::IsAlias>(&data)) {
|
||||
string = refData->alias;
|
||||
if (ref) string += '/' + *ref;
|
||||
if (rev) string += '/' + rev->to_string(Base16, false);
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsPath>(&data)) {
|
||||
assert(subdir == "");
|
||||
assert(!rev);
|
||||
assert(!ref);
|
||||
return refData->path;
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGitHub>(&data)) {
|
||||
assert(!(ref && rev));
|
||||
string = "github:" + refData->owner + "/" + refData->repo;
|
||||
if (ref) { string += '/'; string += *ref; }
|
||||
if (rev) { string += '/'; string += rev->to_string(Base16, false); }
|
||||
if (subdir != "") addParam("dir", subdir);
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGit>(&data)) {
|
||||
assert(!rev || ref);
|
||||
string = refData->uri;
|
||||
|
||||
if (ref) {
|
||||
addParam("ref", *ref);
|
||||
if (rev)
|
||||
addParam("rev", rev->to_string(Base16, false));
|
||||
}
|
||||
|
||||
if (subdir != "") addParam("dir", subdir);
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsPath>(&data))
|
||||
return refData->path;
|
||||
|
||||
else abort();
|
||||
|
||||
// FIXME: need to use ?rev etc. for IsGit URIs.
|
||||
string += (ref ? "/" + *ref : "") +
|
||||
(rev ? "/" + rev->to_string(Base16, false) : "");
|
||||
|
||||
if (subdir != "") string += "?dir=" + subdir;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue