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 {
