diff options
author | jade <lix@jade.fyi> | 2024-10-09 20:37:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@localhost> | 2024-10-09 20:37:58 +0000 |
commit | 9865ebaaa618d82a7b7fdccc636cbaa7dfa42427 (patch) | |
tree | b79db30394a892e7e6b7e0a2f966081b4a366590 /src/nix | |
parent | 7f7a38f2788ba7fa46cf38127f525700cf63e153 (diff) | |
parent | b63d4a0c622fa556695e7666b9b3bde920904920 (diff) |
Merge "Remove static initializers for `RegisterLegacyCommand`" into main
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/daemon-command.hh | 8 | ||||
-rw-r--r-- | src/nix/daemon.cc | 10 | ||||
-rw-r--r-- | src/nix/hash-command.hh | 8 | ||||
-rw-r--r-- | src/nix/hash.cc | 9 | ||||
-rw-r--r-- | src/nix/main.cc | 30 | ||||
-rw-r--r-- | src/nix/meson.build | 12 | ||||
-rw-r--r-- | src/nix/prefetch-command.hh | 8 | ||||
-rw-r--r-- | src/nix/prefetch.cc | 9 | ||||
-rw-r--r-- | src/nix/profile.cc | 2 |
9 files changed, 87 insertions, 9 deletions
diff --git a/src/nix/daemon-command.hh b/src/nix/daemon-command.hh new file mode 100644 index 000000000..454af88e2 --- /dev/null +++ b/src/nix/daemon-command.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixDaemon(); + +} diff --git a/src/nix/daemon.cc b/src/nix/daemon.cc index ca65c38e6..e1d183d7b 100644 --- a/src/nix/daemon.cc +++ b/src/nix/daemon.cc @@ -14,6 +14,7 @@ #include "signals.hh" #include "daemon.hh" #include "unix-domain-socket.hh" +#include "daemon-command.hh" #include <algorithm> #include <climits> @@ -36,7 +37,8 @@ #include <sys/ucred.h> #endif -using namespace nix; +namespace nix { + using namespace nix::daemon; /** @@ -496,7 +498,9 @@ static int main_nix_daemon(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_daemon("nix-daemon", main_nix_daemon); +void registerNixDaemon() { + LegacyCommands::add("nix-daemon", main_nix_daemon); +} struct CmdDaemon : StoreCommand { @@ -560,3 +564,5 @@ struct CmdDaemon : StoreCommand }; static auto rCmdDaemon = registerCommand2<CmdDaemon>({"daemon"}); + +} diff --git a/src/nix/hash-command.hh b/src/nix/hash-command.hh new file mode 100644 index 000000000..5383171a5 --- /dev/null +++ b/src/nix/hash-command.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixHash(); + +} diff --git a/src/nix/hash.cc b/src/nix/hash.cc index f6add527a..40b00c978 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -5,8 +5,9 @@ #include "shared.hh" #include "references.hh" #include "archive.hh" +#include "hash-command.hh" -using namespace nix; +namespace nix { struct CmdHashBase : Command { @@ -221,4 +222,8 @@ static int compatNixHash(int argc, char * * argv) return 0; } -static RegisterLegacyCommand r_nix_hash("nix-hash", compatNixHash); +void registerNixHash() { + LegacyCommands::add("nix-hash", compatNixHash); +} + +} diff --git a/src/nix/main.cc b/src/nix/main.cc index 4a3a7b4e7..fdd3ac2ae 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -15,6 +15,17 @@ #include "markdown.hh" #include "experimental-features-json.hh" #include "deprecated-features-json.hh" +#include "build-remote.hh" +#include "daemon-command.hh" +#include "hash-command.hh" +#include "nix-build.hh" +#include "nix-channel.hh" +#include "nix-collect-garbage.hh" +#include "nix-copy-closure.hh" +#include "nix-env.hh" +#include "nix-instantiate.hh" +#include "nix-store.hh" +#include "prefetch-command.hh" #include <sys/types.h> #include <sys/socket.h> @@ -30,6 +41,21 @@ void chrootHelper(int argc, char * * argv); namespace nix { +void registerLegacyCommands() +{ + registerNixEnv(); + registerNixBuildAndNixShell(); + registerNixInstantiate(); + registerNixCopyClosure(); + registerNixCollectGarbage(); + registerNixChannel(); + registerNixStore(); + registerBuildRemote(); + registerNixDaemon(); + registerNixPrefetchUrl(); + registerNixHash(); +} + static bool haveProxyEnvironmentVariables() { static const std::vector<std::string> proxyVariables = { @@ -356,8 +382,10 @@ void mainWrapped(int argc, char * * argv) // Clean up the progress bar if shown using --log-format in a legacy command too. // Otherwise, this is a harmless no-op. Finally f([] { logger->pause(); }); + { - auto legacy = (*RegisterLegacyCommand::commands)[programName]; + registerLegacyCommands(); + auto legacy = (*LegacyCommands::commands)[programName]; if (legacy) return legacy(argc, argv); } diff --git a/src/nix/meson.build b/src/nix/meson.build index 80223a390..cabdf0d2c 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -71,11 +71,21 @@ nix_sources = files( 'why-depends.cc', ) +nix_headers = files( + 'daemon-command.hh', + 'hash-command.hh', + 'prefetch-command.hh', +) + nix = executable( 'nix', nix_sources, + legacy_sources, nix_generated_headers, - nix2_commands_sources, + nix_headers, + legacy_headers, + legacy_generated_headers, + include_directories : legacy_include_directories, dependencies : [ libasanoptions, liblixcmd, diff --git a/src/nix/prefetch-command.hh b/src/nix/prefetch-command.hh new file mode 100644 index 000000000..078e83485 --- /dev/null +++ b/src/nix/prefetch-command.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixPrefetchUrl(); + +} diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index b99cd5dd0..0183b0008 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -9,10 +9,11 @@ #include "eval-inline.hh" // IWYU pragma: keep #include "legacy.hh" #include "terminal.hh" +#include "prefetch-command.hh" #include <nlohmann/json.hpp> -using namespace nix; +namespace nix { /* If ‘url’ starts with ‘mirror://’, then resolve it using the list of mirrors defined in Nixpkgs. */ @@ -248,7 +249,9 @@ static int main_nix_prefetch_url(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_prefetch_url("nix-prefetch-url", main_nix_prefetch_url); +void registerNixPrefetchUrl() { + LegacyCommands::add("nix-prefetch-url", main_nix_prefetch_url); +} struct CmdStorePrefetchFile : StoreCommand, MixJSON { @@ -328,3 +331,5 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON }; static auto rCmdStorePrefetchFile = registerCommand2<CmdStorePrefetchFile>({"store", "prefetch-file"}); + +} diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 401d5bd77..6739cb5c6 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -8,7 +8,7 @@ #include "archive.hh" #include "builtins/buildenv.hh" #include "flake/flakeref.hh" -#include "../nix-env/user-env.hh" +#include "user-env.hh" #include "profiles.hh" #include "names.hh" |