From fbbca59453fcbc91ff63256b617523b5962b28f8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 31 May 2024 19:18:38 +0200 Subject: [PATCH 1/6] Make RegexCache thread-safe --- src/libexpr/primops.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 22d7f188f..9177b0a2f 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -4062,17 +4062,23 @@ static RegisterPrimOp primop_convertHash({ struct RegexCache { - // TODO use C++20 transparent comparison when available - std::unordered_map cache; - std::list keys; + struct State + { + // TODO use C++20 transparent comparison when available + std::unordered_map cache; + std::list keys; + }; + + Sync state_; std::regex get(std::string_view re) { - auto it = cache.find(re); - if (it != cache.end()) + auto state(state_.lock()); + auto it = state->cache.find(re); + if (it != state->cache.end()) return it->second; - keys.emplace_back(re); - return cache.emplace(keys.back(), std::regex(keys.back(), std::regex::extended)).first->second; + state->keys.emplace_back(re); + return state->cache.emplace(state->keys.back(), std::regex(state->keys.back(), std::regex::extended)).first->second; } }; From 4755e133c410aa2611c23c3f8e106b4194da0c5e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 10 Jun 2024 12:37:17 +0200 Subject: [PATCH 2/6] Fix warning --- src/libexpr/eval-cache.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/eval-cache.hh b/src/libexpr/eval-cache.hh index cac985829..b1911e3a4 100644 --- a/src/libexpr/eval-cache.hh +++ b/src/libexpr/eval-cache.hh @@ -31,7 +31,7 @@ struct CachedEvalError : EvalError class EvalCache : public std::enable_shared_from_this { friend class AttrCursor; - friend class CachedEvalError; + friend struct CachedEvalError; std::shared_ptr db; EvalState & state; @@ -87,7 +87,7 @@ typedef std::variant< class AttrCursor : public std::enable_shared_from_this { friend class EvalCache; - friend class CachedEvalError; + friend struct CachedEvalError; ref root; typedef std::optional, Symbol>> Parent; From 0a09597790348a3e0420020b0bab68517669ecf6 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 10 Jun 2024 12:37:24 +0200 Subject: [PATCH 3/6] Typo --- src/libexpr/eval.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 3524c8b1e..9e6b89544 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -365,7 +365,7 @@ void initGC() }; } #else - #warning "BoehmGC version does not support GC while coroutine exists. GC will be disabled inside coroutines. Consider updating bwd-gc to 8.4 or later." + #warning "BoehmGC version does not support GC while coroutine exists. GC will be disabled inside coroutines. Consider updating bdw-gc to 8.4 or later." #endif From f91f34aa653781ef46c4f6008269785f6198a3d4 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 10 Jun 2024 12:37:44 +0200 Subject: [PATCH 4/6] bdwgc 8.2.4 has sp_corrector > Support client-defined stack pointer adjustment before thread stack push -- https://github.com/ivmai/bdwgc/releases/tag/v8.2.4 This fixes an inaccuracy in cc6f31525253b73e4776b5f733e0950e1706d546, in the update to Nixpkgs 24.05 https://github.com/NixOS/nix/pull/10835 After this fixup, the build log won't ask for an upgrade, and we'll be able to collect when a coroutine exists, e.g. during filterSource. --- src/libexpr/eval.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 9e6b89544..f441977a5 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -354,7 +354,7 @@ void initGC() // TODO: Remove __APPLE__ condition. // Comment suggests an implementation that works on darwin and windows // https://github.com/ivmai/bdwgc/issues/362#issuecomment-1936672196 - #if GC_VERSION_MAJOR >= 8 && GC_VERSION_MINOR >= 4 && !defined(__APPLE__) + #if GC_VERSION_MAJOR >= 8 && GC_VERSION_MINOR >= 2 && GC_VERSION_MICRO >= 4 && !defined(__APPLE__) GC_set_sp_corrector(&fixupBoehmStackPointer); if (!GC_get_sp_corrector()) { @@ -365,7 +365,7 @@ void initGC() }; } #else - #warning "BoehmGC version does not support GC while coroutine exists. GC will be disabled inside coroutines. Consider updating bdw-gc to 8.4 or later." + #warning "BoehmGC version does not support GC while coroutine exists. GC will be disabled inside coroutines. Consider updating bdw-gc to 8.2.4 or later." #endif From 1363f51bcb24ab9948b7b5093490a009947f7453 Mon Sep 17 00:00:00 2001 From: Tom Bereknyei Date: Mon, 10 Jun 2024 08:32:30 -0400 Subject: [PATCH 5/6] fix: remove usage of XDG_RUNTIME_DIR for TMP --- src/nix-build/nix-build.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index b601604dc..77df08edd 100644 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -477,9 +477,7 @@ static void main_nix_build(int argc, char * * argv) // Set the environment. auto env = getEnv(); - auto tmp = getEnvNonEmpty("TMPDIR"); - if (!tmp) - tmp = getEnvNonEmpty("XDG_RUNTIME_DIR").value_or("/tmp"); + auto tmp = getEnvNonEmpty("TMPDIR").value_or("/tmp"); if (pure) { decltype(env) newEnv; @@ -491,7 +489,7 @@ static void main_nix_build(int argc, char * * argv) env["__ETC_PROFILE_SOURCED"] = "1"; } - env["NIX_BUILD_TOP"] = env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = *tmp; + 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); From d1dd7abbf008a0744debe2a13fb2f5a1c689007c Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 10 Jun 2024 20:50:35 +0200 Subject: [PATCH 6/6] mention the actual meaning of FODs in the glossary (#10888) * mention the actual meaning of FODs in the glossary Co-authored-by: Alex Groleau Co-authored-by: Daniel Baker Co-authored-by: Robert Hensing --- doc/manual/src/glossary.md | 5 ++--- doc/manual/src/language/advanced-attributes.md | 15 ++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/manual/src/glossary.md b/doc/manual/src/glossary.md index 55ad9e1c2..4c9b2c52e 100644 --- a/doc/manual/src/glossary.md +++ b/doc/manual/src/glossary.md @@ -71,10 +71,9 @@ [`__contentAddressed`](./language/advanced-attributes.md#adv-attr-__contentAddressed) attribute set to `true`. -- [fixed-output derivation]{#gloss-fixed-output-derivation} +- [fixed-output derivation]{#gloss-fixed-output-derivation} (FOD) - A derivation which includes the - [`outputHash`](./language/advanced-attributes.md#adv-attr-outputHash) attribute. + A [derivation] where a cryptographic hash of the [output] is determined in advance using the [`outputHash`](./language/advanced-attributes.md#adv-attr-outputHash) attribute, and where the [`builder`](@docroot@/language/derivations.md#attr-builder) executable has access to the network. - [store]{#gloss-store} diff --git a/doc/manual/src/language/advanced-attributes.md b/doc/manual/src/language/advanced-attributes.md index 113062db1..70ec06f57 100644 --- a/doc/manual/src/language/advanced-attributes.md +++ b/doc/manual/src/language/advanced-attributes.md @@ -120,12 +120,11 @@ Derivations can declare some infrequently used optional attributes. configuration setting. - [`outputHash`]{#adv-attr-outputHash}; [`outputHashAlgo`]{#adv-attr-outputHashAlgo}; [`outputHashMode`]{#adv-attr-outputHashMode}\ - These attributes declare that the derivation is a so-called - *fixed-output derivation*, which means that a cryptographic hash of - the output is already known in advance. When the build of a - fixed-output derivation finishes, Nix computes the cryptographic - hash of the output and compares it to the hash declared with these - attributes. If there is a mismatch, the build fails. + These attributes declare that the derivation is a so-called *fixed-output derivation* (FOD), which means that a cryptographic hash of the output is already known in advance. + + As opposed to regular derivations, the [`builder`] executable of a fixed-output derivation has access to the network. + Nix computes a cryptographic hash of its output and compares that to the hash declared with these attributes. + If there is a mismatch, the derivation fails. The rationale for fixed-output derivations is derivations such as those produced by the `fetchurl` function. This function downloads a @@ -279,7 +278,9 @@ Derivations can declare some infrequently used optional attributes. > **Note** > - > If set to `false`, the [`builder`](./derivations.md#attr-builder) should be able to run on the system type specified in the [`system` attribute](./derivations.md#attr-system), since the derivation cannot be substituted. + > If set to `false`, the [`builder`] should be able to run on the system type specified in the [`system` attribute](./derivations.md#attr-system), since the derivation cannot be substituted. + + [`builder`]: ./derivations.md#attr-builder - [`__structuredAttrs`]{#adv-attr-structuredAttrs}\ If the special attribute `__structuredAttrs` is set to `true`, the other derivation