From 88f36d2694840816f01ee1436867533669757437 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 6 Jan 2023 22:19:06 +0200 Subject: [PATCH] gzip: make reproducible when GZIP_NO_TIMESTAMPS is set the logic can be tested with ``` $ GZIP_NO_TIMESTAMPS=1 && echo "${GZIP_NO_TIMESTAMPS:+-n }" -n $ unset GZIP_NO_TIMESTAMPS && echo "${GZIP_NO_TIMESTAMPS:+-n }" ``` --- pkgs/stdenv/generic/setup.sh | 4 ++++ pkgs/tools/compression/gzip/default.nix | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index c6cdb6c3df75..4047d8f4ea29 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1348,6 +1348,10 @@ showPhaseFooter() { genericBuild() { + # variable used by our gzip wrapper to add -n. + # gzip is in common-path.nix and is added to nix-shell but we only want to change its behaviour in nix builds. do not move to a setupHook in gzip. + export GZIP_NO_TIMESTAMPS=1 + if [ -f "${buildCommandPath:-}" ]; then source "$buildCommandPath" return diff --git a/pkgs/tools/compression/gzip/default.nix b/pkgs/tools/compression/gzip/default.nix index 771188a98cd9..4aa52ff020f4 100644 --- a/pkgs/tools/compression/gzip/default.nix +++ b/pkgs/tools/compression/gzip/default.nix @@ -1,7 +1,7 @@ { lib, stdenv , fetchurl +, makeWrapper , xz -, writeText }: # Note: this package is used for bootstrapping fetchurl, and thus @@ -22,7 +22,7 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; - nativeBuildInputs = [ xz.bin ]; + nativeBuildInputs = [ xz.bin makeWrapper ]; makeFlags = [ "SHELL=/bin/sh" @@ -40,12 +40,12 @@ stdenv.mkDerivation rec { preFixup = '' sed -i '1{;/#!\/bin\/sh/aPATH="'$out'/bin:$PATH" }' $out/bin/* - ''; - - # set GZIP env variable to "-n" to stop gzip from adding timestamps + '' + # run gzip with "-n" when $GZIP_NO_TIMESTAMPS (set by stdenv's setup.sh) is set to stop gzip from adding timestamps # to archive headers: https://github.com/NixOS/nixpkgs/issues/86348 - setupHook = writeText "setup-hook" '' - export GZIP="-n" + + '' + wrapProgram $out/bin/gzip \ + --add-flags "\''${GZIP_NO_TIMESTAMPS:+-n}" ''; meta = {