aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/daemon-command.hh8
-rw-r--r--src/nix/daemon.cc10
-rw-r--r--src/nix/develop.cc2
-rw-r--r--src/nix/flake.cc5
-rw-r--r--src/nix/fmt.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
12 files changed, 94 insertions, 19 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/develop.cc b/src/nix/develop.cc
index fb144c904..d1615ecdc 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -639,7 +639,7 @@ struct CmdDevelop : Common, MixEnvironment
throw Error("package 'nixpkgs#bashInteractive' does not provide a 'bin/bash'");
} catch (Error &) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
}
// Override SHELL with the one chosen for this environment.
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 15c393c90..0c704a995 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -16,6 +16,7 @@
#include "eval-cache.hh"
#include "markdown.hh"
#include "terminal.hh"
+#include "signals.hh"
#include <limits>
#include <nlohmann/json.hpp>
@@ -367,9 +368,11 @@ struct CmdFlakeCheck : FlakeCommand
auto reportError = [&](const Error & e) {
try {
throw e;
+ } catch (Interrupted & e) {
+ throw;
} catch (Error & e) {
if (settings.keepGoing) {
- ignoreException();
+ ignoreExceptionExceptInterrupt();
hasErrors = true;
}
else
diff --git a/src/nix/fmt.cc b/src/nix/fmt.cc
index 059904150..f47f2204a 100644
--- a/src/nix/fmt.cc
+++ b/src/nix/fmt.cc
@@ -39,14 +39,8 @@ struct CmdFmt : SourceExprCommand {
Strings programArgs{app.program};
// Propagate arguments from the CLI
- if (args.empty()) {
- // Format the current flake out of the box
- programArgs.push_back(".");
- } else {
- // User wants more power, let them decide which paths to include/exclude
- for (auto &i : args) {
- programArgs.push_back(i);
- }
+ for (auto &i : args) {
+ programArgs.push_back(i);
}
runProgramInStore(store, UseSearchPath::DontUse, app.program, programArgs);
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"