1 updateSourceDateEpoch
() {
4 # Get the last modification time of all regular files, sort them,
5 # and get the most recent. Maybe we should use
6 # https://github.com/0-wiz-0/findnewest here.
7 local -a res
=($
(find "$path" -type f
-not -newer "$NIX_BUILD_TOP/.." -printf '%T@ %p\0' \
8 |
sort -n --zero-terminated |
tail -n1 --zero-terminated |
head -c -1))
9 local time="${res[0]//\.[0-9]*/}" # remove the fraction part
10 local newestFile
="${res[1]}"
12 # Update $SOURCE_DATE_EPOCH if the most recent file we found is newer.
13 if [ "${time:-0}" -gt "$SOURCE_DATE_EPOCH" ]; then
14 echo "setting SOURCE_DATE_EPOCH to timestamp $time of file $newestFile"
15 export SOURCE_DATE_EPOCH
="$time"
17 # Warn if the new timestamp is too close to the present. This
18 # may indicate that we were being applied to a file generated
19 # during the build, or that an unpacker didn't restore
20 # timestamps properly.
21 local now
="$(date +%s)"
22 if [ "$time" -gt $
((now
- 60)) ]; then
23 echo "warning: file $newestFile may be generated; SOURCE_DATE_EPOCH may be non-deterministic"
28 postUnpackHooks
+=(_updateSourceDateEpochFromSourceRoot
)
30 _updateSourceDateEpochFromSourceRoot
() {
31 if [ -n "$sourceRoot" ]; then
32 updateSourceDateEpoch
"$sourceRoot"