Fetch the flake registry from the NixOS/flake-registry repo

This commit is contained in:
Eelco Dolstra 2019-05-22 22:56:46 +02:00
parent 55a0451e51
commit 66f1d7ee95
7 changed files with 19 additions and 41 deletions

View file

@ -1,20 +0,0 @@
{
"flakes": {
"dwarffs": {
"uri": "github:edolstra/dwarffs/flake"
},
"nix": {
"uri": "github:NixOS/nix/flakes"
},
"nixpkgs": {
"uri": "github:edolstra/nixpkgs/release-19.03"
},
"hydra": {
"uri": "github:NixOS/hydra/flake"
},
"patchelf": {
"uri": "github:NixOS/patchelf"
}
},
"version": 1
}

View file

@ -10,5 +10,3 @@ GLOBAL_CXXFLAGS += -I . -I src -I src/libutil -I src/libstore -I src/libmain -I
$(foreach i, config.h $(call rwildcard, src/lib*, *.hh), \ $(foreach i, config.h $(call rwildcard, src/lib*, *.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix, 0644))) $(eval $(call install-file-in, $(i), $(includedir)/nix, 0644)))
$(eval $(call install-data-in,$(d)/flake-registry.json,$(datadir)/nix))

View file

@ -1978,14 +1978,6 @@ std::ostream & operator << (std::ostream & str, const ExternalValueBase & v) {
EvalSettings evalSettings; 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); static GlobalConfig::Register r1(&evalSettings);

View file

@ -325,9 +325,11 @@ public:
const std::vector<std::shared_ptr<FlakeRegistry>> getFlakeRegistries(); const std::vector<std::shared_ptr<FlakeRegistry>> getFlakeRegistries();
std::shared_ptr<FlakeRegistry> getGlobalFlakeRegistry();
private: private:
std::shared_ptr<FlakeRegistry> _flakeRegistry; std::shared_ptr<FlakeRegistry> _globalFlakeRegistry;
std::once_flag _flakeRegistryInit; std::once_flag _globalFlakeRegistryInit;
}; };
@ -368,10 +370,8 @@ struct EvalSettings : Config
Setting<Strings> allowedUris{this, {}, "allowed-uris", Setting<Strings> allowedUris{this, {}, "allowed-uris",
"Prefixes of URIs that builtin functions such as fetchurl and fetchGit are allowed to fetch."}; "Prefixes of URIs that builtin functions such as fetchurl and fetchGit are allowed to fetch."};
Setting<std::string> flakeRegistry{this, "", "flake-registry", Setting<std::string> flakeRegistry{this, "https://raw.githubusercontent.com/NixOS/flake-registry/master/flake-registry.json", "flake-registry",
"Path or URI of the global flake registry."}; "Path or URI of the global flake registry."};
EvalSettings();
}; };
extern EvalSettings evalSettings; extern EvalSettings evalSettings;

View file

@ -131,9 +131,19 @@ 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> getGlobalRegistry() std::shared_ptr<FlakeRegistry> EvalState::getGlobalFlakeRegistry()
{ {
return readRegistry(evalSettings.flakeRegistry); std::call_once(_globalFlakeRegistryInit, [&]() {
auto path = evalSettings.flakeRegistry;
if (!hasPrefix(path, "/"))
path = getDownloader()->downloadCached(store,
evalSettings.flakeRegistry, false, "registry").path;
_globalFlakeRegistry = readRegistry(path);
});
return _globalFlakeRegistry;
} }
Path getUserRegistryPath() Path getUserRegistryPath()
@ -162,7 +172,7 @@ const Registries EvalState::getFlakeRegistries()
Registries registries; Registries registries;
registries.push_back(getFlagRegistry(registryOverrides)); registries.push_back(getFlagRegistry(registryOverrides));
registries.push_back(getUserRegistry()); registries.push_back(getUserRegistry());
registries.push_back(getGlobalRegistry()); registries.push_back(getGlobalFlakeRegistry());
return registries; return registries;
} }

View file

@ -120,8 +120,6 @@ struct NonFlake
resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {}; resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {};
}; };
std::shared_ptr<FlakeRegistry> getGlobalRegistry();
Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed); Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed);
struct ResolvedFlake struct ResolvedFlake

View file

@ -298,7 +298,7 @@ struct CmdFlakePin : virtual Args, EvalCommand
it->second = getFlake(*evalState, it->second, true).resolvedRef; it->second = getFlake(*evalState, it->second, true).resolvedRef;
writeRegistry(userRegistry, userRegistryPath); writeRegistry(userRegistry, userRegistryPath);
} else { } else {
std::shared_ptr<FlakeRegistry> globalReg = getGlobalRegistry(); std::shared_ptr<FlakeRegistry> globalReg = evalState->getGlobalFlakeRegistry();
it = globalReg->entries.find(FlakeRef(alias)); it = globalReg->entries.find(FlakeRef(alias));
if (it != globalReg->entries.end()) { if (it != globalReg->entries.end()) {
FlakeRef newRef = getFlake(*evalState, it->second, true).resolvedRef; FlakeRef newRef = getFlake(*evalState, it->second, true).resolvedRef;