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 }"

```
This commit is contained in:
Artturin 2023-01-06 22:19:06 +02:00
parent 272763effc
commit 88f36d2694
2 changed files with 11 additions and 7 deletions

View file

@ -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

View file

@ -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 = {