aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-09-10 13:13:19 -0700
committerRebecca Turner <rbt@sent.as>2024-10-01 16:08:58 -0700
commitb63d4a0c622fa556695e7666b9b3bde920904920 (patch)
tree48f4df7f13c1908f943f45be0c6f5c9c56252d6a
parent775292766025380d04004e42fefbdb8ca40b3fa3 (diff)
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
-rw-r--r--src/legacy/build-remote.cc (renamed from src/build-remote/build-remote.cc)9
-rw-r--r--src/legacy/build-remote.hh8
-rw-r--r--src/legacy/buildenv.nix (renamed from src/nix-env/buildenv.nix)0
-rw-r--r--src/legacy/dotgraph.cc (renamed from src/nix-store/dotgraph.cc)0
-rw-r--r--src/legacy/dotgraph.hh (renamed from src/nix-store/dotgraph.hh)0
-rw-r--r--src/legacy/graphml.cc (renamed from src/nix-store/graphml.cc)0
-rw-r--r--src/legacy/graphml.hh (renamed from src/nix-store/graphml.hh)0
-rw-r--r--src/legacy/meson.build35
-rw-r--r--src/legacy/nix-build.cc (renamed from src/nix-build/nix-build.cc)16
-rw-r--r--src/legacy/nix-build.hh8
-rw-r--r--src/legacy/nix-channel.cc (renamed from src/nix-channel/nix-channel.cc)9
-rw-r--r--src/legacy/nix-channel.hh8
-rw-r--r--src/legacy/nix-collect-garbage.cc (renamed from src/nix-collect-garbage/nix-collect-garbage.cc)9
-rw-r--r--src/legacy/nix-collect-garbage.hh8
-rw-r--r--src/legacy/nix-copy-closure.cc (renamed from src/nix-copy-closure/nix-copy-closure.cc)9
-rw-r--r--src/legacy/nix-copy-closure.hh8
-rw-r--r--src/legacy/nix-env.cc (renamed from src/nix-env/nix-env.cc)10
-rw-r--r--src/legacy/nix-env.hh8
-rw-r--r--src/legacy/nix-instantiate.cc (renamed from src/nix-instantiate/nix-instantiate.cc)9
-rw-r--r--src/legacy/nix-instantiate.hh8
-rw-r--r--src/legacy/nix-store.cc (renamed from src/nix-store/nix-store.cc)8
-rw-r--r--src/legacy/nix-store.hh8
-rw-r--r--src/legacy/unpack-channel.nix (renamed from src/nix-channel/unpack-channel.nix)0
-rw-r--r--src/legacy/user-env.cc (renamed from src/nix-env/user-env.cc)0
-rw-r--r--src/legacy/user-env.hh (renamed from src/nix-env/user-env.hh)0
-rw-r--r--src/libcmd/legacy.cc2
-rw-r--r--src/libcmd/legacy.hh4
-rw-r--r--src/meson.build49
-rw-r--r--src/nix-channel/meson.build1
-rw-r--r--src/nix/daemon-command.hh8
-rw-r--r--src/nix/daemon.cc10
-rw-r--r--src/nix/hash-command.hh8
-rw-r--r--src/nix/hash.cc9
-rw-r--r--src/nix/main.cc30
-rw-r--r--src/nix/meson.build12
-rw-r--r--src/nix/prefetch-command.hh8
-rw-r--r--src/nix/prefetch.cc9
-rw-r--r--src/nix/profile.cc2
-rw-r--r--tests/functional/restricted.sh4
-rw-r--r--tests/unit/meson.build2
40 files changed, 253 insertions, 83 deletions
diff --git a/src/build-remote/build-remote.cc b/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
index c8955a94e..c8955a94e 100644
--- a/src/nix-env/buildenv.nix
+++ b/src/legacy/buildenv.nix
diff --git a/src/nix-store/dotgraph.cc b/src/legacy/dotgraph.cc
index 2c530999b..2c530999b 100644
--- a/src/nix-store/dotgraph.cc
+++ b/src/legacy/dotgraph.cc
diff --git a/src/nix-store/dotgraph.hh b/src/legacy/dotgraph.hh
index 4fd944080..4fd944080 100644
--- a/src/nix-store/dotgraph.hh
+++ b/src/legacy/dotgraph.hh
diff --git a/src/nix-store/graphml.cc b/src/legacy/graphml.cc
index 3e789a2d8..3e789a2d8 100644
--- a/src/nix-store/graphml.cc
+++ b/src/legacy/graphml.cc
diff --git a/src/nix-store/graphml.hh b/src/legacy/graphml.hh
index bd3a4a37c..bd3a4a37c 100644
--- a/src/nix-store/graphml.hh
+++ b/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
index 4b8d7a2fa..eb9b6cd8d 100644
--- a/src/nix-build/nix-build.cc
+++ b/src/legacy/nix-build.cc
@@ -24,11 +24,13 @@
#include "attr-path.hh"
#include "legacy.hh"
#include "shlex.hh"
+#include "nix-build.hh"
-using namespace nix;
-using namespace std::string_literals;
+extern char * * environ __attribute__((weak)); // Man what even is this
+
+namespace nix {
-extern char * * environ __attribute__((weak));
+using namespace std::string_literals;
static void main_nix_build(int argc, char * * argv)
{
@@ -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
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 <fcntl.h>
#include <regex>
#include <pwd.h>
-using namespace nix;
+namespace nix {
typedef std::map<std::string, std::string> 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
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 <iostream>
#include <cerrno>
-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
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
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 <ctime>
#include <algorithm>
@@ -28,9 +29,10 @@
#include <unistd.h>
#include <nlohmann/json.hpp>
-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
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 <map>
#include <iostream>
-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
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 <iostream>
#include <algorithm>
@@ -24,10 +25,9 @@
#include <fcntl.h>
-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
index 84e324a4d..84e324a4d 100644
--- a/src/nix-channel/unpack-channel.nix
+++ b/src/legacy/unpack-channel.nix
diff --git a/src/nix-env/user-env.cc b/src/legacy/user-env.cc
index f5dbd06ca..f5dbd06ca 100644
--- a/src/nix-env/user-env.cc
+++ b/src/legacy/user-env.cc
diff --git a/src/nix-env/user-env.hh b/src/legacy/user-env.hh
index af45d2d85..af45d2d85 100644
--- a/src/nix-env/user-env.hh
+++ b/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<void(int, char * *)> MainFunction;
-struct RegisterLegacyCommand
+struct LegacyCommands
{
typedef std::map<std::string, MainFunction> 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 <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"
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 <foo>')
nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in <foo>' -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)…