This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
prepare-source.nix
59 lines (53 loc) · 2.46 KB
/
prepare-source.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{ stdenv
, buildPackages
, socFamily ? null
, ledeSrc
, kernelSrc
, patchutils
, version
} :
let versionScalar = v :
let nth = n : builtins.elemAt v n;
in (nth 2) + ((nth 1) * 1000) + ((nth 0) * 1000000);
versionExceeds = a : b : (versionScalar a) > (versionScalar b) ;
lib = stdenv.lib; in
stdenv.mkDerivation rec {
name = "kernel-source";
phases = [ "unpackPhase" "patchFromLede" "patchPhase" "buildPhase" "installPhase" ];
src = kernelSrc;
nativeBuildInputs = [ patchutils ];
patchFromLede = let
majmin = "${toString (builtins.elemAt version 0)}.${toString (builtins.elemAt version 1)}";
in ''
q_apply() {
if test -d $1 ; then find $1 -type f | sort | xargs -n1 patch -N -p1 -i ;fi
}
cp -dRv ${ledeSrc}/target/linux/generic/files/* .
cp -dRv ${ledeSrc}/target/linux/ramips/files-${majmin}/* .
cp -dRv ${ledeSrc}/target/linux/ar71xx/files/* .
q_apply ${ledeSrc}/target/linux/generic/backport-${majmin}/
q_apply ${ledeSrc}/target/linux/generic/pending-${majmin}/
q_apply ${ledeSrc}/target/linux/generic/hack-${majmin}/
cat ${ledeSrc}/package/kernel/mac80211/patches/rt2x00/601-*.patch | filterdiff -x '*/local-symbols' -x '*/rt2x00_platform.h' | patch -p1 -N
cat ${ledeSrc}/package/kernel/mac80211/patches/rt2x00/602-*.patch | sed 's/CPTCFG_/CONFIG_/g' | filterdiff -x '*/local-symbols' | patch -p1 -N
cat ${ledeSrc}/package/kernel/mac80211/patches/rt2x00/603-*.patch | patch -p1 -N
cat ${ledeSrc}/package/kernel/mac80211/patches/rt2x00/604-*.patch | patch -p1 -N
cat ${ledeSrc}/package/kernel/mac80211/patches/rt2x00/609-*.patch | patch -p1 -N
${lib.optionalString (! isNull socFamily)
"q_apply ${ledeSrc}/target/linux/${socFamily}/patches-${majmin}/"}
chmod -R +w . # */
'';
patches = [ ./kernel-ath79-wdt-at-boot.patch
./kernel-lzma-command.patch
./kexec_copy_from_user_return.patch
] ++ lib.optional (! versionExceeds version [4 10 0]) ./kernel-memmap-param.patch
++ lib.optional (versionExceeds version [4 10 0]) ./kexec-fdt.patch;
patchFlags = [ "-p1" ];
buildPhase = ''
substituteInPlace scripts/ld-version.sh --replace /usr/bin/awk ${buildPackages.pkgs.gawk}/bin/awk
substituteInPlace Makefile --replace /bin/pwd ${buildPackages.pkgs.coreutils}/bin/pwd
'';
installPhase = ''
cp -a . $out
'';
}