diff options
-rw-r--r-- | doc/manual/change-authors.yml | 5 | ||||
-rw-r--r-- | doc/manual/rl-next/enable-coredumps.md | 13 | ||||
-rw-r--r-- | doc/manual/rl-next/nixversion-fake.md | 14 | ||||
-rw-r--r-- | package.nix | 2 | ||||
-rw-r--r-- | src/libcmd/repl.cc | 4 | ||||
-rw-r--r-- | src/libexpr/eval-settings.hh | 7 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 29 | ||||
-rw-r--r-- | src/libstore/build/local-derivation-goal.cc | 3 | ||||
-rw-r--r-- | src/libstore/globals.hh | 9 | ||||
-rw-r--r-- | src/libutil/util.hh | 6 | ||||
-rw-r--r-- | tests/nixos/coredumps/default.nix | 15 | ||||
-rw-r--r-- | tests/nixos/coredumps/package.nix | 16 | ||||
-rw-r--r-- | tests/nixos/default.nix | 2 | ||||
-rw-r--r-- | tests/nixos/util.nix | 7 |
14 files changed, 112 insertions, 20 deletions
diff --git a/doc/manual/change-authors.yml b/doc/manual/change-authors.yml index 732c459a8..8c07d7e90 100644 --- a/doc/manual/change-authors.yml +++ b/doc/manual/change-authors.yml @@ -61,3 +61,8 @@ edolstra: roberth: display_name: Robert Hensing github: roberth + +midnightveil: + display_name: julia + forgejo: midnightveil + github: midnightveil diff --git a/doc/manual/rl-next/enable-coredumps.md b/doc/manual/rl-next/enable-coredumps.md new file mode 100644 index 000000000..092aa58a1 --- /dev/null +++ b/doc/manual/rl-next/enable-coredumps.md @@ -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). diff --git a/doc/manual/rl-next/nixversion-fake.md b/doc/manual/rl-next/nixversion-fake.md index 93f75611d..725b8e609 100644 --- a/doc/manual/rl-next/nixversion-fake.md +++ b/doc/manual/rl-next/nixversion-fake.md @@ -1,13 +1,17 @@ --- -synopsis: "`builtins.nixVersion` now returns a fixed value \"2.18.3-lix\"" -cls: 558 +synopsis: "`builtins.nixVersion` and `builtins.langVersion` return fixed values" +cls: [558, 1144] credits: jade category: Breaking Changes --- -`builtins.nixVersion` now returns a fixed value `"2.18.3-lix"`. This prevents -feature detection assuming that features that exist in Nix post-Lix-branch-off -might exist, even though the Lix version is greater than the Nix version. +`builtins.nixVersion` now returns a fixed value `"2.18.3-lix"`. + +`builtins.langVersion` returns a fixed value `6`, matching CppNix 2.18. + +This prevents feature detection assuming that features that exist in Nix +post-Lix-branch-off might exist, even though the Lix version is greater than +the Nix version. In the future, check for builtins for feature detection. If a feature cannot be detected by *those* means, please file a Lix bug. diff --git a/package.nix b/package.nix index 83a4411ec..fe56a4003 100644 --- a/package.nix +++ b/package.nix @@ -375,7 +375,6 @@ stdenv.mkDerivation (finalAttrs: { just, nixfmt, glibcLocales, - bear, pre-commit-checks, clang-tools, llvmPackages, @@ -418,7 +417,6 @@ stdenv.mkDerivation (finalAttrs: { llvmPackages.clang-unwrapped.dev ] ++ lib.optional (pre-commit-checks ? enabledPackages) pre-commit-checks.enabledPackages - ++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) bear ++ lib.optional (lib.meta.availableOn stdenv.buildPlatform clangbuildanalyzer) clangbuildanalyzer ++ finalAttrs.checkInputs; diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 34de2160a..525c25560 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -141,7 +141,11 @@ struct NixRepl * Note: This is `shared_ptr` to avoid garbage collection. */ std::shared_ptr<Value *> replOverlaysEvalFunction = + #if HAVE_BOEHMGC std::allocate_shared<Value *>(traceable_allocator<Value *>(), nullptr); + #else + std::make_shared<Value *>(nullptr); + #endif /** * Get the `info` AttrSet that's passed as the first argument to each diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh index 98fe6881e..4674acda2 100644 --- a/src/libexpr/eval-settings.hh +++ b/src/libexpr/eval-settings.hh @@ -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", diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 33a2688f1..e36b800c3 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -4355,10 +4355,13 @@ void EvalState::createBaseEnv() .doc = R"( Legacy version of Nix. Always returns "2.18.3-lix" on Lix. - To determine if features exist, Nix scripts should instead use direct - means of feature detection, such as checking for existence of - builtins they want to use. Doing so allows for much better compatibility - across implementations. + Code in the Nix language should use other means of feature detection + like detecting the presence of builtins, rather than trying to find + the version of the Nix implementation, as there may be other Nix + implementations with different feature combinations. + + If the feature you want to write compatibility code for cannot be + detected by any means, please file a Lix bug. )", }); @@ -4377,15 +4380,23 @@ void EvalState::createBaseEnv() )", }); - /* Language version. This should be increased every time a new - language feature gets added. It's not necessary to increase it - when primops get added, because you can just use `builtins ? - primOp' to check. */ + /* Legacy language version. + * This is fixed at 6, and will never change in the future on Lix. + * A better language versioning construct needs to be built instead. */ v.mkInt(6); addConstant("__langVersion", v, { .type = nInt, .doc = R"( - The current version of the Nix language. + The legacy version of the Nix language. Always is `6` on Lix, + matching Nix 2.18. + + Code in the Nix language should use other means of feature detection + like detecting the presence of builtins, rather than trying to find + the version of the Nix implementation, as there may be other Nix + implementations with different feature combinations. + + If the feature you want to write compatibility code for cannot be + detected by any means, please file a Lix bug. )", }); diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 3429afafa..cdbd0f5a7 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -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? diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index 16af3a415..8856d8fae 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -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"( diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 5adabae28..914d6cce0 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -240,11 +240,15 @@ std::optional<Path> getSelfExe(); /** * @return $XDG_STATE_HOME or $HOME/.local/state. + * + * @note Not to be confused with settings.nixStateDir. */ Path getStateDir(); /** - * Create the Nix state directory and return the path to it. + * Create $XDG_STATE_HOME/nix or $HOME/.local/state/nix, and return + * the path to it. + * @note Not to be confused with settings.nixStateDir. */ Path createNixStateDir(); diff --git a/tests/nixos/coredumps/default.nix b/tests/nixos/coredumps/default.nix new file mode 100644 index 000000000..3d0d62945 --- /dev/null +++ b/tests/nixos/coredumps/default.nix @@ -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; }"') + ''; +} diff --git a/tests/nixos/coredumps/package.nix b/tests/nixos/coredumps/package.nix new file mode 100644 index 000000000..a7f6434ed --- /dev/null +++ b/tests/nixos/coredumps/package.nix @@ -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 +'' diff --git a/tests/nixos/default.nix b/tests/nixos/default.nix index 987463b07..9dd888916 100644 --- a/tests/nixos/default.nix +++ b/tests/nixos/default.nix @@ -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; } diff --git a/tests/nixos/util.nix b/tests/nixos/util.nix index 0c51cc075..1b8b4223c 100644 --- a/tests/nixos/util.nix +++ b/tests/nixos/util.nix @@ -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} ''; }; } |