diff --git a/pkgs/by-name/fb/fbthrift/package.nix b/pkgs/by-name/fb/fbthrift/package.nix index 13bd7fe6b278..71e759c7def1 100644 --- a/pkgs/by-name/fb/fbthrift/package.nix +++ b/pkgs/by-name/fb/fbthrift/package.nix @@ -43,6 +43,10 @@ stdenv.mkDerivation (finalAttrs: { }; patches = [ + # Map `$NIX_BUILD_TOP` to `/build` in the Thrift compiler output to + # avoid reproducibility issues on Darwin. + ./scrub-build-directory-from-output.patch + # Remove a line that breaks the build due to the CMake classic of # incorrect path concatenation. ./remove-cmake-install-rpath.patch diff --git a/pkgs/by-name/fb/fbthrift/scrub-build-directory-from-output.patch b/pkgs/by-name/fb/fbthrift/scrub-build-directory-from-output.patch new file mode 100644 index 000000000000..9fdfc77f2ead --- /dev/null +++ b/pkgs/by-name/fb/fbthrift/scrub-build-directory-from-output.patch @@ -0,0 +1,36 @@ +diff --git a/thrift/compiler/generate/t_mstch_cpp2_generator.cc b/thrift/compiler/generate/t_mstch_cpp2_generator.cc +index d232df5158..96d15efbda 100644 +--- a/thrift/compiler/generate/t_mstch_cpp2_generator.cc ++++ b/thrift/compiler/generate/t_mstch_cpp2_generator.cc +@@ -1116,6 +1116,13 @@ + mstch::node autogen_path() { + std::string path = service_->program()->path(); + std::replace(path.begin(), path.end(), '\\', '/'); ++ // Ensure output reproducibility for Nix builds. ++ if (auto nix_build_top = std::getenv("NIX_BUILD_TOP")) { ++ auto prefix = std::string(nix_build_top) + "/"; ++ if (path.starts_with(prefix)) { ++ path.replace(0, prefix.length(), "/build/"); ++ } ++ } + return path; + } + mstch::node cpp_includes() { +diff --git a/thrift/compiler/generate/t_whisker_generator.cc b/thrift/compiler/generate/t_whisker_generator.cc +index 99a6ac14af..fa91a05247 100644 +--- a/thrift/compiler/generate/t_whisker_generator.cc ++++ b/thrift/compiler/generate/t_whisker_generator.cc +@@ -572,6 +572,13 @@ + // use posix path separators, even on windows, for autogen comment + // to avoid spurious fixture regen diffs + std::replace(path.begin(), path.end(), '\\', '/'); ++ // Ensure output reproducibility for Nix builds. ++ if (auto nix_build_top = std::getenv("NIX_BUILD_TOP")) { ++ auto prefix = std::string(nix_build_top) + "/"; ++ if (path.starts_with(prefix)) { ++ path.replace(0, prefix.length(), "/build/"); ++ } ++ } + return path; + }); + def.property("namespaces", [&](const t_program& self) -> map::ptr {