nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 37 lines 1.6 kB view raw
1updateSourceDateEpoch() { 2 local path="$1" 3 # Avoid passing option-looking directory to find. The example is diffoscope-269: 4 # https://salsa.debian.org/reproducible-builds/diffoscope/-/issues/378 5 [[ $path == -* ]] && path="./$path" 6 7 # Get the last modification time of all regular files, sort them, 8 # and get the most recent. Maybe we should use 9 # https://github.com/0-wiz-0/findnewest here. 10 local -a res=($(find "$path" -type f -not -newer "$NIX_BUILD_TOP/.." -printf '%T@ "%p"\0' \ 11 | sort -n --zero-terminated | tail -n1 --zero-terminated | head -c -1)) 12 local time="${res[0]//\.[0-9]*/}" # remove the fraction part 13 local newestFile="${res[1]}" 14 15 # Update $SOURCE_DATE_EPOCH if the most recent file we found is newer. 16 if [ "${time:-0}" -gt "$SOURCE_DATE_EPOCH" ]; then 17 echo "setting SOURCE_DATE_EPOCH to timestamp $time of file $newestFile" 18 export SOURCE_DATE_EPOCH="$time" 19 20 # Warn if the new timestamp is too close to the present. This 21 # may indicate that we were being applied to a file generated 22 # during the build, or that an unpacker didn't restore 23 # timestamps properly. 24 local now="$(date +%s)" 25 if [ "$time" -gt $((now - 60)) ]; then 26 echo "warning: file $newestFile may be generated; SOURCE_DATE_EPOCH may be non-deterministic" 27 fi 28 fi 29} 30 31postUnpackHooks+=(_updateSourceDateEpochFromSourceRoot) 32 33_updateSourceDateEpochFromSourceRoot() { 34 if [ -n "$sourceRoot" ]; then 35 updateSourceDateEpoch "$sourceRoot" 36 fi 37}