Put flake-related stuff in its own namespace
This commit is contained in:
parent
c356d034f3
commit
6e4a8c47f4
|
@ -17,7 +17,10 @@ namespace nix {
|
||||||
class Store;
|
class Store;
|
||||||
class EvalState;
|
class EvalState;
|
||||||
enum RepairFlag : bool;
|
enum RepairFlag : bool;
|
||||||
|
|
||||||
|
namespace flake {
|
||||||
struct FlakeRegistry;
|
struct FlakeRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v);
|
typedef void (* PrimOpFun) (EvalState & state, const Pos & pos, Value * * args, Value & v);
|
||||||
|
@ -323,12 +326,12 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<FlakeRegistry>> getFlakeRegistries();
|
const std::vector<std::shared_ptr<flake::FlakeRegistry>> getFlakeRegistries();
|
||||||
|
|
||||||
std::shared_ptr<FlakeRegistry> getGlobalFlakeRegistry();
|
std::shared_ptr<flake::FlakeRegistry> getGlobalFlakeRegistry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FlakeRegistry> _globalFlakeRegistry;
|
std::shared_ptr<flake::FlakeRegistry> _globalFlakeRegistry;
|
||||||
std::once_flag _globalFlakeRegistryInit;
|
std::once_flag _globalFlakeRegistryInit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
using namespace flake;
|
||||||
|
|
||||||
|
namespace flake {
|
||||||
|
|
||||||
/* Read a registry. */
|
/* Read a registry. */
|
||||||
std::shared_ptr<FlakeRegistry> readRegistry(const Path & path)
|
std::shared_ptr<FlakeRegistry> readRegistry(const Path & path)
|
||||||
{
|
{
|
||||||
|
@ -133,24 +137,6 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
|
||||||
writeFile(path, json.dump(4) + "\n"); // '4' = indentation in json file
|
writeFile(path, json.dump(4) + "\n"); // '4' = indentation in json file
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<FlakeRegistry> EvalState::getGlobalFlakeRegistry()
|
|
||||||
{
|
|
||||||
std::call_once(_globalFlakeRegistryInit, [&]() {
|
|
||||||
auto path = evalSettings.flakeRegistry;
|
|
||||||
|
|
||||||
if (!hasPrefix(path, "/")) {
|
|
||||||
CachedDownloadRequest request(evalSettings.flakeRegistry);
|
|
||||||
request.name = "flake-registry.json";
|
|
||||||
request.gcRoot = true;
|
|
||||||
path = getDownloader()->downloadCached(store, request).path;
|
|
||||||
}
|
|
||||||
|
|
||||||
_globalFlakeRegistry = readRegistry(path);
|
|
||||||
});
|
|
||||||
|
|
||||||
return _globalFlakeRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
Path getUserRegistryPath()
|
Path getUserRegistryPath()
|
||||||
{
|
{
|
||||||
return getHome() + "/.config/nix/registry.json";
|
return getHome() + "/.config/nix/registry.json";
|
||||||
|
@ -170,17 +156,6 @@ std::shared_ptr<FlakeRegistry> getFlagRegistry(RegistryOverrides registryOverrid
|
||||||
return flagRegistry;
|
return flagRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This always returns a vector with flakeReg, userReg, globalReg.
|
|
||||||
// If one of them doesn't exist, the registry is left empty but does exist.
|
|
||||||
const Registries EvalState::getFlakeRegistries()
|
|
||||||
{
|
|
||||||
Registries registries;
|
|
||||||
registries.push_back(getFlagRegistry(registryOverrides));
|
|
||||||
registries.push_back(getUserRegistry());
|
|
||||||
registries.push_back(getGlobalFlakeRegistry());
|
|
||||||
return registries;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
|
static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
|
||||||
std::vector<FlakeRef> pastSearches = {});
|
std::vector<FlakeRef> pastSearches = {});
|
||||||
|
|
||||||
|
@ -637,3 +612,34 @@ void gitCloneFlake(FlakeRef flakeRef, EvalState & state, Registries registries,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<flake::FlakeRegistry> EvalState::getGlobalFlakeRegistry()
|
||||||
|
{
|
||||||
|
std::call_once(_globalFlakeRegistryInit, [&]() {
|
||||||
|
auto path = evalSettings.flakeRegistry;
|
||||||
|
|
||||||
|
if (!hasPrefix(path, "/")) {
|
||||||
|
CachedDownloadRequest request(evalSettings.flakeRegistry);
|
||||||
|
request.name = "flake-registry.json";
|
||||||
|
request.gcRoot = true;
|
||||||
|
path = getDownloader()->downloadCached(store, request).path;
|
||||||
|
}
|
||||||
|
|
||||||
|
_globalFlakeRegistry = readRegistry(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
return _globalFlakeRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This always returns a vector with flakeReg, userReg, globalReg.
|
||||||
|
// If one of them doesn't exist, the registry is left empty but does exist.
|
||||||
|
const Registries EvalState::getFlakeRegistries()
|
||||||
|
{
|
||||||
|
Registries registries;
|
||||||
|
registries.push_back(getFlagRegistry(registryOverrides));
|
||||||
|
registries.push_back(getUserRegistry());
|
||||||
|
registries.push_back(getGlobalFlakeRegistry());
|
||||||
|
return registries;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -5,13 +5,15 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
struct Value;
|
||||||
|
class EvalState;
|
||||||
|
|
||||||
|
namespace flake {
|
||||||
|
|
||||||
static const size_t FLAG_REGISTRY = 0;
|
static const size_t FLAG_REGISTRY = 0;
|
||||||
static const size_t USER_REGISTRY = 1;
|
static const size_t USER_REGISTRY = 1;
|
||||||
static const size_t GLOBAL_REGISTRY = 2;
|
static const size_t GLOBAL_REGISTRY = 2;
|
||||||
|
|
||||||
struct Value;
|
|
||||||
class EvalState;
|
|
||||||
|
|
||||||
struct FlakeRegistry
|
struct FlakeRegistry
|
||||||
{
|
{
|
||||||
std::map<FlakeRef, FlakeRef> entries;
|
std::map<FlakeRef, FlakeRef> entries;
|
||||||
|
@ -143,3 +145,5 @@ void updateLockFile(EvalState &, const FlakeRef & flakeRef, bool recreateLockFil
|
||||||
void gitCloneFlake(FlakeRef flakeRef, EvalState &, Registries, const Path & destDir);
|
void gitCloneFlake(FlakeRef flakeRef, EvalState &, Registries, const Path & destDir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,10 @@ struct Value;
|
||||||
class Bindings;
|
class Bindings;
|
||||||
class EvalState;
|
class EvalState;
|
||||||
class Store;
|
class Store;
|
||||||
|
|
||||||
|
namespace flake {
|
||||||
enum HandleLockFile : unsigned int;
|
enum HandleLockFile : unsigned int;
|
||||||
|
}
|
||||||
|
|
||||||
/* A command that require a Nix store. */
|
/* A command that require a Nix store. */
|
||||||
struct StoreCommand : virtual Command
|
struct StoreCommand : virtual Command
|
||||||
|
@ -71,7 +74,7 @@ struct MixFlakeOptions : virtual Args
|
||||||
|
|
||||||
MixFlakeOptions();
|
MixFlakeOptions();
|
||||||
|
|
||||||
HandleLockFile getLockFileMode();
|
flake::HandleLockFile getLockFileMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
|
struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
using namespace nix::flake;
|
||||||
|
|
||||||
class FlakeCommand : virtual Args, public EvalCommand, public MixFlakeOptions
|
class FlakeCommand : virtual Args, public EvalCommand, public MixFlakeOptions
|
||||||
{
|
{
|
||||||
|
@ -33,12 +34,12 @@ public:
|
||||||
Flake getFlake()
|
Flake getFlake()
|
||||||
{
|
{
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
return nix::getFlake(*evalState, getFlakeRef(), useRegistries);
|
return flake::getFlake(*evalState, getFlakeRef(), useRegistries);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedFlake resolveFlake()
|
ResolvedFlake resolveFlake()
|
||||||
{
|
{
|
||||||
return nix::resolveFlake(*getEvalState(), getFlakeRef(), getLockFileMode());
|
return flake::resolveFlake(*getEvalState(), getFlakeRef(), getLockFileMode());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ MixFlakeOptions::MixFlakeOptions()
|
||||||
.set(&useRegistries, false);
|
.set(&useRegistries, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleLockFile MixFlakeOptions::getLockFileMode()
|
flake::HandleLockFile MixFlakeOptions::getLockFileMode()
|
||||||
{
|
{
|
||||||
|
using namespace flake;
|
||||||
return
|
return
|
||||||
useRegistries
|
useRegistries
|
||||||
? recreateLockFile
|
? recreateLockFile
|
||||||
|
@ -163,18 +164,20 @@ struct InstallableAttrPath : InstallableValue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void makeFlakeClosureGCRoot(Store & store, const FlakeRef & origFlakeRef, const ResolvedFlake & resFlake)
|
void makeFlakeClosureGCRoot(Store & store,
|
||||||
|
const FlakeRef & origFlakeRef,
|
||||||
|
const flake::ResolvedFlake & resFlake)
|
||||||
{
|
{
|
||||||
if (std::get_if<FlakeRef::IsPath>(&origFlakeRef.data)) return;
|
if (std::get_if<FlakeRef::IsPath>(&origFlakeRef.data)) return;
|
||||||
|
|
||||||
/* Get the store paths of all non-local flakes. */
|
/* Get the store paths of all non-local flakes. */
|
||||||
PathSet closure;
|
PathSet closure;
|
||||||
|
|
||||||
std::queue<std::reference_wrapper<const ResolvedFlake>> queue;
|
std::queue<std::reference_wrapper<const flake::ResolvedFlake>> queue;
|
||||||
queue.push(resFlake);
|
queue.push(resFlake);
|
||||||
|
|
||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
const ResolvedFlake & flake = queue.front();
|
const flake::ResolvedFlake & flake = queue.front();
|
||||||
queue.pop();
|
queue.pop();
|
||||||
if (!std::get_if<FlakeRef::IsPath>(&flake.flake.sourceInfo.resolvedRef.data))
|
if (!std::get_if<FlakeRef::IsPath>(&flake.flake.sourceInfo.resolvedRef.data))
|
||||||
closure.insert(flake.flake.sourceInfo.storePath);
|
closure.insert(flake.flake.sourceInfo.storePath);
|
||||||
|
|
Loading…
Reference in a new issue