mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
nix flake add: Handle ~/.config/nix not existing
Fixes $ nix flake add fnord github:edolstra/fnord error: opening file '/home/eelco/.config/nix/registry.json': No such file or directory
This commit is contained in:
parent
42be60c6af
commit
f9c7176a87
1 changed files with 13 additions and 8 deletions
|
@ -23,6 +23,7 @@ std::unique_ptr<FlakeRegistry> readRegistry(const Path & path)
|
|||
{
|
||||
auto registry = std::make_unique<FlakeRegistry>();
|
||||
|
||||
try {
|
||||
auto json = nlohmann::json::parse(readFile(path));
|
||||
|
||||
auto version = json.value("version", 0);
|
||||
|
@ -34,6 +35,9 @@ std::unique_ptr<FlakeRegistry> readRegistry(const Path & path)
|
|||
FlakeRegistry::Entry entry{FlakeRef(i->value("uri", ""))};
|
||||
registry->entries.emplace(i.key(), entry);
|
||||
}
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo != ENOENT) throw;
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
@ -47,6 +51,7 @@ void writeRegistry(FlakeRegistry registry, Path path)
|
|||
for (auto elem : registry.entries) {
|
||||
json["flakes"][elem.first] = { {"uri", elem.second.ref.to_string()} };
|
||||
}
|
||||
createDirs(dirOf(path));
|
||||
writeFile(path, json.dump(4)); // The '4' is the number of spaces used in the indentation in the json file.
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue