Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <nlohmann/json.hpp>

#include "nix/cmd/command.hh"
#include "nix/cmd/legacy.hh"
#include "nix/cmd/markdown.hh"
#include "nix/store/store-open.hh"
#include "nix/store/local-fs-store.hh"
Expand All @@ -14,6 +15,18 @@

namespace nix {

RegisterCommand::Commands & RegisterCommand::commands()
{
static RegisterCommand::Commands commands;
return commands;
}

RegisterLegacyCommand::Commands & RegisterLegacyCommand::commands()
{
static RegisterLegacyCommand::Commands commands;
return commands;
}

nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
{
nix::Commands res;
Expand Down
6 changes: 1 addition & 5 deletions src/libcmd/include/nix/cmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,7 @@ struct RegisterCommand
{
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;

static Commands & commands()
{
static Commands commands;
return commands;
}
static Commands & commands();

RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command)
{
Expand Down
6 changes: 1 addition & 5 deletions src/libcmd/include/nix/cmd/legacy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ struct RegisterLegacyCommand
{
typedef std::map<std::string, MainFunction> Commands;

static Commands & commands()
{
static Commands commands;
return commands;
}
static Commands & commands();

RegisterLegacyCommand(const std::string & name, MainFunction fun)
{
Expand Down
6 changes: 1 addition & 5 deletions src/libexpr/include/nix/expr/primops.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ struct RegisterPrimOp
{
typedef std::vector<PrimOp> PrimOps;

static PrimOps & primOps()
{
static PrimOps primOps;
return primOps;
}
static PrimOps & primOps();

/**
* You can register a constant by passing an arity of 0. fun
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/include/nix/expr/print-options.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct PrintOptions
* `PrintOptions` for unknown and therefore potentially large values in error messages,
* to avoid printing "too much" output.
*/
static PrintOptions errorPrintOptions = PrintOptions{
static constexpr PrintOptions errorPrintOptions = PrintOptions{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just stumbled upon this. It seems to be immutable, but this should cause a compile error if that changes.

Alternatively it could be moved to the library.

.ansiColors = true,
.maxDepth = 10,
.maxAttrs = 10,
Expand Down
6 changes: 6 additions & 0 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

namespace nix {

RegisterPrimOp::PrimOps & RegisterPrimOp::primOps()
{
static RegisterPrimOp::PrimOps primOps;
return primOps;
}

/*************************************************************
* Miscellaneous
*************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions src/libstore/builtins/buildenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

namespace nix {

RegisterBuiltinBuilder::BuiltinBuilders & RegisterBuiltinBuilder::builtinBuilders()
{
static RegisterBuiltinBuilder::BuiltinBuilders builders;
return builders;
}

namespace {

struct State
Expand Down
6 changes: 1 addition & 5 deletions src/libstore/include/nix/store/builtins.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ struct RegisterBuiltinBuilder
{
typedef std::map<std::string, BuiltinBuilder> BuiltinBuilders;

static BuiltinBuilders & builtinBuilders()
{
static BuiltinBuilders builders;
return builders;
}
static BuiltinBuilders & builtinBuilders();

RegisterBuiltinBuilder(const std::string & name, BuiltinBuilder && fun)
{
Expand Down
6 changes: 6 additions & 0 deletions src/libutil/config-global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

namespace nix {

GlobalConfig::ConfigRegistrations & GlobalConfig::configRegistrations()
{
static GlobalConfig::ConfigRegistrations configRegistrations;
return configRegistrations;
}

bool GlobalConfig::set(const std::string & name, const std::string & value)
{
for (auto & config : configRegistrations())
Expand Down
6 changes: 1 addition & 5 deletions src/libutil/include/nix/util/config-global.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ struct GlobalConfig : public AbstractConfig
{
typedef std::vector<Config *> ConfigRegistrations;

static ConfigRegistrations & configRegistrations()
{
static ConfigRegistrations configRegistrations;
return configRegistrations;
}
static ConfigRegistrations & configRegistrations();

bool set(const std::string & name, const std::string & value) override;

Expand Down
Loading