Merge changes I23c99755,I45306148 into main

* changes:
  Remove static initializers for `CommandRegistry`
  RegisterCommand -> CommandRegistry
This commit is contained in:
rebecca “wiggles” turner
2025-03-18 18:17:03 +00:00
committed by Lix Systems Gerrit
90 changed files with 781 additions and 125 deletions
+6 -3
View File
@@ -12,12 +12,15 @@ extern char * * environ __attribute__((weak));
namespace nix {
RegisterCommand::CommandMap * RegisterCommand::commands = nullptr;
CommandRegistry::CommandMap * CommandRegistry::commands = nullptr;
nix::CommandMap RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
nix::CommandMap CommandRegistry::getCommandsFor(const std::vector<std::string> & prefix)
{
if (!CommandRegistry::commands) {
CommandRegistry::commands = new CommandMap;
}
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) {
+9 -7
View File
@@ -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<std::string>,
@@ -270,10 +270,12 @@ struct RegisterCommand
>;
static CommandMap * commands;
RegisterCommand(std::vector<std::string> && name,
static void add(std::vector<std::string> && name,
std::function<ref<Command>(AsyncIoRoot & aio)> command)
{
if (!commands) commands = new CommandMap;
if (!commands) {
commands = new CommandMap;
}
commands->emplace(name, command);
}
@@ -301,17 +303,17 @@ public:
};
template<class T>
static RegisterCommand registerCommand(const std::string & name)
static void registerCommand(const std::string & name)
{
return RegisterCommand({name}, [](AsyncIoRoot & aio) {
CommandRegistry::add({name}, [](AsyncIoRoot & aio) {
return make_ref<MixAio<T>>(aio);
});
}
template<class T>
static RegisterCommand registerCommand2(std::vector<std::string> && name)
static void registerCommand2(std::vector<std::string> && name)
{
return RegisterCommand(std::move(name), [](AsyncIoRoot & aio) {
CommandRegistry::add(std::move(name), [](AsyncIoRoot & aio) {
return make_ref<MixAio<T>>(aio);
});
}
+9 -3
View File
@@ -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<CmdAddFile>({"store", "add-file"});
static auto rCmdAddPath = registerCommand2<CmdAddPath>({"store", "add-path"});
void registerNixStoreAdd()
{
registerCommand2<CmdAddFile>({"store", "add-file"});
registerCommand2<CmdAddPath>({"store", "add-path"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreAdd();
}
+8 -2
View File
@@ -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 <nlohmann/json.hpp>
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<CmdBuild>("build");
void registerNixBuild()
{
registerCommand<CmdBuild>("build");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixBuild();
}
+8 -2
View File
@@ -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<CmdBundle>("bundle");
void registerNixBundle()
{
registerCommand<CmdBundle>("bundle");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixBundle();
}
+9 -3
View File
@@ -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<CmdCatStore>({"store", "cat"});
static auto rCmdCatNar = registerCommand2<CmdCatNar>({"nar", "cat"});
void registerNixCat()
{
registerCommand2<CmdCatStore>({"store", "cat"});
registerCommand2<CmdCatNar>({"nar", "cat"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixCat();
}
+10 -4
View File
@@ -2,14 +2,15 @@
#include "lix/libmain/common-args.hh"
#include "lix/libmain/shared.hh"
#include "lix/libstore/store-api.hh"
#include "config.hh"
#include <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct CmdConfig : MultiCommand
{
CmdConfig() : MultiCommand(RegisterCommand::getCommandsFor({"config"}))
CmdConfig() : MultiCommand(CommandRegistry::getCommandsFor({"config"}))
{ }
std::string description() override
@@ -76,5 +77,10 @@ struct CmdConfigShow : Command, MixJSON
}
};
static auto rCmdConfig = registerCommand<CmdConfig>("config");
static auto rShowConfig = registerCommand2<CmdConfigShow>({"config", "show"});
void registerNixConfig()
{
registerCommand<CmdConfig>("config");
registerCommand2<CmdConfigShow>({"config", "show"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixConfig();
}
+8 -2
View File
@@ -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<CmdCopy>("copy");
void registerNixCopy()
{
registerCommand<CmdCopy>("copy");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixCopy();
}
+5 -2
View File
@@ -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 <algorithm>
#include <climits>
@@ -580,6 +580,9 @@ struct CmdDaemon : StoreCommand
}
};
static auto rCmdDaemon = registerCommand2<CmdDaemon>({"daemon"});
void registerNixDaemon()
{
registerCommand2<CmdDaemon>({"daemon"});
}
}
@@ -3,6 +3,7 @@
namespace nix {
void registerNixDaemon();
void registerLegacyNixDaemon();
}
+7 -2
View File
@@ -7,7 +7,7 @@
#include "lix/libstore/derivations.hh"
#include <nlohmann/json.hpp>
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<CmdAddDerivation>({"derivation", "add"});
void registerNixDerivationAdd()
{
registerCommand2<CmdAddDerivation>({"derivation", "add"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixDerivationAdd();
}
+7 -2
View File
@@ -8,7 +8,7 @@
#include "lix/libstore/derivations.hh"
#include <nlohmann/json.hpp>
using namespace nix;
namespace nix {
using json = nlohmann::json;
struct CmdShowDerivation : InstallablesCommand
@@ -62,4 +62,9 @@ struct CmdShowDerivation : InstallablesCommand
}
};
static auto rCmdShowDerivation = registerCommand2<CmdShowDerivation>({"derivation", "show"});
void registerNixDerivationShow()
{
registerCommand2<CmdShowDerivation>({"derivation", "show"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixDerivationShow();
}
+9 -3
View File
@@ -1,10 +1,11 @@
#include "lix/libcmd/command.hh"
#include "derivation.hh"
using namespace nix;
namespace nix {
struct CmdDerivation : MultiCommand
{
CmdDerivation() : MultiCommand(RegisterCommand::getCommandsFor({"derivation"}))
CmdDerivation() : MultiCommand(CommandRegistry::getCommandsFor({"derivation"}))
{ }
std::string description() override
@@ -22,4 +23,9 @@ struct CmdDerivation : MultiCommand
}
};
static auto rCmdDerivation = registerCommand<CmdDerivation>("derivation");
void registerNixDerivation()
{
registerCommand<CmdDerivation>("derivation");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixDerivation();
}
+9 -3
View File
@@ -9,6 +9,7 @@
#include "lix/libutil/async.hh"
#include "run.hh"
#include "lix/libstore/temporary-dir.hh"
#include "develop.hh"
#include <iterator>
#include <memory>
@@ -16,7 +17,7 @@
#include <nlohmann/json.hpp>
#include <algorithm>
using namespace nix;
namespace nix {
struct DevelopSettings : Config
{
@@ -703,5 +704,10 @@ struct CmdPrintDevEnv : Common, MixJSON
}
};
static auto rCmdPrintDevEnv = registerCommand<CmdPrintDevEnv>("print-dev-env");
static auto rCmdDevelop = registerCommand<CmdDevelop>("develop");
void registerNixDevelop()
{
registerCommand<CmdPrintDevEnv>("print-dev-env");
registerCommand<CmdDevelop>("develop");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixDevelop();
}
+7 -2
View File
@@ -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 <nlohmann/json.hpp>
#include <regex>
@@ -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<CmdDiffClosures>({"store", "diff-closures"});
void registerNixStoreDiffClosures() {
registerCommand2<CmdDiffClosures>({"store", "diff-closures"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreDiffClosures();
}
+8 -2
View File
@@ -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<CmdDoctor>("doctor");
void registerNixDoctor()
{
registerCommand<CmdDoctor>("doctor");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixDoctor();
}
+9 -4
View File
@@ -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<CmdDumpPath>({"store", "dump-path"});
struct CmdDumpPath2 : Command
{
Path path;
@@ -63,4 +62,10 @@ struct CmdDumpPath2 : Command
}
};
static auto rDumpPath2 = registerCommand2<CmdDumpPath2>({"nar", "dump-path"});
void registerNixStoreDumpPath()
{
registerCommand2<CmdDumpPath>({"store", "dump-path"});
registerCommand2<CmdDumpPath2>({"nar", "dump-path"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreDumpPath();
}
+8 -2
View File
@@ -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 <unistd.h>
using namespace nix;
namespace nix {
struct CmdEdit : InstallableCommand
{
@@ -56,4 +57,9 @@ struct CmdEdit : InstallableCommand
}
};
static auto rCmdEdit = registerCommand<CmdEdit>("edit");
void registerNixEdit()
{
registerCommand<CmdEdit>("edit");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixEdit();
}
+8 -2
View File
@@ -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 <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption
{
@@ -139,4 +140,9 @@ struct CmdEval : MixJSON, InstallableCommand, MixReadOnlyOption
}
};
static auto rCmdEval = registerCommand<CmdEval>("eval");
void registerNixEval()
{
registerCommand<CmdEval>("eval");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixEval();
}
+8 -2
View File
@@ -17,12 +17,13 @@
#include "lix/libcmd/markdown.hh"
#include "lix/libutil/terminal.hh"
#include "lix/libutil/signals.hh"
#include "flake.hh"
#include <limits>
#include <nlohmann/json.hpp>
#include <iomanip>
using namespace nix;
namespace nix {
using namespace nix::flake;
using json = nlohmann::json;
@@ -1495,4 +1496,9 @@ struct CmdFlake : MultiCommand
}
};
static auto rCmdFlake = registerCommand<CmdFlake>("flake");
void registerNixFlake()
{
registerCommand<CmdFlake>("flake");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixFlake();
}
+8 -2
View File
@@ -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<std::string> args;
@@ -49,4 +50,9 @@ struct CmdFmt : SourceExprCommand {
};
};
static auto r2 = registerCommand<CmdFmt>("fmt");
void registerNixFmt()
{
registerCommand<CmdFmt>("fmt");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixFmt();
}
+5 -2
View File
@@ -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<CmdHash>("hash");
void registerNixHash()
{
registerCommand<CmdHash>("hash");
}
/* Legacy nix-hash command. */
static int compatNixHash(AsyncIoRoot & aio, std::string programName, Strings argv)
@@ -4,5 +4,6 @@
namespace nix {
void registerLegacyNixHash();
void registerNixHash();
}
+8 -2
View File
@@ -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<CmdLog>("log");
void registerNixLog()
{
registerCommand<CmdLog>("log");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixLog();
}
+8 -3
View File
@@ -5,7 +5,7 @@
#include "lix/libmain/common-args.hh"
#include <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct MixLs : virtual Args, MixJSON
{
@@ -160,5 +160,10 @@ struct CmdLsNar : Command, MixLs
}
};
static auto rCmdLsStore = registerCommand2<CmdLsStore>({"store", "ls"});
static auto rCmdLsNar = registerCommand2<CmdLsNar>({"nar", "ls"});
void registerNixLs()
{
registerCommand2<CmdLsStore>({"store", "ls"});
registerCommand2<CmdLsNar>({"nar", "ls"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixLs();
}
+102 -7
View File
@@ -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 <sys/types.h>
#include <sys/socket.h>
@@ -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<std::string> proxyVariables = {
@@ -114,7 +205,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 +320,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()
@@ -326,7 +417,6 @@ struct CmdHelp : Command
}
};
static auto rCmdHelp = registerCommand<CmdHelp>("help");
struct CmdHelpStores : Command
{
@@ -350,7 +440,11 @@ struct CmdHelpStores : Command
}
};
static auto rCmdHelpStores = registerCommand<CmdHelpStores>("help-stores");
void registerNixHelp()
{
registerCommand<CmdHelp>("help");
registerCommand<CmdHelpStores>("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`.
+8 -2
View File
@@ -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 <nlohmann/json.hpp>
using namespace nix;
namespace nix {
using nlohmann::json;
@@ -57,4 +58,9 @@ struct CmdMakeContentAddressed : virtual CopyCommand, virtual StorePathsCommand,
}
};
static auto rCmdMakeContentAddressed = registerCommand2<CmdMakeContentAddressed>({"store", "make-content-addressed"});
void registerNixMakeContentAddressed()
{
registerCommand2<CmdMakeContentAddressed>({"store", "make-content-addressed"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixMakeContentAddressed();
}
+47 -4
View File
@@ -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(
+9 -3
View File
@@ -1,10 +1,11 @@
#include "lix/libcmd/command.hh"
#include "nar.hh"
using namespace nix;
namespace nix {
struct CmdNar : MultiCommand
{
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
CmdNar() : MultiCommand(CommandRegistry::getCommandsFor({"nar"}))
{ }
std::string description() override
@@ -29,4 +30,9 @@ struct CmdNar : MultiCommand
}
};
static auto rCmdNar = registerCommand<CmdNar>("nar");
void registerNixNar()
{
registerCommand<CmdNar>("nar");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixNar();
}
+8 -2
View File
@@ -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 <atomic>
using namespace nix;
namespace nix {
struct CmdOptimiseStore : StoreCommand
{
@@ -27,4 +28,9 @@ struct CmdOptimiseStore : StoreCommand
}
};
static auto rCmdOptimiseStore = registerCommand2<CmdOptimiseStore>({"store", "optimise"});
void registerNixStoreOptimise()
{
registerCommand2<CmdOptimiseStore>({"store", "optimise"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreOptimise();
}
+8 -2
View File
@@ -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<CmdPathFromHashPart>({"store", "path-from-hash-part"});
void registerNixStorePathFromHashPart()
{
registerCommand2<CmdPathFromHashPart>({"store", "path-from-hash-part"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStorePathFromHashPart();
}
+8 -2
View File
@@ -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 <algorithm>
#include <array>
#include <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct CmdPathInfo : StorePathsCommand, MixJSON
{
@@ -131,4 +132,9 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
}
};
static auto rCmdPathInfo = registerCommand<CmdPathInfo>("path-info");
void registerNixPathInfo()
{
registerCommand<CmdPathInfo>("path-info");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixPathInfo();
}
+8 -2
View File
@@ -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 <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct CmdPingStore : StoreCommand, MixJSON
{
@@ -46,4 +47,9 @@ struct CmdPingStore : StoreCommand, MixJSON
}
};
static auto rCmdPingStore = registerCommand2<CmdPingStore>({"store", "ping"});
void registerNixStorePing()
{
registerCommand2<CmdPingStore>({"store", "ping"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStorePing();
}
+5 -2
View File
@@ -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 <nlohmann/json.hpp>
@@ -337,6 +337,9 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON
}
};
static auto rCmdStorePrefetchFile = registerCommand2<CmdStorePrefetchFile>({"store", "prefetch-file"});
void registerNixStorePrefetchFile()
{
registerCommand2<CmdStorePrefetchFile>({"store", "prefetch-file"});
}
}
@@ -4,5 +4,6 @@
namespace nix {
void registerLegacyNixPrefetchUrl();
void registerNixStorePrefetchFile();
}
+8 -2
View File
@@ -11,12 +11,13 @@
#include "user-env.hh"
#include "lix/libstore/profiles.hh"
#include "lix/libstore/names.hh"
#include "profile.hh"
#include <nlohmann/json.hpp>
#include <regex>
#include <iomanip>
using namespace nix;
namespace nix {
static std::map<Installable *, std::pair<BuiltPaths, ref<ExtraPathInfo>>>
@@ -639,4 +640,9 @@ struct CmdProfile : MultiCommand
}
};
static auto rCmdProfile = registerCommand<CmdProfile>("profile");
void registerNixProfile()
{
registerCommand<CmdProfile>("profile");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixProfile();
}
+10 -5
View File
@@ -1,13 +1,14 @@
#include "lix/libcmd/command.hh"
#include "lix/libmain/common-args.hh"
#include "realisation.hh"
#include <nlohmann/json.hpp>
using namespace nix;
namespace nix {
struct CmdRealisation : MultiCommand
{
CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
CmdRealisation() : MultiCommand(CommandRegistry::getCommandsFor({"realisation"}))
{ }
std::string description() override
@@ -25,8 +26,6 @@ struct CmdRealisation : MultiCommand
}
};
static auto rCmdRealisation = registerCommand<CmdRealisation>("realisation");
struct CmdRealisationInfo : BuiltPathsCommand, MixJSON
{
CmdRealisationInfo() : BuiltPathsCommand(false) {}
@@ -81,4 +80,10 @@ struct CmdRealisationInfo : BuiltPathsCommand, MixJSON
}
};
static auto rCmdRealisationInfo = registerCommand2<CmdRealisationInfo>({"realisation", "info"});
void registerNixRealisation()
{
registerCommand<CmdRealisation>("realisation");
registerCommand2<CmdRealisationInfo>({"realisation", "info"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixRealisation();
}
+8 -2
View File
@@ -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<CmdRegistry>("registry");
void registerNixRegistry()
{
registerCommand<CmdRegistry>("registry");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixRegistry();
}
+5 -1
View File
@@ -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 {
@@ -84,6 +85,9 @@ struct CmdRepl : RawInstallablesCommand
}
};
static auto rCmdRepl = registerCommand<CmdRepl>("repl");
void registerNixRepl()
{
registerCommand<CmdRepl>("repl");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixRepl();
}
+5 -3
View File
@@ -153,8 +153,6 @@ struct CmdShell : InstallablesCommand, MixEnvironment
}
};
static auto rCmdShell = registerCommand<CmdShell>("shell");
struct CmdRun : InstallableCommand
{
using InstallableCommand::run;
@@ -219,7 +217,11 @@ struct CmdRun : InstallableCommand
}
};
static auto rCmdRun = registerCommand<CmdRun>("run");
void registerNixRun()
{
registerCommand<CmdShell>("shell");
registerCommand<CmdRun>("run");
}
void chrootHelper(int argc, char * * argv)
{
+2
View File
@@ -19,4 +19,6 @@ void runProgramInStore(
std::optional<std::string_view> system = std::nullopt
);
void registerNixRun();
}
+8 -2
View File
@@ -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 <regex>
#include <fstream>
#include <nlohmann/json.hpp>
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<CmdSearch>("search");
void registerNixSearch()
{
registerCommand<CmdSearch>("search");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixSearch();
}
+10 -6
View File
@@ -4,11 +4,12 @@
#include "lix/libutil/async.hh"
#include "lix/libutil/thread-pool.hh"
#include "lix/libutil/signals.hh"
#include "sigs.hh"
#include <atomic>
#include <functional>
using namespace nix;
namespace nix {
struct CmdCopySigs : StorePathsCommand
{
@@ -90,8 +91,6 @@ struct CmdCopySigs : StorePathsCommand
}
};
static auto rCmdCopySigs = registerCommand2<CmdCopySigs>({"store", "copy-sigs"});
struct CmdSign : StorePathsCommand
{
Path secretKeyFile;
@@ -155,8 +154,6 @@ struct CmdSign : StorePathsCommand
}
};
static auto rCmdSign = registerCommand2<CmdSign>({"store", "sign"});
struct CmdKeyGenerateSecret : Command
{
std::optional<std::string> keyName;
@@ -242,4 +239,11 @@ struct CmdKey : MultiCommand
}
};
static auto rCmdKey = registerCommand<CmdKey>("key");
void registerNixSigs()
{
registerCommand2<CmdCopySigs>({"store", "copy-sigs"});
registerCommand2<CmdSign>({"store", "sign"});
registerCommand<CmdKey>("key");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixSigs();
}
+8 -2
View File
@@ -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 <atomic>
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<CmdCopyLog>({"store", "copy-log"});
void registerNixStoreCopyLog()
{
registerCommand2<CmdCopyLog>({"store", "copy-log"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreCopyLog();
}
+8 -2
View File
@@ -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<CmdStoreDelete>({"store", "delete"});
void registerNixStoreDelete()
{
registerCommand2<CmdStoreDelete>({"store", "delete"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreDelete();
}
+8 -2
View File
@@ -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<CmdStoreGC>({"store", "gc"});
void registerNixStoreGc()
{
registerCommand2<CmdStoreGC>({"store", "gc"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreGc();
}
+8 -2
View File
@@ -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<CmdStoreRepair>({"store", "repair"});
void registerNixStoreRepair()
{
registerCommand2<CmdStoreRepair>({"store", "repair"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreRepair();
}
+9 -3
View File
@@ -1,10 +1,11 @@
#include "lix/libcmd/command.hh"
#include "store.hh"
using namespace nix;
namespace nix {
struct CmdStore : MultiCommand
{
CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"}))
CmdStore() : MultiCommand(CommandRegistry::getCommandsFor({"store"}))
{ }
std::string description() override
@@ -22,4 +23,9 @@ struct CmdStore : MultiCommand
}
};
static auto rCmdStore = registerCommand<CmdStore>("store");
void registerNixStore()
{
registerCommand<CmdStore>("store");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStore();
}
+8 -2
View File
@@ -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<CmdUpgradeNix>("upgrade-nix");
void registerNixUpgradeNix()
{
registerCommand<CmdUpgradeNix>("upgrade-nix");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixUpgradeNix();
}
+8 -2
View File
@@ -5,11 +5,12 @@
#include "lix/libutil/thread-pool.hh"
#include "lix/libutil/signals.hh"
#include "lix/libutil/exit.hh"
#include "verify.hh"
#include <atomic>
#include <functional>
using namespace nix;
namespace nix {
struct CmdVerify : StorePathsCommand
{
@@ -186,4 +187,9 @@ struct CmdVerify : StorePathsCommand
}
};
static auto rCmdVerify = registerCommand2<CmdVerify>({"store", "verify"});
void registerNixStoreVerify()
{
registerCommand2<CmdVerify>({"store", "verify"});
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixStoreVerify();
}
+8 -2
View File
@@ -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 <queue>
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<CmdWhyDepends>("why-depends");
void registerNixWhyDepends()
{
registerCommand<CmdWhyDepends>("why-depends");
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
/// @file
namespace nix {
void registerNixWhyDepends();
}