forked from lix-project/lix
nix registry: add --registry flag
This commit is contained in:
parent
69eb65403a
commit
093ed47636
|
@ -21,6 +21,13 @@ R""(
|
||||||
# nix registry add nixpkgs/nixos-20.03 ~/Dev/nixpkgs
|
# nix registry add nixpkgs/nixos-20.03 ~/Dev/nixpkgs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Add `nixpkgs` pointing to `github:nixos/nixpkgs` to your custom flake
|
||||||
|
registry:
|
||||||
|
|
||||||
|
```console
|
||||||
|
nix registry add --registry ./custom-flake-registry.json nixpkgs github:nixos/nixpkgs
|
||||||
|
```
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
This command adds an entry to the user registry that maps flake
|
This command adds an entry to the user registry that maps flake
|
||||||
|
|
|
@ -24,6 +24,13 @@ R""(
|
||||||
…
|
…
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Pin `nixpkgs` in a custom registry to its most recent Git revision
|
||||||
|
|
||||||
|
```console
|
||||||
|
# nix registry pin --registry ./custom-flake-registry.json nixpkgs
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
This command adds an entry to the user registry that maps flake
|
This command adds an entry to the user registry that maps flake
|
||||||
|
|
|
@ -8,6 +8,12 @@ R""(
|
||||||
# nix registry remove nixpkgs
|
# nix registry remove nixpkgs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Remove the entry `nixpkgs` from a custom registry:
|
||||||
|
|
||||||
|
```console
|
||||||
|
# nix registry remove --registry ./custom-flake-registry.json nixpkgs
|
||||||
|
```
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
This command removes from the user registry any entry for flake
|
This command removes from the user registry any entry for flake
|
||||||
|
|
|
@ -10,6 +10,45 @@
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
using namespace nix::flake;
|
using namespace nix::flake;
|
||||||
|
|
||||||
|
|
||||||
|
class RegistryCommand: virtual Args
|
||||||
|
{
|
||||||
|
std::string registry_path;
|
||||||
|
|
||||||
|
std::shared_ptr<fetchers::Registry> registry;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RegistryCommand()
|
||||||
|
{
|
||||||
|
addFlag({
|
||||||
|
.longName = "registry",
|
||||||
|
.description = "The registry to operate on.",
|
||||||
|
.labels = {"registry"},
|
||||||
|
.handler = {®istry_path},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<fetchers::Registry> getRegistry() {
|
||||||
|
if (registry) return registry;
|
||||||
|
if (registry_path.empty()) {
|
||||||
|
registry = fetchers::getUserRegistry();
|
||||||
|
} else {
|
||||||
|
registry = fetchers::getCustomRegistry(registry_path);
|
||||||
|
}
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path getRegistryPath() {
|
||||||
|
if (registry_path.empty()) {
|
||||||
|
return fetchers::getUserRegistryPath();
|
||||||
|
} else {
|
||||||
|
return registry_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct CmdRegistryList : StoreCommand
|
struct CmdRegistryList : StoreCommand
|
||||||
{
|
{
|
||||||
std::string description() override
|
std::string description() override
|
||||||
|
@ -45,7 +84,7 @@ struct CmdRegistryList : StoreCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdRegistryAdd : MixEvalArgs, Command
|
struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand
|
||||||
{
|
{
|
||||||
std::string fromUrl, toUrl;
|
std::string fromUrl, toUrl;
|
||||||
|
|
||||||
|
@ -71,16 +110,16 @@ struct CmdRegistryAdd : MixEvalArgs, Command
|
||||||
{
|
{
|
||||||
auto fromRef = parseFlakeRef(fromUrl);
|
auto fromRef = parseFlakeRef(fromUrl);
|
||||||
auto toRef = parseFlakeRef(toUrl);
|
auto toRef = parseFlakeRef(toUrl);
|
||||||
|
auto registry = getRegistry();
|
||||||
fetchers::Attrs extraAttrs;
|
fetchers::Attrs extraAttrs;
|
||||||
if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir;
|
if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir;
|
||||||
auto userRegistry = fetchers::getUserRegistry();
|
registry->remove(fromRef.input);
|
||||||
userRegistry->remove(fromRef.input);
|
registry->add(fromRef.input, toRef.input, extraAttrs);
|
||||||
userRegistry->add(fromRef.input, toRef.input, extraAttrs);
|
registry->write(getRegistryPath());
|
||||||
userRegistry->write(fetchers::getUserRegistryPath());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdRegistryRemove : virtual Args, MixEvalArgs, Command
|
struct CmdRegistryRemove : RegistryCommand, Command
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
|
|
||||||
|
@ -103,13 +142,13 @@ struct CmdRegistryRemove : virtual Args, MixEvalArgs, Command
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
auto userRegistry = fetchers::getUserRegistry();
|
auto registry = getRegistry();
|
||||||
userRegistry->remove(parseFlakeRef(url).input);
|
registry->remove(parseFlakeRef(url).input);
|
||||||
userRegistry->write(fetchers::getUserRegistryPath());
|
registry->write(getRegistryPath());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdRegistryPin : virtual Args, EvalCommand
|
struct CmdRegistryPin : RegistryCommand, EvalCommand
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
|
|
||||||
|
@ -132,14 +171,14 @@ struct CmdRegistryPin : virtual Args, EvalCommand
|
||||||
|
|
||||||
void run(nix::ref<nix::Store> store) override
|
void run(nix::ref<nix::Store> store) override
|
||||||
{
|
{
|
||||||
|
auto registry = getRegistry();
|
||||||
auto ref = parseFlakeRef(url);
|
auto ref = parseFlakeRef(url);
|
||||||
auto userRegistry = fetchers::getUserRegistry();
|
registry->remove(ref.input);
|
||||||
userRegistry->remove(ref.input);
|
|
||||||
auto [tree, resolved] = ref.resolve(store).input.fetch(store);
|
auto [tree, resolved] = ref.resolve(store).input.fetch(store);
|
||||||
fetchers::Attrs extraAttrs;
|
fetchers::Attrs extraAttrs;
|
||||||
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
|
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
|
||||||
userRegistry->add(ref.input, resolved, extraAttrs);
|
registry->add(ref.input, resolved, extraAttrs);
|
||||||
userRegistry->write(fetchers::getUserRegistryPath());
|
registry->write(getRegistryPath());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue