From 77ffaea4fa12f0525758d6c4a3a3bd074906978d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Apr 2020 22:56:50 +0200 Subject: [PATCH] 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 } --- src/libfetchers/registry.cc | 17 ++++++++++++++++- src/libfetchers/registry.hh | 3 ++- src/nix/flake.cc | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index 34e63180c..08dbe797e 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -96,6 +96,18 @@ void Registry::remove(const std::shared_ptr & input) ++i; } +static Path getSystemRegistryPath() +{ + return settings.nixConfDir + "/registry.json"; +} + +static std::shared_ptr getSystemRegistry() +{ + static auto systemRegistry = + Registry::read(getSystemRegistryPath(), Registry::System); + return systemRegistry; +} + Path getUserRegistryPath() { return getHome() + "/.config/nix/registry.json"; @@ -103,7 +115,9 @@ Path getUserRegistryPath() std::shared_ptr getUserRegistry() { - return Registry::read(getUserRegistryPath(), Registry::User); + static auto userRegistry = + Registry::read(getUserRegistryPath(), Registry::User); + return userRegistry; } static std::shared_ptr flagRegistry = @@ -145,6 +159,7 @@ Registries getRegistries(ref store) Registries registries; registries.push_back(getFlagRegistry()); registries.push_back(getUserRegistry()); + registries.push_back(getSystemRegistry()); registries.push_back(getGlobalRegistry(store)); return registries; } diff --git a/src/libfetchers/registry.hh b/src/libfetchers/registry.hh index d2eb7749b..5e8857850 100644 --- a/src/libfetchers/registry.hh +++ b/src/libfetchers/registry.hh @@ -12,7 +12,8 @@ struct Registry enum RegistryType { Flag = 0, User = 1, - Global = 2, + System = 2, + Global = 3, }; RegistryType type; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 2cc61932d..16b797de8 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -67,8 +67,9 @@ struct CmdFlakeList : EvalCommand for (auto & entry : registry->entries) { // FIXME: format nicely std::cout << fmt("%s %s %s\n", - registry->type == Registry::Flag ? "flags " : - registry->type == Registry::User ? "user " : + registry->type == Registry::Flag ? "flags " : + registry->type == Registry::User ? "user " : + registry->type == Registry::System ? "system" : "global", std::get<0>(entry)->to_string(), std::get<1>(entry)->to_string());