Add a system-wide flake registry /etc/nix/registry.json

One application for this is pinning the 'nixpkgs' flake to the exact
revision used to build the NixOS system, e.g.

  {
      "flakes": [
          {
              "from": {
                  "id": "nixpkgs",
                  "type": "indirect"
              },
              "to": {
                  "owner": "NixOS",
                  "repo": "nixpkgs",
                  "type": "github",
                  "rev": "b0c285807d6a9f1b7562ec417c24fa1a30ecc31a"
              }
          }
      ],
      "version": 2
  }
This commit is contained in:
Eelco Dolstra 2020-04-01 22:56:50 +02:00
parent 36c34c3b1f
commit 77ffaea4fa
3 changed files with 21 additions and 4 deletions

View file

@ -96,6 +96,18 @@ void Registry::remove(const std::shared_ptr<const Input> & input)
++i; ++i;
} }
static Path getSystemRegistryPath()
{
return settings.nixConfDir + "/registry.json";
}
static std::shared_ptr<Registry> getSystemRegistry()
{
static auto systemRegistry =
Registry::read(getSystemRegistryPath(), Registry::System);
return systemRegistry;
}
Path getUserRegistryPath() Path getUserRegistryPath()
{ {
return getHome() + "/.config/nix/registry.json"; return getHome() + "/.config/nix/registry.json";
@ -103,7 +115,9 @@ Path getUserRegistryPath()
std::shared_ptr<Registry> getUserRegistry() std::shared_ptr<Registry> getUserRegistry()
{ {
return Registry::read(getUserRegistryPath(), Registry::User); static auto userRegistry =
Registry::read(getUserRegistryPath(), Registry::User);
return userRegistry;
} }
static std::shared_ptr<Registry> flagRegistry = static std::shared_ptr<Registry> flagRegistry =
@ -145,6 +159,7 @@ Registries getRegistries(ref<Store> store)
Registries registries; Registries registries;
registries.push_back(getFlagRegistry()); registries.push_back(getFlagRegistry());
registries.push_back(getUserRegistry()); registries.push_back(getUserRegistry());
registries.push_back(getSystemRegistry());
registries.push_back(getGlobalRegistry(store)); registries.push_back(getGlobalRegistry(store));
return registries; return registries;
} }

View file

@ -12,7 +12,8 @@ struct Registry
enum RegistryType { enum RegistryType {
Flag = 0, Flag = 0,
User = 1, User = 1,
Global = 2, System = 2,
Global = 3,
}; };
RegistryType type; RegistryType type;

View file

@ -69,6 +69,7 @@ struct CmdFlakeList : EvalCommand
std::cout << fmt("%s %s %s\n", std::cout << fmt("%s %s %s\n",
registry->type == Registry::Flag ? "flags " : registry->type == Registry::Flag ? "flags " :
registry->type == Registry::User ? "user " : registry->type == Registry::User ? "user " :
registry->type == Registry::System ? "system" :
"global", "global",
std::get<0>(entry)->to_string(), std::get<0>(entry)->to_string(),
std::get<1>(entry)->to_string()); std::get<1>(entry)->to_string());