third_party/linux: make build reproducible

Linux includes a timestamp, username and hostname in /proc/version and
other places. We need to set these to a fixed value to make the build
reproducible. For the timestamp, we can use the modified date of any
file in the source archive; all files in the archive have the same
timestamp.

See Linux Documentation/kbuild/reproducible-builds.rst

Change-Id: If50bb5a8ee73e5bc37e95a5d38e7ee87d85518a5
Reviewed-on: https://review.monogon.dev/c/monogon/+/4417
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/third_party/linux/def.bzl b/third_party/linux/def.bzl
index 8e5878d..9dd544c 100644
--- a/third_party/linux/def.bzl
+++ b/third_party/linux/def.bzl
@@ -117,6 +117,8 @@
         command = toolchain_cmd + """
             export BISON_PKGDATADIR=$(realpath $(dirname $BISON))/../share/bison
             builddir=$(mktemp -d)
+            # All source files have the same timestamp, take it from an arbitrary file.
+            build_timestamp=$(date -r {kernel_src}/README)
 
             mkdir {kernel_src}/.bin
             cp {kconfig} $builddir/.config
@@ -134,6 +136,9 @@
                 HOSTREADELF="$HOSTREADELF" HOSTCFLAGS="$HOSTCFLAGS" \
                 HOSTLDFLAGS="$HOSTLDFLAGS" \
                 \
+                KBUILD_BUILD_USER=builder \
+                KBUILD_BUILD_HOST=monogon \
+                KBUILD_BUILD_TIMESTAMP="$build_timestamp" \
                 KBUILD_OUTPUT="$builddir" \
                 ARCH="{target_arch}" \
                 olddefconfig {target}