@@ -88,7 +88,10 @@ let
8888
8989 inherit src;
9090
91− patches = map (p: p.patch) kernelPatches;
91+ patches =
92+ map (p: p.patch) kernelPatches
93+ # Required for deterministic builds along with some postPatch magic.
94+ ++ optional (stdenv.lib.versionAtLeast version "4.13") ./randstruct-provide-seed.patch;
9295
9396 prePatch = ''
9497 for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do
@@ -99,6 +102,19 @@ let
99102 sed -i scripts/ld-version.sh -e "s|/usr/bin/awk|${buildPackages.gawk}/bin/awk|"
100103 '';
101104
105+ postPatch = ''
106+ # Set randstruct seed to a deterministic but diversified value. Note:
107+ # we could have instead patched gen-random-seed.sh to take input from
108+ # the buildFlags, but that would require also patching the kernel's
109+ # toplevel Makefile to add a variable export. This would be likely to
110+ # cause future patch conflicts.
111+ if [ -f scripts/gcc-plugins/gen-random-seed.sh ]; then
112+ substituteInPlace scripts/gcc-plugins/gen-random-seed.sh \
113+ --replace NIXOS_RANDSTRUCT_SEED \
114+ $(echo ${src} ${configfile} | sha256sum | cut -d ' ' -f 1 | tr -d '\n')
115+ fi
116+ '';
117+
102118 configurePhase = ''
103119 runHook preConfigure
104120