1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00
This commit is contained in:
Robert Hensing 2025-11-08 14:35:44 +01:00 committed by GitHub
commit 4806bf237e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 3 deletions

View file

@ -7,6 +7,7 @@
#include "nix/util/file-system.hh" #include "nix/util/file-system.hh"
#include "nix/util/processes.hh" #include "nix/util/processes.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/util/environment-variables.hh"
#include <math.h> #include <math.h>
#ifdef __APPLE__ #ifdef __APPLE__
@ -65,13 +66,27 @@ void setStackSize(size_t stackSize)
struct rlimit limit; struct rlimit limit;
if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) { if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) {
savedStackSize = limit.rlim_cur; savedStackSize = limit.rlim_cur;
limit.rlim_cur = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max); if (limit.rlim_max < static_cast<rlim_t>(stackSize)) {
if (getEnv("_NIX_TEST_NO_ENVIRONMENT_WARNINGS") != "1") {
logger->log(
lvlWarn,
HintFmt(
"Stack size hard limit is %1%, which is less than the desired %2%. If possible, increase the hard limit, e.g. with 'ulimit -Hs %3%'.",
limit.rlim_max,
stackSize,
stackSize / 1024)
.str());
}
}
auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
limit.rlim_cur = requestedSize;
if (setrlimit(RLIMIT_STACK, &limit) != 0) { if (setrlimit(RLIMIT_STACK, &limit) != 0) {
logger->log( logger->log(
lvlError, lvlError,
HintFmt( HintFmt(
"Failed to increase stack size from %1% to %2% (maximum allowed stack size: %3%): %4%", "Failed to increase stack size from %1% to %2% (desired: %3%, maximum allowed: %4%): %5%",
savedStackSize, savedStackSize,
requestedSize,
stackSize, stackSize,
limit.rlim_max, limit.rlim_max,
std::strerror(errno)) std::strerror(errno))

View file

@ -566,7 +566,9 @@ int main(int argc, char ** argv)
#ifndef _WIN32 #ifndef _WIN32
// Increase the default stack size for the evaluator and for // Increase the default stack size for the evaluator and for
// libstdc++'s std::regex. // libstdc++'s std::regex.
nix::setStackSize(64 * 1024 * 1024); // This used to be 64 MiB, but macOS as deployed on GitHub Actions has a
// hard limit slightly under that, so we round it down a bit.
nix::setStackSize(60 * 1024 * 1024);
#endif #endif
return nix::handleExceptions(argv[0], [&]() { nix::mainWrapped(argc, argv); }); return nix::handleExceptions(argv[0], [&]() { nix::mainWrapped(argc, argv); });

View file

@ -49,6 +49,9 @@ if ! isTestOnNixOS; then
fi fi
export _NIX_IN_TEST=$TEST_ROOT/shared export _NIX_IN_TEST=$TEST_ROOT/shared
export _NIX_TEST_NO_LSOF=1 export _NIX_TEST_NO_LSOF=1
# Suppress warnings that depend on the test environment (e.g., ulimit warnings)
# to avoid non-deterministic test failures in golden tests
export _NIX_TEST_NO_ENVIRONMENT_WARNINGS=1
export NIX_REMOTE=${NIX_REMOTE_-} export NIX_REMOTE=${NIX_REMOTE_-}
fi # ! isTestOnNixOS fi # ! isTestOnNixOS