From b63d4a0c622fa556695e7666b9b3bde920904920 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 10 Sep 2024 13:13:19 -0700 Subject: [PATCH] Remove static initializers for `RegisterLegacyCommand` This moves the "legacy"/"nix2" commands under a new `src/legacy/` directory, instead of being scattered around in a bunch of different directories. A new `liblegacy` build target is defined, and the `nix` binary is linked against it. Then, `RegisterLegacyCommand` is replaced with `LegacyCommand::add` calls in functions like `registerNixCollectGarbage()`. These registration functions are called explicitly in `src/nix/main.cc`. See: https://git.lix.systems/lix-project/lix/issues/359 Change-Id: Id450ffc3f793374907599cfcc121863b792aac1a --- src/{build-remote => legacy}/build-remote.cc | 9 +++- src/legacy/build-remote.hh | 8 +++ src/{nix-env => legacy}/buildenv.nix | 0 src/{nix-store => legacy}/dotgraph.cc | 0 src/{nix-store => legacy}/dotgraph.hh | 0 src/{nix-store => legacy}/graphml.cc | 0 src/{nix-store => legacy}/graphml.hh | 0 src/legacy/meson.build | 35 +++++++++++++ src/{nix-build => legacy}/nix-build.cc | 16 ++++-- src/legacy/nix-build.hh | 8 +++ src/{nix-channel => legacy}/nix-channel.cc | 9 +++- src/legacy/nix-channel.hh | 8 +++ .../nix-collect-garbage.cc | 9 +++- src/legacy/nix-collect-garbage.hh | 8 +++ .../nix-copy-closure.cc | 9 +++- src/legacy/nix-copy-closure.hh | 8 +++ src/{nix-env => legacy}/nix-env.cc | 10 +++- src/legacy/nix-env.hh | 8 +++ .../nix-instantiate.cc | 9 +++- src/legacy/nix-instantiate.hh | 8 +++ src/{nix-store => legacy}/nix-store.cc | 8 +-- src/legacy/nix-store.hh | 8 +++ .../unpack-channel.nix | 0 src/{nix-env => legacy}/user-env.cc | 0 src/{nix-env => legacy}/user-env.hh | 0 src/libcmd/legacy.cc | 2 +- src/libcmd/legacy.hh | 4 +- src/meson.build | 49 +------------------ src/nix-channel/meson.build | 1 - src/nix/daemon-command.hh | 8 +++ src/nix/daemon.cc | 10 +++- src/nix/hash-command.hh | 8 +++ src/nix/hash.cc | 9 +++- src/nix/main.cc | 30 +++++++++++- src/nix/meson.build | 12 ++++- src/nix/prefetch-command.hh | 8 +++ src/nix/prefetch.cc | 9 +++- src/nix/profile.cc | 2 +- tests/functional/restricted.sh | 4 +- tests/unit/meson.build | 2 +- 40 files changed, 253 insertions(+), 83 deletions(-) rename src/{build-remote => legacy}/build-remote.cc (99%) create mode 100644 src/legacy/build-remote.hh rename src/{nix-env => legacy}/buildenv.nix (100%) rename src/{nix-store => legacy}/dotgraph.cc (100%) rename src/{nix-store => legacy}/dotgraph.hh (100%) rename src/{nix-store => legacy}/graphml.cc (100%) rename src/{nix-store => legacy}/graphml.hh (100%) create mode 100644 src/legacy/meson.build rename src/{nix-build => legacy}/nix-build.cc (98%) create mode 100644 src/legacy/nix-build.hh rename src/{nix-channel => legacy}/nix-channel.cc (98%) create mode 100644 src/legacy/nix-channel.hh rename src/{nix-collect-garbage => legacy}/nix-collect-garbage.cc (95%) create mode 100644 src/legacy/nix-collect-garbage.hh rename src/{nix-copy-closure => legacy}/nix-copy-closure.cc (93%) create mode 100644 src/legacy/nix-copy-closure.hh rename src/{nix-env => legacy}/nix-env.cc (99%) create mode 100644 src/legacy/nix-env.hh rename src/{nix-instantiate => legacy}/nix-instantiate.cc (97%) create mode 100644 src/legacy/nix-instantiate.hh rename src/{nix-store => legacy}/nix-store.cc (99%) create mode 100644 src/legacy/nix-store.hh rename src/{nix-channel => legacy}/unpack-channel.nix (100%) rename src/{nix-env => legacy}/user-env.cc (100%) rename src/{nix-env => legacy}/user-env.hh (100%) delete mode 100644 src/nix-channel/meson.build create mode 100644 src/nix/daemon-command.hh create mode 100644 src/nix/hash-command.hh create mode 100644 src/nix/prefetch-command.hh diff --git a/src/build-remote/build-remote.cc b/src/legacy/build-remote.cc similarity index 99% rename from src/build-remote/build-remote.cc rename to src/legacy/build-remote.cc index 3c7af067b..62ceef283 100644 --- a/src/build-remote/build-remote.cc +++ b/src/legacy/build-remote.cc @@ -19,8 +19,9 @@ #include "legacy.hh" #include "experimental-features.hh" #include "hash.hh" +#include "build-remote.hh" -using namespace nix; +namespace nix { static void handleAlarm(int sig) { } @@ -388,4 +389,8 @@ connected: } } -static RegisterLegacyCommand r_build_remote("build-remote", main_build_remote); +void registerBuildRemote() { + LegacyCommands::add("build-remote", main_build_remote); +} + +} diff --git a/src/legacy/build-remote.hh b/src/legacy/build-remote.hh new file mode 100644 index 000000000..c4a35f706 --- /dev/null +++ b/src/legacy/build-remote.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerBuildRemote(); + +} diff --git a/src/nix-env/buildenv.nix b/src/legacy/buildenv.nix similarity index 100% rename from src/nix-env/buildenv.nix rename to src/legacy/buildenv.nix diff --git a/src/nix-store/dotgraph.cc b/src/legacy/dotgraph.cc similarity index 100% rename from src/nix-store/dotgraph.cc rename to src/legacy/dotgraph.cc diff --git a/src/nix-store/dotgraph.hh b/src/legacy/dotgraph.hh similarity index 100% rename from src/nix-store/dotgraph.hh rename to src/legacy/dotgraph.hh diff --git a/src/nix-store/graphml.cc b/src/legacy/graphml.cc similarity index 100% rename from src/nix-store/graphml.cc rename to src/legacy/graphml.cc diff --git a/src/nix-store/graphml.hh b/src/legacy/graphml.hh similarity index 100% rename from src/nix-store/graphml.hh rename to src/legacy/graphml.hh diff --git a/src/legacy/meson.build b/src/legacy/meson.build new file mode 100644 index 000000000..13b90314c --- /dev/null +++ b/src/legacy/meson.build @@ -0,0 +1,35 @@ +legacy_include_directories = include_directories('.') + +legacy_sources = files( + # `build-remote` is not really legacy (it powers all remote builds), but it's + # not a `nix3` command. + 'build-remote.cc', + 'dotgraph.cc', + 'graphml.cc', + 'nix-build.cc', + 'nix-channel.cc', + 'nix-collect-garbage.cc', + 'nix-copy-closure.cc', + 'nix-env.cc', + 'nix-env.hh', + 'nix-instantiate.cc', + 'nix-store.cc', + 'user-env.cc', +) + +legacy_headers = files( + 'build-remote.hh', + 'nix-build.hh', + 'nix-channel.hh', + 'nix-collect-garbage.hh', + 'nix-copy-closure.hh', + 'nix-instantiate.hh', + 'nix-store.hh', +) + +legacy_generated_headers = [ + gen_header.process('buildenv.nix', preserve_path_from: meson.current_source_dir()), + gen_header.process('unpack-channel.nix', preserve_path_from: meson.current_source_dir()), +] + +fs.copyfile('unpack-channel.nix') diff --git a/src/nix-build/nix-build.cc b/src/legacy/nix-build.cc similarity index 98% rename from src/nix-build/nix-build.cc rename to src/legacy/nix-build.cc index 4b8d7a2fa..eb9b6cd8d 100644 --- a/src/nix-build/nix-build.cc +++ b/src/legacy/nix-build.cc @@ -24,12 +24,14 @@ #include "attr-path.hh" #include "legacy.hh" #include "shlex.hh" +#include "nix-build.hh" + +extern char * * environ __attribute__((weak)); // Man what even is this + +namespace nix { -using namespace nix; using namespace std::string_literals; -extern char * * environ __attribute__((weak)); - static void main_nix_build(int argc, char * * argv) { auto dryRun = false; @@ -613,5 +615,9 @@ static void main_nix_build(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_build("nix-build", main_nix_build); -static RegisterLegacyCommand r_nix_shell("nix-shell", main_nix_build); +void registerNixBuildAndNixShell() { + LegacyCommands::add("nix-build", main_nix_build); + LegacyCommands::add("nix-shell", main_nix_build); +} + +} diff --git a/src/legacy/nix-build.hh b/src/legacy/nix-build.hh new file mode 100644 index 000000000..945ac06e2 --- /dev/null +++ b/src/legacy/nix-build.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixBuildAndNixShell(); + +} diff --git a/src/nix-channel/nix-channel.cc b/src/legacy/nix-channel.cc similarity index 98% rename from src/nix-channel/nix-channel.cc rename to src/legacy/nix-channel.cc index 971337b63..2f79919dd 100644 --- a/src/nix-channel/nix-channel.cc +++ b/src/legacy/nix-channel.cc @@ -7,12 +7,13 @@ #include "fetchers.hh" #include "eval-settings.hh" // for defexpr #include "users.hh" +#include "nix-channel.hh" #include #include #include -using namespace nix; +namespace nix { typedef std::map Channels; @@ -264,4 +265,8 @@ static int main_nix_channel(int argc, char ** argv) } } -static RegisterLegacyCommand r_nix_channel("nix-channel", main_nix_channel); +void registerNixChannel() { + LegacyCommands::add("nix-channel", main_nix_channel); +} + +} diff --git a/src/legacy/nix-channel.hh b/src/legacy/nix-channel.hh new file mode 100644 index 000000000..f1583767f --- /dev/null +++ b/src/legacy/nix-channel.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixChannel(); + +} diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/legacy/nix-collect-garbage.cc similarity index 95% rename from src/nix-collect-garbage/nix-collect-garbage.cc rename to src/legacy/nix-collect-garbage.cc index c831f132f..7640100a0 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/legacy/nix-collect-garbage.cc @@ -7,11 +7,12 @@ #include "globals.hh" #include "legacy.hh" #include "signals.hh" +#include "nix-collect-garbage.hh" #include #include -using namespace nix; +namespace nix { std::string deleteOlderThan; bool dryRun = false; @@ -110,4 +111,8 @@ static int main_nix_collect_garbage(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_collect_garbage("nix-collect-garbage", main_nix_collect_garbage); +void registerNixCollectGarbage() { + LegacyCommands::add("nix-collect-garbage", main_nix_collect_garbage); +} + +} diff --git a/src/legacy/nix-collect-garbage.hh b/src/legacy/nix-collect-garbage.hh new file mode 100644 index 000000000..68515b537 --- /dev/null +++ b/src/legacy/nix-collect-garbage.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixCollectGarbage(); + +} diff --git a/src/nix-copy-closure/nix-copy-closure.cc b/src/legacy/nix-copy-closure.cc similarity index 93% rename from src/nix-copy-closure/nix-copy-closure.cc rename to src/legacy/nix-copy-closure.cc index 7f2bb93b6..1e61e3c48 100644 --- a/src/nix-copy-closure/nix-copy-closure.cc +++ b/src/legacy/nix-copy-closure.cc @@ -1,8 +1,9 @@ #include "shared.hh" #include "store-api.hh" #include "legacy.hh" +#include "nix-copy-closure.hh" -using namespace nix; +namespace nix { static int main_nix_copy_closure(int argc, char ** argv) { @@ -60,4 +61,8 @@ static int main_nix_copy_closure(int argc, char ** argv) } } -static RegisterLegacyCommand r_nix_copy_closure("nix-copy-closure", main_nix_copy_closure); +void registerNixCopyClosure() { + LegacyCommands::add("nix-copy-closure", main_nix_copy_closure); +} + +} diff --git a/src/legacy/nix-copy-closure.hh b/src/legacy/nix-copy-closure.hh new file mode 100644 index 000000000..fb5d0fc6e --- /dev/null +++ b/src/legacy/nix-copy-closure.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixCopyClosure(); + +} diff --git a/src/nix-env/nix-env.cc b/src/legacy/nix-env.cc similarity index 99% rename from src/nix-env/nix-env.cc rename to src/legacy/nix-env.cc index 13fadb1d8..4674fd783 100644 --- a/src/nix-env/nix-env.cc +++ b/src/legacy/nix-env.cc @@ -17,6 +17,7 @@ #include "xml-writer.hh" #include "legacy.hh" #include "eval-settings.hh" // for defexpr +#include "nix-env.hh" #include #include @@ -28,9 +29,10 @@ #include #include -using namespace nix; using std::cout; +namespace nix { + typedef enum { srcNixExprDrvs, @@ -1544,4 +1546,8 @@ static int main_nix_env(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_env("nix-env", main_nix_env); +void registerNixEnv() { + LegacyCommands::add("nix-env", main_nix_env); +} + +} diff --git a/src/legacy/nix-env.hh b/src/legacy/nix-env.hh new file mode 100644 index 000000000..47d62b8e6 --- /dev/null +++ b/src/legacy/nix-env.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixEnv(); + +} diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/legacy/nix-instantiate.cc similarity index 97% rename from src/nix-instantiate/nix-instantiate.cc rename to src/legacy/nix-instantiate.cc index 7487af1c1..5d1da0d70 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/legacy/nix-instantiate.cc @@ -11,12 +11,13 @@ #include "local-fs-store.hh" #include "common-eval-args.hh" #include "legacy.hh" +#include "nix-instantiate.hh" #include #include -using namespace nix; +namespace nix { static Path gcRoot; @@ -195,4 +196,8 @@ static int main_nix_instantiate(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_instantiate("nix-instantiate", main_nix_instantiate); +void registerNixInstantiate() { + LegacyCommands::add("nix-instantiate", main_nix_instantiate); +} + +} diff --git a/src/legacy/nix-instantiate.hh b/src/legacy/nix-instantiate.hh new file mode 100644 index 000000000..f4c35a6b5 --- /dev/null +++ b/src/legacy/nix-instantiate.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixInstantiate(); + +} diff --git a/src/nix-store/nix-store.cc b/src/legacy/nix-store.cc similarity index 99% rename from src/nix-store/nix-store.cc rename to src/legacy/nix-store.cc index bc43aa7b1..e42aa4065 100644 --- a/src/nix-store/nix-store.cc +++ b/src/legacy/nix-store.cc @@ -15,6 +15,7 @@ #include "graphml.hh" #include "legacy.hh" #include "path-with-outputs.hh" +#include "nix-store.hh" #include #include @@ -24,10 +25,9 @@ #include -namespace nix_store { +namespace nix { -using namespace nix; using std::cin; using std::cout; @@ -1176,6 +1176,8 @@ static int main_nix_store(int argc, char * * argv) } } -static RegisterLegacyCommand r_nix_store("nix-store", main_nix_store); +void registerNixStore() { + LegacyCommands::add("nix-store", main_nix_store); +} } diff --git a/src/legacy/nix-store.hh b/src/legacy/nix-store.hh new file mode 100644 index 000000000..b010e7b19 --- /dev/null +++ b/src/legacy/nix-store.hh @@ -0,0 +1,8 @@ +#pragma once +/// @file + +namespace nix { + +void registerNixStore(); + +} diff --git a/src/nix-channel/unpack-channel.nix b/src/legacy/unpack-channel.nix similarity index 100% rename from src/nix-channel/unpack-channel.nix rename to src/legacy/unpack-channel.nix diff --git a/src/nix-env/user-env.cc b/src/legacy/user-env.cc similarity index 100% rename from src/nix-env/user-env.cc rename to src/legacy/user-env.cc diff --git a/src/nix-env/user-env.hh b/src/legacy/user-env.hh similarity index 100% rename from src/nix-env/user-env.hh rename to src/legacy/user-env.hh diff --git a/src/libcmd/legacy.cc b/src/libcmd/legacy.cc index 6df09ee37..8bbe9b031 100644 --- a/src/libcmd/legacy.cc +++ b/src/libcmd/legacy.cc @@ -2,6 +2,6 @@ namespace nix { -RegisterLegacyCommand::Commands * RegisterLegacyCommand::commands = 0; +LegacyCommands::Commands * LegacyCommands::commands = 0; } diff --git a/src/libcmd/legacy.hh b/src/libcmd/legacy.hh index 357500a4d..45a231983 100644 --- a/src/libcmd/legacy.hh +++ b/src/libcmd/legacy.hh @@ -9,12 +9,12 @@ namespace nix { typedef std::function MainFunction; -struct RegisterLegacyCommand +struct LegacyCommands { typedef std::map Commands; static Commands * commands; - RegisterLegacyCommand(const std::string & name, MainFunction fun) + static void add(const std::string & name, MainFunction fun) { if (!commands) commands = new Commands; (*commands)[name] = fun; diff --git a/src/meson.build b/src/meson.build index 66fbb13ba..8b63ef995 100644 --- a/src/meson.build +++ b/src/meson.build @@ -26,54 +26,9 @@ libasanoptions = declare_dependency( link_whole: asanoptions ) -build_remote_sources = files( - 'build-remote/build-remote.cc', -) -nix_build_sources = files( - 'nix-build/nix-build.cc', -) -nix_channel_sources = files( - 'nix-channel/nix-channel.cc', -) -unpack_channel_gen = gen_header.process('nix-channel/unpack-channel.nix') -nix_collect_garbage_sources = files( - 'nix-collect-garbage/nix-collect-garbage.cc', -) -nix_copy_closure_sources = files( - 'nix-copy-closure/nix-copy-closure.cc', -) -nix_env_buildenv_gen = gen_header.process('nix-env/buildenv.nix') -nix_env_sources = files( - 'nix-env/nix-env.cc', - 'nix-env/user-env.cc', -) -nix_instantiate_sources = files( - 'nix-instantiate/nix-instantiate.cc', -) -nix_store_sources = files( - 'nix-store/dotgraph.cc', - 'nix-store/graphml.cc', - 'nix-store/nix-store.cc', -) - -# Hurray for Meson list flattening! -nix2_commands_sources = [ - build_remote_sources, - nix_build_sources, - nix_channel_sources, - unpack_channel_gen, - nix_collect_garbage_sources, - nix_copy_closure_sources, - nix_env_buildenv_gen, - nix_env_sources, - nix_instantiate_sources, - nix_store_sources, -] +# Legacy commands. +subdir('legacy') # Finally, the nix command itself, which all of the other commands are implmented in terms of # as a multicall binary. subdir('nix') - -# Just copies nix-channel/unpack-channel.nix to the build directory. -# Done as a subdir to get Meson to respect the path hierarchy. -subdir('nix-channel') diff --git a/src/nix-channel/meson.build b/src/nix-channel/meson.build deleted file mode 100644 index 97b92d789..000000000 --- a/src/nix-channel/meson.build +++ /dev/null @@ -1 +0,0 @@ -fs.copyfile('unpack-channel.nix') 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 #include @@ -36,7 +37,8 @@ #include #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({"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 #include @@ -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 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 -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({"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" diff --git a/tests/functional/restricted.sh b/tests/functional/restricted.sh index 450674bd6..dd6386278 100644 --- a/tests/functional/restricted.sh +++ b/tests/functional/restricted.sh @@ -11,8 +11,8 @@ nix-instantiate --restrict-eval ./simple.nix -I src1=simple.nix -I src2=config.n (! nix-instantiate --restrict-eval --eval -E 'builtins.readFile ./simple.nix') nix-instantiate --restrict-eval --eval -E 'builtins.readFile ./simple.nix' -I src=../.. -(! nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../../src/nix-channel') -nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../../src/nix-channel' -I src=../../src +(! nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../../src/legacy') +nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../../src/legacy' -I src=../../src (! nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in ') nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in ' -I src=. diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 8b0c66dd8..c831ba379 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -255,7 +255,7 @@ test( env : default_test_env + { # No special meaning here, it's just a file laying around that is unlikely to go anywhere # any time soon. - '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'src/nix-env/buildenv.nix', + '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'src/legacy/buildenv.nix', # Use a temporary home directory for the unit tests. # Otherwise, /homeless-shelter is created in the single-user sandbox, and functional tests will fail. # TODO(alois31): handle TMPDIR properly (meson can't, and setting HOME in the test is too late)…