Compare commits

...

6 commits

10 changed files with 90 additions and 8 deletions

View file

@ -61,3 +61,8 @@ edolstra:
roberth:
display_name: Robert Hensing
github: roberth
midnightveil:
display_name: julia
forgejo: midnightveil
github: midnightveil

View file

@ -0,0 +1,13 @@
---
synopsis: "Add an option `enable-core-dumps` that enables core dumps from builds"
cls: 1088
credits: midnightveil
category: Features
---
In the past, Lix disabled core dumps by setting the soft `RLIMIT_CORE` to 0
unconditionally. Although this rlimit could be altered from the builder since
it is just the soft limit, this was kind of annoying to do. By passing
`--option enable-core-dumps true` to an offending build, one can now cause the
core dumps to be handled by the system in the normal way (winding up in
`coredumpctl`, say, on Linux).

View file

@ -14,8 +14,11 @@ struct EvalSettings : Config
static std::string resolvePseudoUrl(std::string_view url);
Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation",
"Whether builtin functions that allow executing native code should be enabled."};
Setting<bool> enableNativeCode{this, false, "allow-unsafe-native-code-during-evaluation", R"(
Whether builtin functions that allow executing native code should be enabled.
In particular, this adds the `importNative` and `exec` builtins.
)"};
Setting<Strings> nixPath{
this, getDefaultNixPath(), "nix-path",

View file

@ -1977,6 +1977,9 @@ void LocalDerivationGoal::runChild()
/* Disable core dumps by default. */
struct rlimit limit = { 0, RLIM_INFINITY };
if (settings.enableCoreDumps) {
limit.rlim_cur = RLIM_INFINITY;
}
setrlimit(RLIMIT_CORE, &limit);
// FIXME: set other limits to deterministic values?

View file

@ -290,6 +290,15 @@ public:
Setting<off_t> reservedSize{this, 8 * 1024 * 1024, "gc-reserved-space",
"Amount of reserved disk space for the garbage collector."};
Setting<bool> enableCoreDumps{
this, false, "enable-core-dumps",
R"(
If set to `false` (the default), `RLIMIT_CORE` has a soft limit of zero.
If set to `true`, the soft limit is infinite.
The hard limit is always infinite.
)"};
Setting<bool> fsyncMetadata{
this, true, "fsync-metadata",
R"(

View file

@ -87,11 +87,13 @@ public:
expectArgs({
.label="inputs",
.optional=true,
.handler={[&](std::string inputToUpdate){
auto inputPath = flake::parseInputPath(inputToUpdate);
if (lockFlags.inputUpdates.contains(inputPath))
warn("Input '%s' was specified multiple times. You may have done this by accident.");
lockFlags.inputUpdates.insert(inputPath);
.handler={[&](std::vector<std::string> inputsToUpdate) {
for (const auto & inputToUpdate : inputsToUpdate) {
auto inputPath = flake::parseInputPath(inputToUpdate);
if (lockFlags.inputUpdates.contains(inputPath))
warn("Input '%s' was specified multiple times. You may have done this by accident.", inputToUpdate);
lockFlags.inputUpdates.insert(inputPath);
}
}},
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix);
@ -132,6 +134,15 @@ struct CmdFlakeLock : FlakeCommand
CmdFlakeLock()
{
addFlag({
.longName="update-input",
.description="Replaced with `nix flake update input...`",
.labels={"input-path"},
.handler={[&](std::string inputToUpdate){
throw UsageError("`nix flake lock --update-input %1%` has been replaced by `nix flake update %1%`", inputToUpdate);
}}
});
/* Remove flags that don't make sense. */
removeFlag("no-write-lock-file");
}

View file

@ -0,0 +1,15 @@
let
inherit (import ../util.nix) mkNixBuildTest;
in mkNixBuildTest rec {
name = "coredumps";
extraMachineConfig = { pkgs, ... }: {
boot.kernel.sysctl."kernel.core_pattern" = "core";
};
expressionFile = ./package.nix;
testScriptPost = ''
# do a test, but this time with coredumps enabled.
machine.succeed('nix-build --option enable-core-dumps true --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} { shouldBePresent = true; }"')
'';
}

View file

@ -0,0 +1,16 @@
{ lib, runCommand, shouldBePresent ? false }:
runCommand "core-dump-now" { } ''
set -m
sleep infinity &
# make a coredump
kill -SIGSEGV %1
if ${lib.optionalString (shouldBePresent) "!"} test -n "$(find . -maxdepth 1 -name 'core*' -print -quit)"; then
echo "core file was in wrong presence state, expected: ${if shouldBePresent then "present" else "missing"}"
exit 1
fi
touch $out
''

View file

@ -166,4 +166,6 @@ in
rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox;
broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix;
coredumps = runNixOSTestFor "x86_64-linux" ./coredumps;
}

View file

@ -1,5 +1,6 @@
{
mkNixBuildTest = { name, expressionFile, extraMachineConfig ? {} }:
mkNixBuildTest =
{ name, expressionFile, extraMachineConfig ? {}, testScriptPre ? "", testScriptPost ? "" }:
{ lib, pkgs, ... }:
{
inherit name;
@ -17,7 +18,11 @@
testScript = { nodes }: ''
start_all()
${testScriptPre}
machine.succeed('nix-build --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} {}"')
${testScriptPost}
'';
};
}