forked from lix-project/lix
FlakeRegistry = FlakeRef -> FlakeRef
This commit is contained in:
parent
c64f98b883
commit
4ad4e48668
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
|
||||||
"flakes": {
|
"flakes": {
|
||||||
"dwarffs": {
|
"dwarffs": {
|
||||||
"uri": "github:edolstra/dwarffs/flake"
|
"uri": "github:edolstra/dwarffs/flake"
|
||||||
|
@ -7,5 +6,6 @@
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"uri": "github:edolstra/nixpkgs/flake"
|
"uri": "github:edolstra/nixpkgs/flake"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"version": 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,8 @@ std::shared_ptr<FlakeRegistry> readRegistry(const Path & path)
|
||||||
throw Error("flake registry '%s' has unsupported version %d", path, version);
|
throw Error("flake registry '%s' has unsupported version %d", path, version);
|
||||||
|
|
||||||
auto flakes = json["flakes"];
|
auto flakes = json["flakes"];
|
||||||
for (auto i = flakes.begin(); i != flakes.end(); ++i) {
|
for (auto i = flakes.begin(); i != flakes.end(); ++i)
|
||||||
FlakeRegistry::Entry entry{FlakeRef(i->value("uri", ""))};
|
registry->entries.emplace(i.key(), FlakeRef(i->value("uri", "")));
|
||||||
registry->entries.emplace(i.key(), entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
@ -41,9 +39,8 @@ void writeRegistry(FlakeRegistry registry, Path path)
|
||||||
{
|
{
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
json["version"] = 1;
|
json["version"] = 1;
|
||||||
for (auto elem : registry.entries) {
|
for (auto elem : registry.entries)
|
||||||
json["flakes"][elem.first] = { {"uri", elem.second.ref.to_string()} };
|
json["flakes"][elem.first.to_string()] = { {"uri", elem.second.to_string()} };
|
||||||
}
|
|
||||||
createDirs(dirOf(path));
|
createDirs(dirOf(path));
|
||||||
writeFile(path, json.dump(4)); // The '4' is the number of spaces used in the indentation in the json file.
|
writeFile(path, json.dump(4)); // The '4' is the number of spaces used in the indentation in the json file.
|
||||||
}
|
}
|
||||||
|
@ -127,106 +124,31 @@ void writeLockFile(LockFile lockFile, Path path)
|
||||||
writeFile(path, json.dump(4)); // '4' = indentation in json file
|
writeFile(path, json.dump(4)); // '4' = indentation in json file
|
||||||
}
|
}
|
||||||
|
|
||||||
Path getUserRegistryPath()
|
std::shared_ptr<FlakeRegistry> getGlobalRegistry()
|
||||||
>>>>>>> Fixed dependency resolution
|
|
||||||
{
|
{
|
||||||
FlakeRef flakeRef(json["uri"]);
|
return std::make_shared<FlakeRegistry>();
|
||||||
if (!flakeRef.isImmutable())
|
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
|
||||||
|
|
||||||
LockFile::FlakeEntry entry(flakeRef);
|
|
||||||
|
|
||||||
auto nonFlakeRequires = json["nonFlakeRequires"];
|
|
||||||
|
|
||||||
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
|
||||||
FlakeRef flakeRef(i->value("uri", ""));
|
|
||||||
if (!flakeRef.isImmutable())
|
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
|
||||||
entry.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto requires = json["requires"];
|
|
||||||
|
|
||||||
for (auto i = requires.begin(); i != requires.end(); ++i)
|
|
||||||
entry.flakeEntries.insert_or_assign(i.key(), readFlakeEntry(*i));
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
LockFile readLockFile(const Path & path)
|
|
||||||
{
|
|
||||||
LockFile lockFile;
|
|
||||||
|
|
||||||
if (!pathExists(path))
|
|
||||||
return lockFile;
|
|
||||||
|
|
||||||
auto json = nlohmann::json::parse(readFile(path));
|
|
||||||
|
|
||||||
auto version = json.value("version", 0);
|
|
||||||
if (version != 1)
|
|
||||||
throw Error("lock file '%s' has unsupported version %d", path, version);
|
|
||||||
|
|
||||||
auto nonFlakeRequires = json["nonFlakeRequires"];
|
|
||||||
|
|
||||||
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
|
||||||
FlakeRef flakeRef(i->value("uri", ""));
|
|
||||||
if (!flakeRef.isImmutable())
|
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
|
||||||
lockFile.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto requires = json["requires"];
|
|
||||||
|
|
||||||
for (auto i = requires.begin(); i != requires.end(); ++i)
|
|
||||||
lockFile.flakeEntries.insert_or_assign(i.key(), readFlakeEntry(*i));
|
|
||||||
|
|
||||||
return lockFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json flakeEntryToJson(LockFile::FlakeEntry & entry)
|
|
||||||
{
|
|
||||||
nlohmann::json json;
|
|
||||||
json["uri"] = entry.ref.to_string();
|
|
||||||
for (auto & x : entry.nonFlakeEntries)
|
|
||||||
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
|
||||||
for (auto & x : entry.flakeEntries)
|
|
||||||
json["requires"][x.first] = flakeEntryToJson(x.second);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeLockFile(LockFile lockFile, Path path)
|
|
||||||
{
|
|
||||||
nlohmann::json json;
|
|
||||||
json["version"] = 1;
|
|
||||||
json["nonFlakeRequires"];
|
|
||||||
for (auto & x : lockFile.nonFlakeEntries)
|
|
||||||
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
|
||||||
for (auto & x : lockFile.flakeEntries)
|
|
||||||
json["requires"][x.first] = flakeEntryToJson(x.second);
|
|
||||||
createDirs(dirOf(path));
|
|
||||||
writeFile(path, json.dump(4)); // '4' = indentation in json file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path getUserRegistryPath()
|
Path getUserRegistryPath()
|
||||||
{
|
{
|
||||||
return getHome() + "/.config/nix/registry.json";
|
return getHome() + "/.config/nix/registry.json";
|
||||||
}
|
}
|
||||||
std::shared_ptr<FlakeRegistry> getGlobalRegistry()
|
|
||||||
{
|
|
||||||
// FIXME: get from nixos.org.
|
|
||||||
Path registryFile = settings.nixDataDir + "/nix/flake-registry.json";
|
|
||||||
return readRegistry(registryFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<FlakeRegistry> getUserRegistry()
|
std::shared_ptr<FlakeRegistry> getUserRegistry()
|
||||||
{
|
{
|
||||||
return readRegistry(getUserRegistryPath());
|
return readRegistry(getUserRegistryPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<FlakeRegistry> getLocalRegistry()
|
||||||
|
{
|
||||||
|
Path registryFile = settings.nixDataDir + "/nix/flake-registry.json";
|
||||||
|
return readRegistry(registryFile);
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<FlakeRegistry> getFlagRegistry()
|
std::shared_ptr<FlakeRegistry> getFlagRegistry()
|
||||||
{
|
{
|
||||||
|
// TODO (Nick): Implement this.
|
||||||
return std::make_shared<FlakeRegistry>();
|
return std::make_shared<FlakeRegistry>();
|
||||||
// TODO: Implement this once the right flags are implemented.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<FlakeRegistry>> EvalState::getFlakeRegistries()
|
const std::vector<std::shared_ptr<FlakeRegistry>> EvalState::getFlakeRegistries()
|
||||||
|
@ -259,9 +181,9 @@ Value * makeFlakeRegistryValue(EvalState & state)
|
||||||
|
|
||||||
for (auto & registry : registries) {
|
for (auto & registry : registries) {
|
||||||
for (auto & entry : registry->entries) {
|
for (auto & entry : registry->entries) {
|
||||||
auto vEntry = state.allocAttr(*v, entry.first);
|
auto vEntry = state.allocAttr(*v, entry.first.to_string());
|
||||||
state.mkAttrs(*vEntry, 2);
|
state.mkAttrs(*vEntry, 2);
|
||||||
mkString(*state.allocAttr(*vEntry, state.symbols.create("uri")), entry.second.ref.to_string());
|
mkString(*state.allocAttr(*vEntry, state.symbols.create("uri")), entry.second.to_string());
|
||||||
vEntry->attrs->sort();
|
vEntry->attrs->sort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,22 +194,29 @@ Value * makeFlakeRegistryValue(EvalState & state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
|
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
|
||||||
std::vector<std::shared_ptr<FlakeRegistry>> registries)
|
std::vector<std::shared_ptr<FlakeRegistry>> registries, std::vector<FlakeRef> pastSearches = {})
|
||||||
{
|
{
|
||||||
if (auto refData = std::get_if<FlakeRef::IsAlias>(&flakeRef.data)) {
|
for (std::shared_ptr<FlakeRegistry> registry : registries) {
|
||||||
for (auto registry : registries) {
|
auto i = registry->entries.find(flakeRef);
|
||||||
auto i = registry->entries.find(refData->alias);
|
|
||||||
if (i != registry->entries.end()) {
|
if (i != registry->entries.end()) {
|
||||||
auto newRef = FlakeRef(i->second.ref);
|
auto newRef = i->second;
|
||||||
if (!newRef.isDirect())
|
if (std::get_if<FlakeRef::IsAlias>(&flakeRef.data)) {
|
||||||
throw Error("found indirect flake URI '%s' in the flake registry", i->second.ref.to_string());
|
if (flakeRef.ref) newRef.ref = flakeRef.ref;
|
||||||
if (flakeRef.ref) newRef.setRef(*flakeRef.ref);
|
if (flakeRef.rev) newRef.rev = flakeRef.rev;
|
||||||
if (flakeRef.rev) newRef.setRev(*flakeRef.rev);
|
}
|
||||||
return newRef;
|
std::string errorMsg = "found cycle in flake registries: ";
|
||||||
|
for (FlakeRef oldRef : pastSearches) {
|
||||||
|
errorMsg += oldRef.to_string();
|
||||||
|
if (oldRef == newRef)
|
||||||
|
throw Error(errorMsg);
|
||||||
|
errorMsg += " - ";
|
||||||
|
}
|
||||||
|
pastSearches.push_back(newRef);
|
||||||
|
return lookupFlake(state, newRef, registries, pastSearches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw Error("cannot find flake with alias '%s' in the flake registry or in the flake lock file", refData->alias);
|
if (!flakeRef.isDirect())
|
||||||
} else
|
throw Error("indirect flake URI '%s' is the result of a lookup", flakeRef.to_string());
|
||||||
return flakeRef;
|
return flakeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,6 +231,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
|
||||||
{
|
{
|
||||||
FlakeRef fRef = lookupFlake(state, flakeRef, state.getFlakeRegistries());
|
FlakeRef fRef = lookupFlake(state, flakeRef, state.getFlakeRegistries());
|
||||||
|
|
||||||
|
// This only downloads only one revision of the repo, not the entire history.
|
||||||
if (auto refData = std::get_if<FlakeRef::IsGitHub>(&fRef.data)) {
|
if (auto refData = std::get_if<FlakeRef::IsGitHub>(&fRef.data)) {
|
||||||
if (evalSettings.pureEval && !impureIsAllowed && !fRef.isImmutable())
|
if (evalSettings.pureEval && !impureIsAllowed && !fRef.isImmutable())
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", fRef.to_string());
|
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", fRef.to_string());
|
||||||
|
@ -332,6 +262,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This downloads the entire git history
|
||||||
else if (auto refData = std::get_if<FlakeRef::IsGit>(&fRef.data)) {
|
else if (auto refData = std::get_if<FlakeRef::IsGit>(&fRef.data)) {
|
||||||
auto gitInfo = exportGit(state.store, refData->uri, fRef.ref,
|
auto gitInfo = exportGit(state.store, refData->uri, fRef.ref,
|
||||||
fRef.rev ? fRef.rev->to_string(Base16, false) : "", "source");
|
fRef.rev ? fRef.rev->to_string(Base16, false) : "", "source");
|
||||||
|
@ -342,7 +273,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (auto refData = std::get_if<FlakeRef::IsPath>(&directFlakeRef.data)) {
|
else if (auto refData = std::get_if<FlakeRef::IsPath>(&fRef.data)) {
|
||||||
if (!pathExists(refData->path + "/.git"))
|
if (!pathExists(refData->path + "/.git"))
|
||||||
throw Error("flake '%s' does not reference a Git repository", refData->path);
|
throw Error("flake '%s' does not reference a Git repository", refData->path);
|
||||||
auto gitInfo = exportGit(state.store, refData->path, {}, "", "source");
|
auto gitInfo = exportGit(state.store, refData->path, {}, "", "source");
|
||||||
|
@ -452,7 +383,7 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al
|
||||||
dependencies.
|
dependencies.
|
||||||
FIXME: this should return a graph of flakes.
|
FIXME: this should return a graph of flakes.
|
||||||
*/
|
*/
|
||||||
Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef, bool impureTopRef, bool isTopFlake = true)
|
Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef, bool impureTopRef, bool isTopFlake)
|
||||||
{
|
{
|
||||||
Flake flake = getFlake(state, topRef, isTopFlake && impureTopRef);
|
Flake flake = getFlake(state, topRef, isTopFlake && impureTopRef);
|
||||||
Dependencies deps(flake);
|
Dependencies deps(flake);
|
||||||
|
@ -461,7 +392,7 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef, bool impur
|
||||||
deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first));
|
deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first));
|
||||||
|
|
||||||
for (auto & newFlakeRef : flake.requires)
|
for (auto & newFlakeRef : flake.requires)
|
||||||
deps.flakeDeps.push_back(resolveFlake(state, newFlakeRef, impureTopRef, false));
|
deps.flakeDeps.push_back(resolveFlake(state, newFlakeRef, false));
|
||||||
|
|
||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
@ -505,25 +436,23 @@ void updateLockFile(EvalState & state, Path path)
|
||||||
|
|
||||||
// Return the `provides` of the top flake, while assigning to `v` the provides
|
// Return the `provides` of the top flake, while assigning to `v` the provides
|
||||||
// of the dependencies as well.
|
// of the dependencies as well.
|
||||||
Value * makeFlakeValue(EvalState & state, FlakeUri flakeUri, Value & v)
|
Value * makeFlakeValue(EvalState & state, const FlakeRef & flakeRef, bool impureTopRef, Value & v)
|
||||||
{
|
{
|
||||||
FlakeRef flakeRef = FlakeRef(flakeUri);
|
Dependencies deps = resolveFlake(state, flakeRef, impureTopRef);
|
||||||
|
|
||||||
Dependencies deps = resolveFlake(state, flakeRef, impure);
|
// FIXME: we should call each flake with only its dependencies
|
||||||
|
// (rather than the closure of the top-level flake).
|
||||||
// // FIXME: we should call each flake with only its dependencies
|
|
||||||
// // (rather than the closure of the top-level flake).
|
|
||||||
|
|
||||||
auto vResult = state.allocValue();
|
auto vResult = state.allocValue();
|
||||||
// This will store the attribute set of the `nonFlakeRequires` and the `requires.provides`.
|
// This will store the attribute set of the `nonFlakeRequires` and the `requires.provides`.
|
||||||
|
|
||||||
state.mkAttrs(*vResult, deps.flakeDeps.size());
|
state.mkAttrs(*vResult, deps.flakeDeps.size());
|
||||||
|
|
||||||
Value * vTop = 0;
|
Value * vTop = state.allocAttr(*vResult, deps.flake.id);
|
||||||
|
|
||||||
for (auto & flake : deps.flakeDeps) {
|
for (auto & dep : deps.flakeDeps) {
|
||||||
|
Flake flake = dep.flake;
|
||||||
auto vFlake = state.allocAttr(*vResult, flake.id);
|
auto vFlake = state.allocAttr(*vResult, flake.id);
|
||||||
if (deps.topFlakeId == flake.id) vTop = vFlake;
|
|
||||||
|
|
||||||
state.mkAttrs(*vFlake, 4);
|
state.mkAttrs(*vFlake, 4);
|
||||||
|
|
||||||
|
@ -532,7 +461,7 @@ Value * makeFlakeValue(EvalState & state, FlakeUri flakeUri, Value & v)
|
||||||
state.store->assertStorePath(flake.path);
|
state.store->assertStorePath(flake.path);
|
||||||
mkString(*state.allocAttr(*vFlake, state.sOutPath), flake.path, {flake.path});
|
mkString(*state.allocAttr(*vFlake, state.sOutPath), flake.path, {flake.path});
|
||||||
|
|
||||||
if (flake.second.revCount)
|
if (flake.revCount)
|
||||||
mkInt(*state.allocAttr(*vFlake, state.symbols.create("revCount")), *flake.revCount);
|
mkInt(*state.allocAttr(*vFlake, state.symbols.create("revCount")), *flake.revCount);
|
||||||
|
|
||||||
auto vProvides = state.allocAttr(*vFlake, state.symbols.create("provides"));
|
auto vProvides = state.allocAttr(*vFlake, state.symbols.create("provides"));
|
||||||
|
|
|
@ -10,13 +10,7 @@ class EvalState;
|
||||||
|
|
||||||
struct FlakeRegistry
|
struct FlakeRegistry
|
||||||
{
|
{
|
||||||
struct Entry
|
std::map<FlakeRef, FlakeRef> entries;
|
||||||
{
|
|
||||||
FlakeRef ref;
|
|
||||||
Entry(const FlakeRef & flakeRef) : ref(flakeRef) {};
|
|
||||||
Entry operator=(const Entry & entry) { return Entry(entry.ref); }
|
|
||||||
};
|
|
||||||
std::map<FlakeAlias, Entry> entries;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LockFile
|
struct LockFile
|
||||||
|
@ -79,7 +73,7 @@ struct Dependencies
|
||||||
Dependencies(const Flake & flake) : flake(flake) {}
|
Dependencies(const Flake & flake) : flake(flake) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Dependencies resolveFlake(EvalState &, const FlakeRef &, bool impureTopRef, bool isTopFlake);
|
Dependencies resolveFlake(EvalState &, const FlakeRef &, bool impureTopRef, bool isTopFlake = true);
|
||||||
|
|
||||||
FlakeRegistry updateLockFile(EvalState &, Flake &);
|
FlakeRegistry updateLockFile(EvalState &, Flake &);
|
||||||
|
|
||||||
|
|
|
@ -103,48 +103,60 @@ typedef std::string FlakeUri;
|
||||||
|
|
||||||
struct FlakeRef
|
struct FlakeRef
|
||||||
{
|
{
|
||||||
std::optional<std::string> ref;
|
|
||||||
std::optional<Hash> rev;
|
|
||||||
|
|
||||||
struct IsAlias
|
struct IsAlias
|
||||||
{
|
{
|
||||||
FlakeAlias alias;
|
FlakeAlias alias;
|
||||||
|
bool operator<(const IsAlias & b) const { return alias < b.alias; };
|
||||||
|
bool operator==(const IsAlias & b) const { return alias == b.alias; };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IsGitHub
|
struct IsGitHub {
|
||||||
{
|
|
||||||
std::string owner, repo;
|
std::string owner, repo;
|
||||||
|
bool operator<(const IsGitHub & b) const {
|
||||||
|
return std::make_tuple(owner, repo) < std::make_tuple(b.owner, b.repo);
|
||||||
|
}
|
||||||
|
bool operator==(const IsGitHub & b) const {
|
||||||
|
return owner == b.owner && repo == b.repo;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Git, Tarball
|
// Git, Tarball
|
||||||
struct IsGit
|
struct IsGit
|
||||||
{
|
{
|
||||||
std::string uri;
|
std::string uri;
|
||||||
|
bool operator<(const IsGit & b) const { return uri < b.uri; }
|
||||||
|
bool operator==(const IsGit & b) const { return uri == b.uri; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IsPath
|
struct IsPath
|
||||||
{
|
{
|
||||||
Path path;
|
Path path;
|
||||||
|
bool operator<(const IsPath & b) const { return path < b.path; }
|
||||||
|
bool operator==(const IsPath & b) const { return path == b.path; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Git, Tarball
|
// Git, Tarball
|
||||||
|
|
||||||
std::variant<IsFlakeId, IsGitHub, IsGit, IsPath> data;
|
std::variant<IsAlias, IsGitHub, IsGit, IsPath> data;
|
||||||
|
|
||||||
|
std::optional<std::string> ref;
|
||||||
|
std::optional<Hash> rev;
|
||||||
|
|
||||||
|
bool operator<(const FlakeRef & flakeRef) const
|
||||||
|
{
|
||||||
|
return std::make_tuple(this->data, ref, rev) <
|
||||||
|
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const FlakeRef & flakeRef) const
|
||||||
|
{
|
||||||
|
return std::make_tuple(this->data, ref, rev) ==
|
||||||
|
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse a flake URI.
|
// Parse a flake URI.
|
||||||
FlakeRef(const std::string & uri, bool allowRelative = false);
|
FlakeRef(const std::string & uri, bool allowRelative = false);
|
||||||
|
|
||||||
// Default constructor
|
|
||||||
FlakeRef(const FlakeRef & flakeRef) : data(flakeRef.data) {};
|
|
||||||
|
|
||||||
/* Unify two flake references so that the resulting reference
|
|
||||||
combines the information from both. For example,
|
|
||||||
"nixpkgs/<hash>" and "github:NixOS/nixpkgs" unifies to
|
|
||||||
"nixpkgs/master". May throw an exception if the references are
|
|
||||||
incompatible (e.g. "nixpkgs/<hash1>" and "nixpkgs/<hash2>",
|
|
||||||
where hash1 != hash2). */
|
|
||||||
FlakeRef(const FlakeRef & a, const FlakeRef & b);
|
|
||||||
|
|
||||||
// FIXME: change to operator <<.
|
// FIXME: change to operator <<.
|
||||||
std::string to_string() const;
|
std::string to_string() const;
|
||||||
|
|
||||||
|
@ -160,9 +172,5 @@ struct FlakeRef
|
||||||
bool isImmutable() const;
|
bool isImmutable() const;
|
||||||
|
|
||||||
FlakeRef baseRef() const;
|
FlakeRef baseRef() const;
|
||||||
|
|
||||||
void setRef(std::optional<std::string> ref) { ref = ref; }
|
|
||||||
|
|
||||||
void setRev(std::optional<Hash> rev) { rev = rev; }
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include "primops/flake.hh"
|
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
#include "command.hh"
|
#include "command.hh"
|
||||||
#include "common-args.hh"
|
#include "common-args.hh"
|
||||||
|
@ -78,7 +77,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::string flakeUri = "";
|
// FlakeUri flakeUri = "";
|
||||||
// if(updateLock)
|
// if(updateLock)
|
||||||
// for (uint i = 0; i < installables.size(); i++)
|
// for (uint i = 0; i < installables.size(); i++)
|
||||||
// // if (auto flakeUri = installableToFlakeUri)
|
// // if (auto flakeUri = installableToFlakeUri)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
|
#include "primops/flake.hh"
|
||||||
#include "common-eval-args.hh"
|
#include "common-eval-args.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -46,7 +47,7 @@ struct GitRepoCommand : virtual Args
|
||||||
|
|
||||||
struct FlakeCommand : virtual Args
|
struct FlakeCommand : virtual Args
|
||||||
{
|
{
|
||||||
std::string flakeUri;
|
FlakeUri flakeUri;
|
||||||
|
|
||||||
FlakeCommand()
|
FlakeCommand()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include "primops/flake.hh"
|
|
||||||
#include "command.hh"
|
#include "command.hh"
|
||||||
#include "common-args.hh"
|
#include "common-args.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
|
@ -29,11 +28,9 @@ struct CmdFlakeList : StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
for (auto & registry : registries) {
|
for (auto & registry : registries)
|
||||||
for (auto & entry : registry->entries) {
|
for (auto & entry : registry->entries)
|
||||||
std::cout << entry.first << " " << entry.second.ref.to_string() << "\n";
|
std::cout << entry.first.to_string() << " " << entry.second.to_string() << "\n";
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,7 +78,7 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON, StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
FlakeRef flakeRef(flakeUri);
|
FlakeRef flakeRef(flakeUri);
|
||||||
|
|
||||||
Dependencies deps = resolveFlake(*evalState, flakeRef, true, true);
|
Dependencies deps = resolveFlake(*evalState, flakeRef, true);
|
||||||
|
|
||||||
std::queue<Dependencies> todo;
|
std::queue<Dependencies> todo;
|
||||||
todo.push(deps);
|
todo.push(deps);
|
||||||
|
@ -135,15 +132,15 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON, MixEvalArgs, StoreCommand
|
||||||
void run(nix::ref<nix::Store> store) override
|
void run(nix::ref<nix::Store> store) override
|
||||||
{
|
{
|
||||||
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
||||||
nix::Flake flake = nix::getFlake(*evalState, FlakeRef(flakeUri));
|
nix::Flake flake = nix::getFlake(*evalState, FlakeRef(flakeUri), true);
|
||||||
printFlakeInfo(flake, json);
|
printFlakeInfo(flake, json);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdFlakeAdd : MixEvalArgs, Command
|
struct CmdFlakeAdd : MixEvalArgs, Command
|
||||||
{
|
{
|
||||||
FlakeAlias flakeAlias;
|
FlakeUri alias;
|
||||||
FlakeUri flakeUri;
|
FlakeUri uri;
|
||||||
|
|
||||||
std::string name() override
|
std::string name() override
|
||||||
{
|
{
|
||||||
|
@ -157,25 +154,24 @@ struct CmdFlakeAdd : MixEvalArgs, Command
|
||||||
|
|
||||||
CmdFlakeAdd()
|
CmdFlakeAdd()
|
||||||
{
|
{
|
||||||
expectArg("flake-id", &flakeAlias);
|
expectArg("alias", &alias);
|
||||||
expectArg("flake-uri", &flakeUri);
|
expectArg("flake-uri", &uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
FlakeRef newFlakeRef(flakeUri);
|
FlakeRef aliasRef(alias);
|
||||||
Path userRegistryPath = getUserRegistryPath();
|
Path userRegistryPath = getUserRegistryPath();
|
||||||
auto userRegistry = readRegistry(userRegistryPath);
|
auto userRegistry = readRegistry(userRegistryPath);
|
||||||
FlakeRegistry::Entry entry(newFlakeRef);
|
userRegistry->entries.erase(aliasRef);
|
||||||
userRegistry->entries.erase(flakeAlias);
|
userRegistry->entries.insert_or_assign(aliasRef, FlakeRef(uri));
|
||||||
userRegistry->entries.insert_or_assign(flakeAlias, newFlakeRef);
|
|
||||||
writeRegistry(*userRegistry, userRegistryPath);
|
writeRegistry(*userRegistry, userRegistryPath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdFlakeRemove : virtual Args, MixEvalArgs, Command
|
struct CmdFlakeRemove : virtual Args, MixEvalArgs, Command
|
||||||
{
|
{
|
||||||
FlakeAlias flakeAlias;
|
FlakeUri alias;
|
||||||
|
|
||||||
std::string name() override
|
std::string name() override
|
||||||
{
|
{
|
||||||
|
@ -189,21 +185,21 @@ struct CmdFlakeRemove : virtual Args, MixEvalArgs, Command
|
||||||
|
|
||||||
CmdFlakeRemove()
|
CmdFlakeRemove()
|
||||||
{
|
{
|
||||||
expectArg("flake-id", &flakeAlias);
|
expectArg("alias", &alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
Path userRegistryPath = getUserRegistryPath();
|
Path userRegistryPath = getUserRegistryPath();
|
||||||
auto userRegistry = readRegistry(userRegistryPath);
|
auto userRegistry = readRegistry(userRegistryPath);
|
||||||
userRegistry->entries.erase(flakeAlias);
|
userRegistry->entries.erase(FlakeRef(alias));
|
||||||
writeRegistry(*userRegistry, userRegistryPath);
|
writeRegistry(*userRegistry, userRegistryPath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdFlakePin : virtual Args, StoreCommand, MixEvalArgs
|
struct CmdFlakePin : virtual Args, StoreCommand, MixEvalArgs
|
||||||
{
|
{
|
||||||
FlakeAlias flakeAlias;
|
FlakeUri alias;
|
||||||
|
|
||||||
std::string name() override
|
std::string name() override
|
||||||
{
|
{
|
||||||
|
@ -217,7 +213,7 @@ struct CmdFlakePin : virtual Args, StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
CmdFlakePin()
|
CmdFlakePin()
|
||||||
{
|
{
|
||||||
expectArg("flake-id", &flakeAlias);
|
expectArg("alias", &alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(nix::ref<nix::Store> store) override
|
void run(nix::ref<nix::Store> store) override
|
||||||
|
@ -226,14 +222,13 @@ struct CmdFlakePin : virtual Args, StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
Path userRegistryPath = getUserRegistryPath();
|
Path userRegistryPath = getUserRegistryPath();
|
||||||
FlakeRegistry userRegistry = *readRegistry(userRegistryPath);
|
FlakeRegistry userRegistry = *readRegistry(userRegistryPath);
|
||||||
auto it = userRegistry.entries.find(flakeAlias);
|
auto it = userRegistry.entries.find(FlakeRef(alias));
|
||||||
if (it != userRegistry.entries.end()) {
|
if (it != userRegistry.entries.end()) {
|
||||||
FlakeRef oldRef = it->second.ref;
|
it->second = getFlake(*evalState, it->second, true).ref;
|
||||||
it->second.ref = getFlake(*evalState, oldRef, true).ref;
|
|
||||||
// The 'ref' in 'flake' is immutable.
|
// The 'ref' in 'flake' is immutable.
|
||||||
writeRegistry(userRegistry, userRegistryPath);
|
writeRegistry(userRegistry, userRegistryPath);
|
||||||
} else
|
} else
|
||||||
throw Error("the flake alias '%s' does not exist in the user registry", flakeAlias);
|
throw Error("the flake alias '%s' does not exist in the user registry", alias);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "get-drvs.hh"
|
#include "get-drvs.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "primops/flake.hh"
|
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue