From b30556f8f13139caa46fa0cf6ade0b925b358f00 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sat, 15 Mar 2025 17:08:05 -0700 Subject: [PATCH 1/2] RegisterCommand -> CommandRegistry This should be submitted as part of a stack, doesn't make too much sense on its own, but it's mechanical and it builds it's easy to split it out of the diff. Change-Id: I453061482476c72a5fc6fb2662b000d79b87fc1b --- lix/libcmd/command.cc | 6 +++--- lix/libcmd/command.hh | 12 ++++++------ lix/nix/config.cc | 2 +- lix/nix/derivation.cc | 2 +- lix/nix/main.cc | 4 ++-- lix/nix/nar.cc | 2 +- lix/nix/realisation.cc | 2 +- lix/nix/store.cc | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index fb3daedcf..1aace87bf 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -12,12 +12,12 @@ extern char * * environ __attribute__((weak)); namespace nix { -RegisterCommand::CommandMap * RegisterCommand::commands = nullptr; +CommandRegistry::CommandMap * CommandRegistry::commands = nullptr; -nix::CommandMap RegisterCommand::getCommandsFor(const std::vector & prefix) +nix::CommandMap CommandRegistry::getCommandsFor(const std::vector & prefix) { nix::CommandMap res; - for (auto & [name, command] : *RegisterCommand::commands) { + for (auto & [name, command] : *CommandRegistry::commands) { if (name.size() == prefix.size() + 1) { bool equal = true; for (size_t i = 0; i < prefix.size(); ++i) { diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index e6c910915..1578c0731 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -262,7 +262,7 @@ struct StorePathCommand : public StorePathsCommand /** * A helper class for registering \ref Command commands globally. */ -struct RegisterCommand +struct CommandRegistry { using CommandMap = std::map< std::vector, @@ -270,7 +270,7 @@ struct RegisterCommand >; static CommandMap * commands; - RegisterCommand(std::vector && name, + CommandRegistry(std::vector && name, std::function(AsyncIoRoot & aio)> command) { if (!commands) commands = new CommandMap; @@ -301,17 +301,17 @@ public: }; template -static RegisterCommand registerCommand(const std::string & name) +static CommandRegistry registerCommand(const std::string & name) { - return RegisterCommand({name}, [](AsyncIoRoot & aio) { + return CommandRegistry({name}, [](AsyncIoRoot & aio) { return make_ref>(aio); }); } template -static RegisterCommand registerCommand2(std::vector && name) +static CommandRegistry registerCommand2(std::vector && name) { - return RegisterCommand(std::move(name), [](AsyncIoRoot & aio) { + return CommandRegistry(std::move(name), [](AsyncIoRoot & aio) { return make_ref>(aio); }); } diff --git a/lix/nix/config.cc b/lix/nix/config.cc index 901422006..9ce4bf34c 100644 --- a/lix/nix/config.cc +++ b/lix/nix/config.cc @@ -9,7 +9,7 @@ using namespace nix; struct CmdConfig : MultiCommand { - CmdConfig() : MultiCommand(RegisterCommand::getCommandsFor({"config"})) + CmdConfig() : MultiCommand(CommandRegistry::getCommandsFor({"config"})) { } std::string description() override diff --git a/lix/nix/derivation.cc b/lix/nix/derivation.cc index a5620d076..a8394f075 100644 --- a/lix/nix/derivation.cc +++ b/lix/nix/derivation.cc @@ -4,7 +4,7 @@ using namespace nix; struct CmdDerivation : MultiCommand { - CmdDerivation() : MultiCommand(RegisterCommand::getCommandsFor({"derivation"})) + CmdDerivation() : MultiCommand(CommandRegistry::getCommandsFor({"derivation"})) { } std::string description() override diff --git a/lix/nix/main.cc b/lix/nix/main.cc index 053df9b01..5057671ac 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -114,7 +114,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs AsyncIoRoot & aio() override { return aio_; } NixArgs(const std::string & programName, AsyncIoRoot & aio) - : MultiCommand(RegisterCommand::getCommandsFor({}), true) + : MultiCommand(CommandRegistry::getCommandsFor({}), true) , MixCommonArgs(programName) , aio_(aio) { @@ -229,7 +229,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs // Plugins may add new subcommands. void pluginsInited() override { - commands = RegisterCommand::getCommandsFor({}); + commands = CommandRegistry::getCommandsFor({}); } std::string dumpCli() diff --git a/lix/nix/nar.cc b/lix/nix/nar.cc index 2061b0f1f..6aa798f0c 100644 --- a/lix/nix/nar.cc +++ b/lix/nix/nar.cc @@ -4,7 +4,7 @@ using namespace nix; struct CmdNar : MultiCommand { - CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"})) + CmdNar() : MultiCommand(CommandRegistry::getCommandsFor({"nar"})) { } std::string description() override diff --git a/lix/nix/realisation.cc b/lix/nix/realisation.cc index af13abbbe..73a727aa6 100644 --- a/lix/nix/realisation.cc +++ b/lix/nix/realisation.cc @@ -7,7 +7,7 @@ using namespace nix; struct CmdRealisation : MultiCommand { - CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"})) + CmdRealisation() : MultiCommand(CommandRegistry::getCommandsFor({"realisation"})) { } std::string description() override diff --git a/lix/nix/store.cc b/lix/nix/store.cc index ca9c4b961..9682b9ee0 100644 --- a/lix/nix/store.cc +++ b/lix/nix/store.cc @@ -4,7 +4,7 @@ using namespace nix; struct CmdStore : MultiCommand { - CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"})) + CmdStore() : MultiCommand(CommandRegistry::getCommandsFor({"store"})) { } std::string description() override From 4d9fe67430d6bff050668ff09a675ee2ed4454f1 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sun, 16 Mar 2025 15:52:27 -0700 Subject: [PATCH 2/2] Remove static initializers for `CommandRegistry` This removes static initializers for `nix` subcommands. cl/1905 made the same change but for legacy commands. See: #359 Change-Id: I23c99755719cef8e73fc720b685d4d1cf9b4ef15 --- lix/libcmd/command.cc | 3 + lix/libcmd/command.hh | 14 +-- lix/nix/add-to-store.cc | 12 ++- lix/nix/add-to-store.hh | 7 ++ lix/nix/build.cc | 10 +- lix/nix/build.hh | 7 ++ lix/nix/bundle.cc | 10 +- lix/nix/bundle.hh | 7 ++ lix/nix/cat.cc | 12 ++- lix/nix/cat.hh | 7 ++ lix/nix/config.cc | 12 ++- lix/nix/config.hh | 7 ++ lix/nix/copy.cc | 10 +- lix/nix/copy.hh | 7 ++ lix/nix/daemon.cc | 7 +- lix/nix/{daemon-command.hh => daemon.hh} | 1 + lix/nix/derivation-add.cc | 9 +- lix/nix/derivation-add.hh | 7 ++ lix/nix/derivation-show.cc | 9 +- lix/nix/derivation-show.hh | 7 ++ lix/nix/derivation.cc | 10 +- lix/nix/derivation.hh | 7 ++ lix/nix/develop.cc | 12 ++- lix/nix/develop.hh | 7 ++ lix/nix/diff-closures.cc | 9 +- lix/nix/diff-closures.hh | 7 ++ lix/nix/doctor.cc | 10 +- lix/nix/doctor.hh | 7 ++ lix/nix/dump-path.cc | 13 ++- lix/nix/dump-path.hh | 7 ++ lix/nix/edit.cc | 10 +- lix/nix/edit.hh | 7 ++ lix/nix/eval.cc | 10 +- lix/nix/eval.hh | 7 ++ lix/nix/flake.cc | 10 +- lix/nix/flake.hh | 7 ++ lix/nix/fmt.cc | 10 +- lix/nix/fmt.hh | 7 ++ lix/nix/hash.cc | 7 +- lix/nix/{hash-command.hh => hash.hh} | 1 + lix/nix/log.cc | 10 +- lix/nix/log.hh | 7 ++ lix/nix/ls.cc | 11 +- lix/nix/ls.hh | 7 ++ lix/nix/main.cc | 105 ++++++++++++++++++- lix/nix/make-content-addressed.cc | 10 +- lix/nix/make-content-addressed.hh | 7 ++ lix/nix/meson.build | 51 ++++++++- lix/nix/nar.cc | 10 +- lix/nix/nar.hh | 7 ++ lix/nix/optimise-store.cc | 10 +- lix/nix/optimise-store.hh | 7 ++ lix/nix/path-from-hash-part.cc | 10 +- lix/nix/path-from-hash-part.hh | 7 ++ lix/nix/path-info.cc | 10 +- lix/nix/path-info.hh | 7 ++ lix/nix/ping-store.cc | 10 +- lix/nix/ping-store.hh | 7 ++ lix/nix/prefetch.cc | 7 +- lix/nix/{prefetch-command.hh => prefetch.hh} | 1 + lix/nix/profile.cc | 10 +- lix/nix/profile.hh | 7 ++ lix/nix/realisation.cc | 13 ++- lix/nix/realisation.hh | 7 ++ lix/nix/registry.cc | 10 +- lix/nix/registry.hh | 7 ++ lix/nix/repl.cc | 6 +- lix/nix/repl.hh | 7 ++ lix/nix/run.cc | 8 +- lix/nix/run.hh | 2 + lix/nix/search.cc | 10 +- lix/nix/search.hh | 7 ++ lix/nix/sigs.cc | 16 +-- lix/nix/sigs.hh | 7 ++ lix/nix/store-copy-log.cc | 10 +- lix/nix/store-copy-log.hh | 7 ++ lix/nix/store-delete.cc | 10 +- lix/nix/store-delete.hh | 7 ++ lix/nix/store-gc.cc | 10 +- lix/nix/store-gc.hh | 7 ++ lix/nix/store-repair.cc | 10 +- lix/nix/store-repair.hh | 7 ++ lix/nix/store.cc | 10 +- lix/nix/store.hh | 7 ++ lix/nix/upgrade-nix.cc | 10 +- lix/nix/upgrade-nix.hh | 7 ++ lix/nix/verify.cc | 10 +- lix/nix/verify.hh | 7 ++ lix/nix/why-depends.cc | 10 +- lix/nix/why-depends.hh | 7 ++ 90 files changed, 770 insertions(+), 114 deletions(-) create mode 100644 lix/nix/add-to-store.hh create mode 100644 lix/nix/build.hh create mode 100644 lix/nix/bundle.hh create mode 100644 lix/nix/cat.hh create mode 100644 lix/nix/config.hh create mode 100644 lix/nix/copy.hh rename lix/nix/{daemon-command.hh => daemon.hh} (74%) create mode 100644 lix/nix/derivation-add.hh create mode 100644 lix/nix/derivation-show.hh create mode 100644 lix/nix/derivation.hh create mode 100644 lix/nix/develop.hh create mode 100644 lix/nix/diff-closures.hh create mode 100644 lix/nix/doctor.hh create mode 100644 lix/nix/dump-path.hh create mode 100644 lix/nix/edit.hh create mode 100644 lix/nix/eval.hh create mode 100644 lix/nix/flake.hh create mode 100644 lix/nix/fmt.hh rename lix/nix/{hash-command.hh => hash.hh} (75%) create mode 100644 lix/nix/log.hh create mode 100644 lix/nix/ls.hh create mode 100644 lix/nix/make-content-addressed.hh create mode 100644 lix/nix/nar.hh create mode 100644 lix/nix/optimise-store.hh create mode 100644 lix/nix/path-from-hash-part.hh create mode 100644 lix/nix/path-info.hh create mode 100644 lix/nix/ping-store.hh rename lix/nix/{prefetch-command.hh => prefetch.hh} (68%) create mode 100644 lix/nix/profile.hh create mode 100644 lix/nix/realisation.hh create mode 100644 lix/nix/registry.hh create mode 100644 lix/nix/repl.hh create mode 100644 lix/nix/search.hh create mode 100644 lix/nix/sigs.hh create mode 100644 lix/nix/store-copy-log.hh create mode 100644 lix/nix/store-delete.hh create mode 100644 lix/nix/store-gc.hh create mode 100644 lix/nix/store-repair.hh create mode 100644 lix/nix/store.hh create mode 100644 lix/nix/upgrade-nix.hh create mode 100644 lix/nix/verify.hh create mode 100644 lix/nix/why-depends.hh diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 1aace87bf..b2e94df8f 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -16,6 +16,9 @@ CommandRegistry::CommandMap * CommandRegistry::commands = nullptr; nix::CommandMap CommandRegistry::getCommandsFor(const std::vector & prefix) { + if (!CommandRegistry::commands) { + CommandRegistry::commands = new CommandMap; + } nix::CommandMap res; for (auto & [name, command] : *CommandRegistry::commands) { if (name.size() == prefix.size() + 1) { diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index 1578c0731..007a692f6 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -270,10 +270,12 @@ struct CommandRegistry >; static CommandMap * commands; - CommandRegistry(std::vector && name, + static void add(std::vector && name, std::function(AsyncIoRoot & aio)> command) { - if (!commands) commands = new CommandMap; + if (!commands) { + commands = new CommandMap; + } commands->emplace(name, command); } @@ -301,17 +303,17 @@ public: }; template -static CommandRegistry registerCommand(const std::string & name) +static void registerCommand(const std::string & name) { - return CommandRegistry({name}, [](AsyncIoRoot & aio) { + CommandRegistry::add({name}, [](AsyncIoRoot & aio) { return make_ref>(aio); }); } template -static CommandRegistry registerCommand2(std::vector && name) +static void registerCommand2(std::vector && name) { - return CommandRegistry(std::move(name), [](AsyncIoRoot & aio) { + CommandRegistry::add(std::move(name), [](AsyncIoRoot & aio) { return make_ref>(aio); }); } diff --git a/lix/nix/add-to-store.cc b/lix/nix/add-to-store.cc index f58e7fcba..4a082fdb1 100644 --- a/lix/nix/add-to-store.cc +++ b/lix/nix/add-to-store.cc @@ -3,8 +3,9 @@ #include "lix/libstore/store-api.hh" #include "lix/libutil/archive.hh" #include "lix/libutil/async-io.hh" +#include "add-to-store.hh" -using namespace nix; +namespace nix { struct CmdAddToStore : MixDryRun, StoreCommand { @@ -103,5 +104,10 @@ struct CmdAddPath : CmdAddToStore } }; -static auto rCmdAddFile = registerCommand2({"store", "add-file"}); -static auto rCmdAddPath = registerCommand2({"store", "add-path"}); +void registerNixStoreAdd() +{ + registerCommand2({"store", "add-file"}); + registerCommand2({"store", "add-path"}); +} + +} diff --git a/lix/nix/add-to-store.hh b/lix/nix/add-to-store.hh new file mode 100644 index 000000000..03b958b89 --- /dev/null +++ b/lix/nix/add-to-store.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreAdd(); + +} diff --git a/lix/nix/build.cc b/lix/nix/build.cc index 935d2351a..64da7e7f7 100644 --- a/lix/nix/build.cc +++ b/lix/nix/build.cc @@ -4,10 +4,11 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/local-fs-store.hh" #include "lix/libutil/async.hh" +#include "build.hh" #include -using namespace nix; +namespace nix { static nlohmann::json derivedPathsToJSON(AsyncIoRoot & aio, const DerivedPaths & paths, Store & store) { @@ -174,4 +175,9 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile } }; -static auto rCmdBuild = registerCommand("build"); +void registerNixBuild() +{ + registerCommand("build"); +} + +} diff --git a/lix/nix/build.hh b/lix/nix/build.hh new file mode 100644 index 000000000..cafc7f63b --- /dev/null +++ b/lix/nix/build.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixBuild(); + +} diff --git a/lix/nix/bundle.cc b/lix/nix/bundle.cc index 25cd89ab9..52a5f61d7 100644 --- a/lix/nix/bundle.cc +++ b/lix/nix/bundle.cc @@ -7,8 +7,9 @@ #include "lix/libstore/local-fs-store.hh" #include "lix/libstore/fs-accessor.hh" #include "lix/libexpr/eval-inline.hh" +#include "bundle.hh" -using namespace nix; +namespace nix { struct CmdBundle : InstallableCommand { @@ -135,4 +136,9 @@ struct CmdBundle : InstallableCommand } }; -static auto r2 = registerCommand("bundle"); +void registerNixBundle() +{ + registerCommand("bundle"); +} + +} diff --git a/lix/nix/bundle.hh b/lix/nix/bundle.hh new file mode 100644 index 000000000..60ea8ff90 --- /dev/null +++ b/lix/nix/bundle.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixBundle(); + +} diff --git a/lix/nix/cat.cc b/lix/nix/cat.cc index 032bd23c4..971ce2165 100644 --- a/lix/nix/cat.cc +++ b/lix/nix/cat.cc @@ -2,8 +2,9 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/fs-accessor.hh" #include "lix/libstore/nar-accessor.hh" +#include "cat.hh" -using namespace nix; +namespace nix { struct MixCat : virtual Args { @@ -85,5 +86,10 @@ struct CmdCatNar : StoreCommand, MixCat } }; -static auto rCmdCatStore = registerCommand2({"store", "cat"}); -static auto rCmdCatNar = registerCommand2({"nar", "cat"}); +void registerNixCat() +{ + registerCommand2({"store", "cat"}); + registerCommand2({"nar", "cat"}); +} + +} diff --git a/lix/nix/cat.hh b/lix/nix/cat.hh new file mode 100644 index 000000000..b59e2ce57 --- /dev/null +++ b/lix/nix/cat.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixCat(); + +} diff --git a/lix/nix/config.cc b/lix/nix/config.cc index 9ce4bf34c..f33901c2a 100644 --- a/lix/nix/config.cc +++ b/lix/nix/config.cc @@ -2,10 +2,11 @@ #include "lix/libmain/common-args.hh" #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" +#include "config.hh" #include -using namespace nix; +namespace nix { struct CmdConfig : MultiCommand { @@ -76,5 +77,10 @@ struct CmdConfigShow : Command, MixJSON } }; -static auto rCmdConfig = registerCommand("config"); -static auto rShowConfig = registerCommand2({"config", "show"}); +void registerNixConfig() +{ + registerCommand("config"); + registerCommand2({"config", "show"}); +} + +} diff --git a/lix/nix/config.hh b/lix/nix/config.hh new file mode 100644 index 000000000..945ad015d --- /dev/null +++ b/lix/nix/config.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixConfig(); + +} diff --git a/lix/nix/copy.cc b/lix/nix/copy.cc index 42b38fe81..5b70bf740 100644 --- a/lix/nix/copy.cc +++ b/lix/nix/copy.cc @@ -1,8 +1,9 @@ #include "lix/libcmd/command.hh" #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" +#include "copy.hh" -using namespace nix; +namespace nix { struct CmdCopy : virtual CopyCommand, BuiltPathsCommand { @@ -59,4 +60,9 @@ struct CmdCopy : virtual CopyCommand, BuiltPathsCommand } }; -static auto rCmdCopy = registerCommand("copy"); +void registerNixCopy() +{ + registerCommand("copy"); +} + +} diff --git a/lix/nix/copy.hh b/lix/nix/copy.hh new file mode 100644 index 000000000..0cd9e533f --- /dev/null +++ b/lix/nix/copy.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixCopy(); + +} diff --git a/lix/nix/daemon.cc b/lix/nix/daemon.cc index b401c68cd..c7ad6fdc4 100644 --- a/lix/nix/daemon.cc +++ b/lix/nix/daemon.cc @@ -14,7 +14,7 @@ #include "lix/libutil/signals.hh" #include "lix/libstore/daemon.hh" #include "lix/libutil/unix-domain-socket.hh" -#include "daemon-command.hh" +#include "daemon.hh" #include #include @@ -580,6 +580,9 @@ struct CmdDaemon : StoreCommand } }; -static auto rCmdDaemon = registerCommand2({"daemon"}); +void registerNixDaemon() +{ + registerCommand2({"daemon"}); +} } diff --git a/lix/nix/daemon-command.hh b/lix/nix/daemon.hh similarity index 74% rename from lix/nix/daemon-command.hh rename to lix/nix/daemon.hh index 6cce1298c..bf11b81d1 100644 --- a/lix/nix/daemon-command.hh +++ b/lix/nix/daemon.hh @@ -3,6 +3,7 @@ namespace nix { +void registerNixDaemon(); void registerLegacyNixDaemon(); } diff --git a/lix/nix/derivation-add.cc b/lix/nix/derivation-add.cc index 819d6ec63..336b3d53d 100644 --- a/lix/nix/derivation-add.cc +++ b/lix/nix/derivation-add.cc @@ -7,7 +7,7 @@ #include "lix/libstore/derivations.hh" #include -using namespace nix; +namespace nix { using json = nlohmann::json; struct CmdAddDerivation : MixDryRun, StoreCommand @@ -42,4 +42,9 @@ struct CmdAddDerivation : MixDryRun, StoreCommand } }; -static auto rCmdAddDerivation = registerCommand2({"derivation", "add"}); +void registerNixDerivationAdd() +{ + registerCommand2({"derivation", "add"}); +} + +} diff --git a/lix/nix/derivation-add.hh b/lix/nix/derivation-add.hh new file mode 100644 index 000000000..e725d713a --- /dev/null +++ b/lix/nix/derivation-add.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixDerivationAdd(); + +} diff --git a/lix/nix/derivation-show.cc b/lix/nix/derivation-show.cc index b6405e75f..e20cd2deb 100644 --- a/lix/nix/derivation-show.cc +++ b/lix/nix/derivation-show.cc @@ -8,7 +8,7 @@ #include "lix/libstore/derivations.hh" #include -using namespace nix; +namespace nix { using json = nlohmann::json; struct CmdShowDerivation : InstallablesCommand @@ -62,4 +62,9 @@ struct CmdShowDerivation : InstallablesCommand } }; -static auto rCmdShowDerivation = registerCommand2({"derivation", "show"}); +void registerNixDerivationShow() +{ + registerCommand2({"derivation", "show"}); +} + +} diff --git a/lix/nix/derivation-show.hh b/lix/nix/derivation-show.hh new file mode 100644 index 000000000..23c921c9e --- /dev/null +++ b/lix/nix/derivation-show.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixDerivationShow(); + +} diff --git a/lix/nix/derivation.cc b/lix/nix/derivation.cc index a8394f075..ca5da70e4 100644 --- a/lix/nix/derivation.cc +++ b/lix/nix/derivation.cc @@ -1,6 +1,7 @@ #include "lix/libcmd/command.hh" +#include "derivation.hh" -using namespace nix; +namespace nix { struct CmdDerivation : MultiCommand { @@ -22,4 +23,9 @@ struct CmdDerivation : MultiCommand } }; -static auto rCmdDerivation = registerCommand("derivation"); +void registerNixDerivation() +{ + registerCommand("derivation"); +} + +} diff --git a/lix/nix/derivation.hh b/lix/nix/derivation.hh new file mode 100644 index 000000000..a06b17c96 --- /dev/null +++ b/lix/nix/derivation.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixDerivation(); + +} diff --git a/lix/nix/develop.cc b/lix/nix/develop.cc index dcf261ad9..c280918c3 100644 --- a/lix/nix/develop.cc +++ b/lix/nix/develop.cc @@ -9,6 +9,7 @@ #include "lix/libutil/async.hh" #include "run.hh" #include "lix/libstore/temporary-dir.hh" +#include "develop.hh" #include #include @@ -16,7 +17,7 @@ #include #include -using namespace nix; +namespace nix { struct DevelopSettings : Config { @@ -703,5 +704,10 @@ struct CmdPrintDevEnv : Common, MixJSON } }; -static auto rCmdPrintDevEnv = registerCommand("print-dev-env"); -static auto rCmdDevelop = registerCommand("develop"); +void registerNixDevelop() +{ + registerCommand("print-dev-env"); + registerCommand("develop"); +} + +} diff --git a/lix/nix/develop.hh b/lix/nix/develop.hh new file mode 100644 index 000000000..70654c19c --- /dev/null +++ b/lix/nix/develop.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixDevelop(); + +} diff --git a/lix/nix/diff-closures.cc b/lix/nix/diff-closures.cc index d51fb1a75..592e6a180 100644 --- a/lix/nix/diff-closures.cc +++ b/lix/nix/diff-closures.cc @@ -5,6 +5,7 @@ #include "lix/libmain/common-args.hh" #include "lix/libstore/names.hh" #include "lix/libutil/result.hh" +#include "diff-closures.hh" #include #include @@ -184,7 +185,7 @@ try { } -using namespace nix; +namespace nix { struct CmdDiffClosures : SourceExprCommand, MixJSON, MixOperateOnOptions { @@ -219,4 +220,8 @@ struct CmdDiffClosures : SourceExprCommand, MixJSON, MixOperateOnOptions } }; -static auto rCmdDiffClosures = registerCommand2({"store", "diff-closures"}); +void registerNixStoreDiffClosures() { + registerCommand2({"store", "diff-closures"}); +} + +} diff --git a/lix/nix/diff-closures.hh b/lix/nix/diff-closures.hh new file mode 100644 index 000000000..299ab6b72 --- /dev/null +++ b/lix/nix/diff-closures.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreDiffClosures(); + +} diff --git a/lix/nix/doctor.cc b/lix/nix/doctor.cc index 55104828d..5d30fe360 100644 --- a/lix/nix/doctor.cc +++ b/lix/nix/doctor.cc @@ -8,8 +8,9 @@ #include "lix/libstore/local-fs-store.hh" #include "lix/libstore/worker-protocol.hh" #include "lix/libutil/exit.hh" +#include "doctor.hh" -using namespace nix; +namespace nix { namespace { @@ -152,4 +153,9 @@ struct CmdDoctor : StoreCommand } }; -static auto rCmdDoctor = registerCommand("doctor"); +void registerNixDoctor() +{ + registerCommand("doctor"); +} + +} diff --git a/lix/nix/doctor.hh b/lix/nix/doctor.hh new file mode 100644 index 000000000..36ae9b002 --- /dev/null +++ b/lix/nix/doctor.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixDoctor(); + +} diff --git a/lix/nix/dump-path.cc b/lix/nix/dump-path.cc index 33baef36e..879814e71 100644 --- a/lix/nix/dump-path.cc +++ b/lix/nix/dump-path.cc @@ -1,8 +1,9 @@ #include "lix/libcmd/command.hh" #include "lix/libstore/store-api.hh" #include "lix/libutil/archive.hh" +#include "dump-path.hh" -using namespace nix; +namespace nix { struct CmdDumpPath : StorePathCommand { @@ -27,8 +28,6 @@ struct CmdDumpPath : StorePathCommand } }; -static auto rDumpPath = registerCommand2({"store", "dump-path"}); - struct CmdDumpPath2 : Command { Path path; @@ -63,4 +62,10 @@ struct CmdDumpPath2 : Command } }; -static auto rDumpPath2 = registerCommand2({"nar", "dump-path"}); +void registerNixStoreDumpPath() +{ + registerCommand2({"store", "dump-path"}); + registerCommand2({"nar", "dump-path"}); +} + +} diff --git a/lix/nix/dump-path.hh b/lix/nix/dump-path.hh new file mode 100644 index 000000000..3cd2de6af --- /dev/null +++ b/lix/nix/dump-path.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreDumpPath(); + +} diff --git a/lix/nix/edit.cc b/lix/nix/edit.cc index 31e586f16..dcc9170eb 100644 --- a/lix/nix/edit.cc +++ b/lix/nix/edit.cc @@ -4,10 +4,11 @@ #include "lix/libexpr/attr-path.hh" #include "lix/libcmd/editor-for.hh" #include "lix/libutil/current-process.hh" +#include "edit.hh" #include -using namespace nix; +namespace nix { struct CmdEdit : InstallableCommand { @@ -56,4 +57,9 @@ struct CmdEdit : InstallableCommand } }; -static auto rCmdEdit = registerCommand("edit"); +void registerNixEdit() +{ + registerCommand("edit"); +} + +} diff --git a/lix/nix/edit.hh b/lix/nix/edit.hh new file mode 100644 index 000000000..5481978ae --- /dev/null +++ b/lix/nix/edit.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixEdit(); + +} diff --git a/lix/nix/eval.cc b/lix/nix/eval.cc index 919eacf4b..d08530c4a 100644 --- a/lix/nix/eval.cc +++ b/lix/nix/eval.cc @@ -6,10 +6,11 @@ #include "lix/libexpr/eval.hh" #include "lix/libexpr/eval-inline.hh" #include "lix/libexpr/value-to-json.hh" +#include "eval.hh" #include -using namespace nix; +namespace nix { struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption { @@ -139,4 +140,9 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption } }; -static auto rCmdEval = registerCommand("eval"); +void registerNixEval() +{ + registerCommand("eval"); +} + +} diff --git a/lix/nix/eval.hh b/lix/nix/eval.hh new file mode 100644 index 000000000..2a6227b07 --- /dev/null +++ b/lix/nix/eval.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixEval(); + +} diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index 39eda9a48..595a7ccdd 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -17,12 +17,13 @@ #include "lix/libcmd/markdown.hh" #include "lix/libutil/terminal.hh" #include "lix/libutil/signals.hh" +#include "flake.hh" #include #include #include -using namespace nix; +namespace nix { using namespace nix::flake; using json = nlohmann::json; @@ -1495,4 +1496,9 @@ struct CmdFlake : MultiCommand } }; -static auto rCmdFlake = registerCommand("flake"); +void registerNixFlake() +{ + registerCommand("flake"); +} + +} diff --git a/lix/nix/flake.hh b/lix/nix/flake.hh new file mode 100644 index 000000000..97ad4e109 --- /dev/null +++ b/lix/nix/flake.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixFlake(); + +} diff --git a/lix/nix/fmt.cc b/lix/nix/fmt.cc index 31759edd3..ef834c29e 100644 --- a/lix/nix/fmt.cc +++ b/lix/nix/fmt.cc @@ -1,8 +1,9 @@ #include "lix/libcmd/command.hh" #include "lix/libcmd/installable-value.hh" #include "run.hh" +#include "fmt.hh" -using namespace nix; +namespace nix { struct CmdFmt : SourceExprCommand { std::vector args; @@ -49,4 +50,9 @@ struct CmdFmt : SourceExprCommand { }; }; -static auto r2 = registerCommand("fmt"); +void registerNixFmt() +{ + registerCommand("fmt"); +} + +} diff --git a/lix/nix/fmt.hh b/lix/nix/fmt.hh new file mode 100644 index 000000000..522e19d1a --- /dev/null +++ b/lix/nix/fmt.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixFmt(); + +} diff --git a/lix/nix/hash.cc b/lix/nix/hash.cc index c5cde872e..6cb4a1573 100644 --- a/lix/nix/hash.cc +++ b/lix/nix/hash.cc @@ -5,7 +5,7 @@ #include "lix/libmain/shared.hh" #include "lix/libutil/references.hh" #include "lix/libutil/archive.hh" -#include "hash-command.hh" +#include "hash.hh" namespace nix { @@ -163,7 +163,10 @@ struct CmdHash : MultiCommand } }; -static auto rCmdHash = registerCommand("hash"); +void registerNixHash() +{ + registerCommand("hash"); +} /* Legacy nix-hash command. */ static int compatNixHash(AsyncIoRoot & aio, std::string programName, Strings argv) diff --git a/lix/nix/hash-command.hh b/lix/nix/hash.hh similarity index 75% rename from lix/nix/hash-command.hh rename to lix/nix/hash.hh index 2e1a8050f..b2afa3c47 100644 --- a/lix/nix/hash-command.hh +++ b/lix/nix/hash.hh @@ -4,5 +4,6 @@ namespace nix { void registerLegacyNixHash(); +void registerNixHash(); } diff --git a/lix/nix/log.cc b/lix/nix/log.cc index 64bb53f39..575e03261 100644 --- a/lix/nix/log.cc +++ b/lix/nix/log.cc @@ -3,8 +3,9 @@ #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" #include "lix/libstore/log-store.hh" +#include "log.hh" -using namespace nix; +namespace nix { struct CmdLog : InstallableCommand { @@ -64,4 +65,9 @@ struct CmdLog : InstallableCommand } }; -static auto rCmdLog = registerCommand("log"); +void registerNixLog() +{ + registerCommand("log"); +} + +} diff --git a/lix/nix/log.hh b/lix/nix/log.hh new file mode 100644 index 000000000..2204706a3 --- /dev/null +++ b/lix/nix/log.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixLog(); + +} diff --git a/lix/nix/ls.cc b/lix/nix/ls.cc index a748a6ce8..981e3f035 100644 --- a/lix/nix/ls.cc +++ b/lix/nix/ls.cc @@ -5,7 +5,7 @@ #include "lix/libmain/common-args.hh" #include -using namespace nix; +namespace nix { struct MixLs : virtual Args, MixJSON { @@ -160,5 +160,10 @@ struct CmdLsNar : Command, MixLs } }; -static auto rCmdLsStore = registerCommand2({"store", "ls"}); -static auto rCmdLsNar = registerCommand2({"nar", "ls"}); +void registerNixLs() +{ + registerCommand2({"store", "ls"}); + registerCommand2({"nar", "ls"}); +} + +} diff --git a/lix/nix/ls.hh b/lix/nix/ls.hh new file mode 100644 index 000000000..d3f6639c7 --- /dev/null +++ b/lix/nix/ls.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixLs(); + +} diff --git a/lix/nix/main.cc b/lix/nix/main.cc index 5057671ac..adbf7a55f 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -15,9 +15,30 @@ #include "lix/libcmd/markdown.hh" #include "lix/libutil/experimental-features-json.hh" #include "lix/libutil/deprecated-features-json.hh" +#include "add-to-store.hh" #include "build-remote.hh" -#include "daemon-command.hh" -#include "hash-command.hh" +#include "build.hh" +#include "bundle.hh" +#include "cat.hh" +#include "config.hh" +#include "copy.hh" +#include "daemon.hh" +#include "derivation-add.hh" +#include "derivation-show.hh" +#include "derivation.hh" +#include "develop.hh" +#include "diff-closures.hh" +#include "doctor.hh" +#include "dump-path.hh" +#include "edit.hh" +#include "eval.hh" +#include "flake.hh" +#include "fmt.hh" +#include "hash.hh" +#include "log.hh" +#include "ls.hh" +#include "make-content-addressed.hh" +#include "nar.hh" #include "nix-build.hh" #include "nix-channel.hh" #include "nix-collect-garbage.hh" @@ -25,8 +46,26 @@ #include "nix-env.hh" #include "nix-instantiate.hh" #include "nix-store.hh" -#include "prefetch-command.hh" +#include "optimise-store.hh" +#include "path-from-hash-part.hh" +#include "path-info.hh" +#include "ping-store.hh" +#include "prefetch.hh" +#include "profile.hh" +#include "realisation.hh" +#include "registry.hh" +#include "repl.hh" #include "run.hh" +#include "search.hh" +#include "sigs.hh" +#include "store-copy-log.hh" +#include "store-delete.hh" +#include "store-gc.hh" +#include "store-repair.hh" +#include "store.hh" +#include "upgrade-nix.hh" +#include "verify.hh" +#include "why-depends.hh" #include #include @@ -53,6 +92,58 @@ void registerLegacyCommands() registerLegacyNixHash(); } +void registerNixHelp(); + +void registerCommands() +{ + // keep-sorted start + registerNixBuild(); + registerNixBundle(); + registerNixCat(); + registerNixConfig(); + registerNixCopy(); + registerNixDaemon(); + registerNixDerivation(); + registerNixDerivationAdd(); + registerNixDerivationShow(); + registerNixDevelop(); + registerNixDoctor(); + registerNixEdit(); + registerNixEval(); + registerNixFlake(); + registerNixFmt(); + registerNixHash(); + registerNixHelp(); + registerNixLog(); + registerNixLs(); + registerNixMakeContentAddressed(); + registerNixNar(); + registerNixPathInfo(); + registerNixProfile(); + registerNixRealisation(); + registerNixRegistry(); + registerNixRepl(); + registerNixRun(); + registerNixSearch(); + registerNixSigs(); + registerNixStore(); + registerNixStoreAdd(); + registerNixStoreCopyLog(); + registerNixStoreDelete(); + registerNixStoreDiffClosures(); + registerNixStoreDumpPath(); + registerNixStoreGc(); + registerNixStoreOptimise(); + registerNixStorePathFromHashPart(); + registerNixStorePing(); + registerNixStorePrefetchFile(); + registerNixStoreRepair(); + registerNixStoreVerify(); + registerNixUpgradeNix(); + registerNixWhyDepends(); + // keep-sorted end +} + static bool haveProxyEnvironmentVariables() { static const std::vector proxyVariables = { @@ -326,7 +417,6 @@ struct CmdHelp : Command } }; -static auto rCmdHelp = registerCommand("help"); struct CmdHelpStores : Command { @@ -350,7 +440,11 @@ struct CmdHelpStores : Command } }; -static auto rCmdHelpStores = registerCommand("help-stores"); +void registerNixHelp() +{ + registerCommand("help"); + registerCommand("help-stores"); +} void mainWrapped(AsyncIoRoot & aio, int argc, char * * argv) { @@ -407,6 +501,7 @@ void mainWrapped(AsyncIoRoot & aio, int argc, char * * argv) verbosity = lvlInfo; } + registerCommands(); // NOTE: out of over-cautiousness for backward compatibility, // the program name had always been `nix` for a long time. // Only when we invoke it as `lix`, we should propagate `lix`. diff --git a/lix/nix/make-content-addressed.cc b/lix/nix/make-content-addressed.cc index 3acfea167..e158d0a99 100644 --- a/lix/nix/make-content-addressed.cc +++ b/lix/nix/make-content-addressed.cc @@ -2,10 +2,11 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/make-content-addressed.hh" #include "lix/libmain/common-args.hh" +#include "make-content-addressed.hh" #include -using namespace nix; +namespace nix { using nlohmann::json; @@ -57,4 +58,9 @@ struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand, } }; -static auto rCmdMakeContentAddressed = registerCommand2({"store", "make-content-addressed"}); +void registerNixMakeContentAddressed() +{ + registerCommand2({"store", "make-content-addressed"}); +} + +} diff --git a/lix/nix/make-content-addressed.hh b/lix/nix/make-content-addressed.hh new file mode 100644 index 000000000..60f778782 --- /dev/null +++ b/lix/nix/make-content-addressed.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixMakeContentAddressed(); + +} diff --git a/lix/nix/meson.build b/lix/nix/meson.build index 45fd6abb4..2d5d15669 100644 --- a/lix/nix/meson.build +++ b/lix/nix/meson.build @@ -60,11 +60,13 @@ nix_settings_headers += custom_target( ) nix_sources = files( + # keep-sorted start 'add-to-store.cc', 'app.cc', 'build.cc', 'bundle.cc', 'cat.cc', + 'config.cc', 'copy.cc', 'daemon.cc', 'derivation-add.cc', @@ -95,7 +97,6 @@ nix_sources = files( 'repl.cc', 'run.cc', 'search.cc', - 'config.cc', 'sigs.cc', 'store-copy-log.cc', 'store-delete.cc', @@ -105,12 +106,54 @@ nix_sources = files( 'upgrade-nix.cc', 'verify.cc', 'why-depends.cc', + # keep-sorted end ) nix_headers = files( - 'daemon-command.hh', - 'hash-command.hh', - 'prefetch-command.hh', + # keep-sorted start + 'add-to-store.hh', + 'build.hh', + 'bundle.hh', + 'cat.hh', + 'config.hh', + 'copy.hh', + 'daemon.hh', + 'derivation-add.hh', + 'derivation-show.hh', + 'derivation.hh', + 'develop.hh', + 'diff-closures.hh', + 'doctor.hh', + 'dump-path.hh', + 'edit.hh', + 'eval.hh', + 'flake.hh', + 'fmt.hh', + 'hash.hh', + 'log.hh', + 'ls.hh', + 'make-content-addressed.hh', + 'nar.hh', + 'optimise-store.hh', + 'path-from-hash-part.hh', + 'path-info.hh', + 'ping-store.hh', + 'prefetch.hh', + 'profile.hh', + 'realisation.hh', + 'registry.hh', + 'repl.hh', + 'search.hh', + 'sigs.hh', + 'store-copy-log.hh', + 'store-delete.hh', + 'store-gc.hh', + 'store-repair.hh', + 'store.hh', + 'upgrade-nix.hh', + 'verify.hh', + 'why-depends.hh', + # keep-sorted end ) nix = executable( diff --git a/lix/nix/nar.cc b/lix/nix/nar.cc index 6aa798f0c..4730b10b1 100644 --- a/lix/nix/nar.cc +++ b/lix/nix/nar.cc @@ -1,6 +1,7 @@ #include "lix/libcmd/command.hh" +#include "nar.hh" -using namespace nix; +namespace nix { struct CmdNar : MultiCommand { @@ -29,4 +30,9 @@ struct CmdNar : MultiCommand } }; -static auto rCmdNar = registerCommand("nar"); +void registerNixNar() +{ + registerCommand("nar"); +} + +} diff --git a/lix/nix/nar.hh b/lix/nix/nar.hh new file mode 100644 index 000000000..cc335646f --- /dev/null +++ b/lix/nix/nar.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixNar(); + +} diff --git a/lix/nix/optimise-store.cc b/lix/nix/optimise-store.cc index f2b236e6c..7d83cf0dd 100644 --- a/lix/nix/optimise-store.cc +++ b/lix/nix/optimise-store.cc @@ -2,10 +2,11 @@ #include "lix/libmain/shared.hh" #include "lix/libutil/signals.hh" #include "lix/libstore/store-api.hh" +#include "optimise-store.hh" #include -using namespace nix; +namespace nix { struct CmdOptimiseStore : StoreCommand { @@ -27,4 +28,9 @@ struct CmdOptimiseStore : StoreCommand } }; -static auto rCmdOptimiseStore = registerCommand2({"store", "optimise"}); +void registerNixStoreOptimise() +{ + registerCommand2({"store", "optimise"}); +} + +} diff --git a/lix/nix/optimise-store.hh b/lix/nix/optimise-store.hh new file mode 100644 index 000000000..5a55e393a --- /dev/null +++ b/lix/nix/optimise-store.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreOptimise(); + +} diff --git a/lix/nix/path-from-hash-part.cc b/lix/nix/path-from-hash-part.cc index 8e3f0b7be..7eda8a2c9 100644 --- a/lix/nix/path-from-hash-part.cc +++ b/lix/nix/path-from-hash-part.cc @@ -1,7 +1,8 @@ #include "lix/libcmd/command.hh" #include "lix/libstore/store-api.hh" +#include "path-from-hash-part.hh" -using namespace nix; +namespace nix { struct CmdPathFromHashPart : StoreCommand { @@ -36,4 +37,9 @@ struct CmdPathFromHashPart : StoreCommand } }; -static auto rCmdPathFromHashPart = registerCommand2({"store", "path-from-hash-part"}); +void registerNixStorePathFromHashPart() +{ + registerCommand2({"store", "path-from-hash-part"}); +} + +} diff --git a/lix/nix/path-from-hash-part.hh b/lix/nix/path-from-hash-part.hh new file mode 100644 index 000000000..574c4af32 --- /dev/null +++ b/lix/nix/path-from-hash-part.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStorePathFromHashPart(); + +} diff --git a/lix/nix/path-info.cc b/lix/nix/path-info.cc index 75283ce01..6ae313ef1 100644 --- a/lix/nix/path-info.cc +++ b/lix/nix/path-info.cc @@ -3,13 +3,14 @@ #include "lix/libstore/store-api.hh" #include "lix/libmain/common-args.hh" #include "lix/libutil/async.hh" +#include "path-info.hh" #include #include #include -using namespace nix; +namespace nix { struct CmdPathInfo : StorePathsCommand, MixJSON { @@ -131,4 +132,9 @@ struct CmdPathInfo : StorePathsCommand, MixJSON } }; -static auto rCmdPathInfo = registerCommand("path-info"); +void registerNixPathInfo() +{ + registerCommand("path-info"); +} + +} diff --git a/lix/nix/path-info.hh b/lix/nix/path-info.hh new file mode 100644 index 000000000..f318d7210 --- /dev/null +++ b/lix/nix/path-info.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixPathInfo(); + +} diff --git a/lix/nix/ping-store.cc b/lix/nix/ping-store.cc index 4b75a12a4..3e97b4b03 100644 --- a/lix/nix/ping-store.cc +++ b/lix/nix/ping-store.cc @@ -2,10 +2,11 @@ #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" #include "lix/libutil/finally.hh" +#include "ping-store.hh" #include -using namespace nix; +namespace nix { struct CmdPingStore : StoreCommand, MixJSON { @@ -46,4 +47,9 @@ struct CmdPingStore : StoreCommand, MixJSON } }; -static auto rCmdPingStore = registerCommand2({"store", "ping"}); +void registerNixStorePing() +{ + registerCommand2({"store", "ping"}); +} + +} diff --git a/lix/nix/ping-store.hh b/lix/nix/ping-store.hh new file mode 100644 index 000000000..d4446ec49 --- /dev/null +++ b/lix/nix/ping-store.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStorePing(); + +} diff --git a/lix/nix/prefetch.cc b/lix/nix/prefetch.cc index 3f7bae7f8..21746364f 100644 --- a/lix/nix/prefetch.cc +++ b/lix/nix/prefetch.cc @@ -11,7 +11,7 @@ #include "lix/libcmd/legacy.hh" #include "lix/libstore/temporary-dir.hh" #include "lix/libutil/terminal.hh" -#include "prefetch-command.hh" +#include "prefetch.hh" #include @@ -337,6 +337,9 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON } }; -static auto rCmdStorePrefetchFile = registerCommand2({"store", "prefetch-file"}); +void registerNixStorePrefetchFile() +{ + registerCommand2({"store", "prefetch-file"}); +} } diff --git a/lix/nix/prefetch-command.hh b/lix/nix/prefetch.hh similarity index 68% rename from lix/nix/prefetch-command.hh rename to lix/nix/prefetch.hh index 7a5e54de1..cf7281823 100644 --- a/lix/nix/prefetch-command.hh +++ b/lix/nix/prefetch.hh @@ -4,5 +4,6 @@ namespace nix { void registerLegacyNixPrefetchUrl(); +void registerNixStorePrefetchFile(); } diff --git a/lix/nix/profile.cc b/lix/nix/profile.cc index 98b163022..ea44ed178 100644 --- a/lix/nix/profile.cc +++ b/lix/nix/profile.cc @@ -11,12 +11,13 @@ #include "user-env.hh" #include "lix/libstore/profiles.hh" #include "lix/libstore/names.hh" +#include "profile.hh" #include #include #include -using namespace nix; +namespace nix { static std::map>> @@ -639,4 +640,9 @@ struct CmdProfile : MultiCommand } }; -static auto rCmdProfile = registerCommand("profile"); +void registerNixProfile() +{ + registerCommand("profile"); +} + +} diff --git a/lix/nix/profile.hh b/lix/nix/profile.hh new file mode 100644 index 000000000..b792bafe8 --- /dev/null +++ b/lix/nix/profile.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixProfile(); + +} diff --git a/lix/nix/realisation.cc b/lix/nix/realisation.cc index 73a727aa6..63df61459 100644 --- a/lix/nix/realisation.cc +++ b/lix/nix/realisation.cc @@ -1,9 +1,10 @@ #include "lix/libcmd/command.hh" #include "lix/libmain/common-args.hh" +#include "realisation.hh" #include -using namespace nix; +namespace nix { struct CmdRealisation : MultiCommand { @@ -25,8 +26,6 @@ struct CmdRealisation : MultiCommand } }; -static auto rCmdRealisation = registerCommand("realisation"); - struct CmdRealisationInfo : BuiltPathsCommand, MixJSON { CmdRealisationInfo() : BuiltPathsCommand(false) {} @@ -81,4 +80,10 @@ struct CmdRealisationInfo : BuiltPathsCommand, MixJSON } }; -static auto rCmdRealisationInfo = registerCommand2({"realisation", "info"}); +void registerNixRealisation() +{ + registerCommand("realisation"); + registerCommand2({"realisation", "info"}); +} + +} diff --git a/lix/nix/realisation.hh b/lix/nix/realisation.hh new file mode 100644 index 000000000..12f1bdb73 --- /dev/null +++ b/lix/nix/realisation.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixRealisation(); + +} diff --git a/lix/nix/registry.cc b/lix/nix/registry.cc index d0b0400c6..acf852c87 100644 --- a/lix/nix/registry.cc +++ b/lix/nix/registry.cc @@ -7,8 +7,9 @@ #include "lix/libfetchers/fetchers.hh" #include "lix/libutil/url-parts.hh" #include "lix/libfetchers/registry.hh" +#include "registry.hh" -using namespace nix; +namespace nix { using namespace nix::flake; @@ -240,4 +241,9 @@ struct CmdRegistry : MultiCommand } }; -static auto rCmdRegistry = registerCommand("registry"); +void registerNixRegistry() +{ + registerCommand("registry"); +} + +} diff --git a/lix/nix/registry.hh b/lix/nix/registry.hh new file mode 100644 index 000000000..db34e9565 --- /dev/null +++ b/lix/nix/registry.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixRegistry(); + +} diff --git a/lix/nix/repl.cc b/lix/nix/repl.cc index 466ffea6a..e10cda3a8 100644 --- a/lix/nix/repl.cc +++ b/lix/nix/repl.cc @@ -4,6 +4,7 @@ #include "lix/libcmd/command.hh" #include "lix/libcmd/installable-value.hh" #include "lix/libcmd/repl.hh" +#include "repl.hh" namespace nix { @@ -93,6 +94,9 @@ struct CmdRepl : RawInstallablesCommand } }; -static auto rCmdRepl = registerCommand("repl"); +void registerNixRepl() +{ + registerCommand("repl"); +} } diff --git a/lix/nix/repl.hh b/lix/nix/repl.hh new file mode 100644 index 000000000..90bccc5e4 --- /dev/null +++ b/lix/nix/repl.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixRepl(); + +} diff --git a/lix/nix/run.cc b/lix/nix/run.cc index 2953bdf91..ec9182b4e 100644 --- a/lix/nix/run.cc +++ b/lix/nix/run.cc @@ -153,8 +153,6 @@ struct CmdShell : InstallablesCommand, MixEnvironment } }; -static auto rCmdShell = registerCommand("shell"); - struct CmdRun : InstallableCommand { using InstallableCommand::run; @@ -219,7 +217,11 @@ struct CmdRun : InstallableCommand } }; -static auto rCmdRun = registerCommand("run"); +void registerNixRun() +{ + registerCommand("shell"); + registerCommand("run"); +} void chrootHelper(int argc, char * * argv) { diff --git a/lix/nix/run.hh b/lix/nix/run.hh index 3f1baf1bd..83b11070d 100644 --- a/lix/nix/run.hh +++ b/lix/nix/run.hh @@ -19,4 +19,6 @@ void runProgramInStore( std::optional system = std::nullopt ); +void registerNixRun(); + } diff --git a/lix/nix/search.cc b/lix/nix/search.cc index 1c84692f7..9cefef98d 100644 --- a/lix/nix/search.cc +++ b/lix/nix/search.cc @@ -10,12 +10,13 @@ #include "lix/libexpr/eval-cache.hh" #include "lix/libexpr/attr-path.hh" #include "lix/libutil/hilite.hh" +#include "search.hh" #include #include #include -using namespace nix; +namespace nix { using json = nlohmann::json; std::string wrap(std::string prefix, std::string s) @@ -203,4 +204,9 @@ struct CmdSearch : InstallableCommand, MixJSON } }; -static auto rCmdSearch = registerCommand("search"); +void registerNixSearch() +{ + registerCommand("search"); +} + +} diff --git a/lix/nix/search.hh b/lix/nix/search.hh new file mode 100644 index 000000000..4c1fc4fd9 --- /dev/null +++ b/lix/nix/search.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixSearch(); + +} diff --git a/lix/nix/sigs.cc b/lix/nix/sigs.cc index 7ab26a5c1..0c497e821 100644 --- a/lix/nix/sigs.cc +++ b/lix/nix/sigs.cc @@ -4,11 +4,12 @@ #include "lix/libutil/async.hh" #include "lix/libutil/thread-pool.hh" #include "lix/libutil/signals.hh" +#include "sigs.hh" #include #include -using namespace nix; +namespace nix { struct CmdCopySigs : StorePathsCommand { @@ -90,8 +91,6 @@ struct CmdCopySigs : StorePathsCommand } }; -static auto rCmdCopySigs = registerCommand2({"store", "copy-sigs"}); - struct CmdSign : StorePathsCommand { Path secretKeyFile; @@ -155,8 +154,6 @@ struct CmdSign : StorePathsCommand } }; -static auto rCmdSign = registerCommand2({"store", "sign"}); - struct CmdKeyGenerateSecret : Command { std::optional keyName; @@ -242,4 +239,11 @@ struct CmdKey : MultiCommand } }; -static auto rCmdKey = registerCommand("key"); +void registerNixSigs() +{ + registerCommand2({"store", "copy-sigs"}); + registerCommand2({"store", "sign"}); + registerCommand("key"); +} + +} diff --git a/lix/nix/sigs.hh b/lix/nix/sigs.hh new file mode 100644 index 000000000..e4146da28 --- /dev/null +++ b/lix/nix/sigs.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixSigs(); + +} diff --git a/lix/nix/store-copy-log.cc b/lix/nix/store-copy-log.cc index f91530f2a..47a3cda48 100644 --- a/lix/nix/store-copy-log.cc +++ b/lix/nix/store-copy-log.cc @@ -5,10 +5,11 @@ #include "lix/libstore/log-store.hh" #include "lix/libutil/sync.hh" #include "lix/libutil/thread-pool.hh" +#include "store-copy-log.hh" #include -using namespace nix; +namespace nix { struct CmdCopyLog : virtual CopyCommand, virtual InstallablesCommand { @@ -43,4 +44,9 @@ struct CmdCopyLog : virtual CopyCommand, virtual InstallablesCommand } }; -static auto rCmdCopyLog = registerCommand2({"store", "copy-log"}); +void registerNixStoreCopyLog() +{ + registerCommand2({"store", "copy-log"}); +} + +} diff --git a/lix/nix/store-copy-log.hh b/lix/nix/store-copy-log.hh new file mode 100644 index 000000000..53ad4db34 --- /dev/null +++ b/lix/nix/store-copy-log.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreCopyLog(); + +} diff --git a/lix/nix/store-delete.cc b/lix/nix/store-delete.cc index 4a4b59e3f..d2020f071 100644 --- a/lix/nix/store-delete.cc +++ b/lix/nix/store-delete.cc @@ -4,8 +4,9 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/store-cast.hh" #include "lix/libstore/gc-store.hh" +#include "store-delete.hh" -using namespace nix; +namespace nix { struct CmdStoreDelete : StorePathsCommand { @@ -62,4 +63,9 @@ struct CmdStoreDelete : StorePathsCommand } }; -static auto rCmdStoreDelete = registerCommand2({"store", "delete"}); +void registerNixStoreDelete() +{ + registerCommand2({"store", "delete"}); +} + +} diff --git a/lix/nix/store-delete.hh b/lix/nix/store-delete.hh new file mode 100644 index 000000000..40a67bcb7 --- /dev/null +++ b/lix/nix/store-delete.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreDelete(); + +} diff --git a/lix/nix/store-gc.cc b/lix/nix/store-gc.cc index 84ac29a5c..b66bc1628 100644 --- a/lix/nix/store-gc.cc +++ b/lix/nix/store-gc.cc @@ -4,8 +4,9 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/store-cast.hh" #include "lix/libstore/gc-store.hh" +#include "store-gc.hh" -using namespace nix; +namespace nix { struct CmdStoreGC : StoreCommand, MixDryRun { @@ -44,4 +45,9 @@ struct CmdStoreGC : StoreCommand, MixDryRun } }; -static auto rCmdStoreGC = registerCommand2({"store", "gc"}); +void registerNixStoreGc() +{ + registerCommand2({"store", "gc"}); +} + +} diff --git a/lix/nix/store-gc.hh b/lix/nix/store-gc.hh new file mode 100644 index 000000000..82ca55938 --- /dev/null +++ b/lix/nix/store-gc.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreGc(); + +} diff --git a/lix/nix/store-repair.cc b/lix/nix/store-repair.cc index c080cb866..04f3f2d5e 100644 --- a/lix/nix/store-repair.cc +++ b/lix/nix/store-repair.cc @@ -1,7 +1,8 @@ #include "lix/libcmd/command.hh" #include "lix/libstore/store-api.hh" +#include "store-repair.hh" -using namespace nix; +namespace nix { struct CmdStoreRepair : StorePathsCommand { @@ -24,4 +25,9 @@ struct CmdStoreRepair : StorePathsCommand } }; -static auto rStoreRepair = registerCommand2({"store", "repair"}); +void registerNixStoreRepair() +{ + registerCommand2({"store", "repair"}); +} + +} diff --git a/lix/nix/store-repair.hh b/lix/nix/store-repair.hh new file mode 100644 index 000000000..accc228d4 --- /dev/null +++ b/lix/nix/store-repair.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreRepair(); + +} diff --git a/lix/nix/store.cc b/lix/nix/store.cc index 9682b9ee0..b7d14fa52 100644 --- a/lix/nix/store.cc +++ b/lix/nix/store.cc @@ -1,6 +1,7 @@ #include "lix/libcmd/command.hh" +#include "store.hh" -using namespace nix; +namespace nix { struct CmdStore : MultiCommand { @@ -22,4 +23,9 @@ struct CmdStore : MultiCommand } }; -static auto rCmdStore = registerCommand("store"); +void registerNixStore() +{ + registerCommand("store"); +} + +} diff --git a/lix/nix/store.hh b/lix/nix/store.hh new file mode 100644 index 000000000..cee0089df --- /dev/null +++ b/lix/nix/store.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStore(); + +} diff --git a/lix/nix/upgrade-nix.cc b/lix/nix/upgrade-nix.cc index bcafa9e96..674f7ce35 100644 --- a/lix/nix/upgrade-nix.cc +++ b/lix/nix/upgrade-nix.cc @@ -13,8 +13,9 @@ #include "lix/libexpr/eval-settings.hh" #include "lix/libexpr/attr-path.hh" #include "lix/libstore/names.hh" +#include "upgrade-nix.hh" -using namespace nix; +namespace nix { struct CmdUpgradeNix : MixDryRun, EvalCommand { @@ -300,4 +301,9 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand } }; -static auto rCmdUpgradeNix = registerCommand("upgrade-nix"); +void registerNixUpgradeNix() +{ + registerCommand("upgrade-nix"); +} + +} diff --git a/lix/nix/upgrade-nix.hh b/lix/nix/upgrade-nix.hh new file mode 100644 index 000000000..7c74563f8 --- /dev/null +++ b/lix/nix/upgrade-nix.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixUpgradeNix(); + +} diff --git a/lix/nix/verify.cc b/lix/nix/verify.cc index 45a505233..727c197c3 100644 --- a/lix/nix/verify.cc +++ b/lix/nix/verify.cc @@ -5,11 +5,12 @@ #include "lix/libutil/thread-pool.hh" #include "lix/libutil/signals.hh" #include "lix/libutil/exit.hh" +#include "verify.hh" #include #include -using namespace nix; +namespace nix { struct CmdVerify : StorePathsCommand { @@ -186,4 +187,9 @@ struct CmdVerify : StorePathsCommand } }; -static auto rCmdVerify = registerCommand2({"store", "verify"}); +void registerNixStoreVerify() +{ + registerCommand2({"store", "verify"}); +} + +} diff --git a/lix/nix/verify.hh b/lix/nix/verify.hh new file mode 100644 index 000000000..e3527efd0 --- /dev/null +++ b/lix/nix/verify.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixStoreVerify(); + +} diff --git a/lix/nix/why-depends.cc b/lix/nix/why-depends.cc index 6c1853986..b699da4db 100644 --- a/lix/nix/why-depends.cc +++ b/lix/nix/why-depends.cc @@ -2,10 +2,11 @@ #include "lix/libstore/store-api.hh" #include "lix/libstore/fs-accessor.hh" #include "lix/libmain/shared.hh" +#include "why-depends.hh" #include -using namespace nix; +namespace nix { static std::string hilite(const std::string & s, size_t pos, size_t len, const std::string & colour = ANSI_RED) @@ -300,4 +301,9 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions } }; -static auto rCmdWhyDepends = registerCommand("why-depends"); +void registerNixWhyDepends() +{ + registerCommand("why-depends"); +} + +} diff --git a/lix/nix/why-depends.hh b/lix/nix/why-depends.hh new file mode 100644 index 000000000..cdd969990 --- /dev/null +++ b/lix/nix/why-depends.hh @@ -0,0 +1,7 @@ +#pragma once +/// @file +namespace nix { + +void registerNixWhyDepends(); + +}