1010
1111namespace nix ::fetchers {
1212
13- std::shared_ptr<Registry> Registry::read (const Settings & settings, const Path & path, RegistryType type)
13+ std::shared_ptr<Registry> Registry::read (const Settings & settings, const SourcePath & path, RegistryType type)
1414{
1515 debug (" reading registry '%s'" , path);
1616
1717 auto registry = std::make_shared<Registry>(settings, type);
1818
19- if (!pathExists (path ))
19+ if (!path. pathExists ())
2020 return std::make_shared<Registry>(settings, type);
2121
2222 try {
2323
24- auto json = nlohmann::json::parse (readFile (path ));
24+ auto json = nlohmann::json::parse (path. readFile ());
2525
2626 auto version = json.value (" version" , 0 );
2727
@@ -97,7 +97,10 @@ static Path getSystemRegistryPath()
9797
9898static std::shared_ptr<Registry> getSystemRegistry (const Settings & settings)
9999{
100- static auto systemRegistry = Registry::read (settings, getSystemRegistryPath (), Registry::System);
100+ static auto systemRegistry = Registry::read (
101+ settings,
102+ SourcePath{getFSSourceAccessor (), CanonPath{getSystemRegistryPath ()}}.resolveSymlinks (),
103+ Registry::System);
101104 return systemRegistry;
102105}
103106
@@ -108,13 +111,17 @@ Path getUserRegistryPath()
108111
109112std::shared_ptr<Registry> getUserRegistry (const Settings & settings)
110113{
111- static auto userRegistry = Registry::read (settings, getUserRegistryPath (), Registry::User);
114+ static auto userRegistry = Registry::read (
115+ settings,
116+ SourcePath{getFSSourceAccessor (), CanonPath{getUserRegistryPath ()}}.resolveSymlinks (),
117+ Registry::User);
112118 return userRegistry;
113119}
114120
115121std::shared_ptr<Registry> getCustomRegistry (const Settings & settings, const Path & p)
116122{
117- static auto customRegistry = Registry::read (settings, p, Registry::Custom);
123+ static auto customRegistry =
124+ Registry::read (settings, SourcePath{getFSSourceAccessor (), CanonPath{p}}.resolveSymlinks (), Registry::Custom);
118125 return customRegistry;
119126}
120127
@@ -137,14 +144,19 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, re
137144 return std::make_shared<Registry>(settings, Registry::Global); // empty registry
138145 }
139146
140- if (!isAbsolute (path)) {
141- auto storePath = downloadFile (store, settings, path, " flake-registry.json" ).storePath ;
142- if (auto store2 = store.dynamic_pointer_cast <LocalFSStore>())
143- store2->addPermRoot (storePath, getCacheDir () + " /flake-registry.json" );
144- path = store->toRealPath (storePath);
145- }
146-
147- return Registry::read (settings, path, Registry::Global);
147+ return Registry::read (
148+ settings,
149+ [&] -> SourcePath {
150+ if (!isAbsolute (path)) {
151+ auto storePath = downloadFile (store, settings, path, " flake-registry.json" ).storePath ;
152+ if (auto store2 = store.dynamic_pointer_cast <LocalFSStore>())
153+ store2->addPermRoot (storePath, getCacheDir () + " /flake-registry.json" );
154+ return {store->requireStoreObjectAccessor (storePath)};
155+ } else {
156+ return SourcePath{getFSSourceAccessor (), CanonPath{path}}.resolveSymlinks ();
157+ }
158+ }(),
159+ Registry::Global);
148160 }();
149161
150162 return reg;
0 commit comments