Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ void LocalDerivationGoal::initEnv()
/* The maximum number of cores to utilize for parallel building. */
env["NIX_BUILD_CORES"] = fmt("%d", settings.buildCores);

/* The maximum average load to target for buildsystems supporting it. */
env["NIX_LOAD_LIMIT"] = fmt("%d", settings.loadLimit);

initTmpDir();

/* Compatibility hack with Nix <= 0.7: if this is a fixed-output
Expand Down
2 changes: 2 additions & 0 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ struct ClientSettings
time_t maxSilentTime;
bool verboseBuild;
unsigned int buildCores;
unsigned int loadLimit;
bool useSubstitutes;
StringMap overrides;

Expand All @@ -202,6 +203,7 @@ struct ClientSettings
settings.maxSilentTime = maxSilentTime;
settings.verboseBuild = verboseBuild;
settings.buildCores = buildCores;
settings.loadLimit = loadLimit;
settings.useSubstitutes = useSubstitutes;

for (auto & i : overrides) {
Expand Down
16 changes: 16 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ public:
)",
{"build-cores"}, false};

Setting<unsigned int> loadLimit{
this,
getDefaultCores(),
"load-limit",
R"(
Sets the value of the `NIX_LOAD_LIMIT` environment variable in the
invocation of builders. Builders can use this variable at their
discretion to schedule jobs based on the average load of the system.
For instance, in Nixpkgs, if the derivation attribute
`enableParallelBuilding` is set to `true`, the builder passes the
`-lN` flag to GNU Make. It can be overriden using the `--max-build-load`
command line switch and defaults to `1`. The value `0`means that
the builder should ignore the average system load.
)",
{}, false};

/* Read-only mode. Don't copy stuff to the store, don't change
the database. */
bool readOnlyMode = false;
Expand Down
1 change: 1 addition & 0 deletions src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ static void main_nix_build(int argc, char * * argv)
env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = *tmp;
env["NIX_STORE"] = store->storeDir;
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
env["NIX_LOAD_LIMIT"] = std::to_string(settings.loadLimit);

auto passAsFile = tokenizeString<StringSet>(getOr(drv.env, "passAsFile", ""));

Expand Down