2512.nix (3477B)
1 { 2 fetchFromGitHub, 3 pkgsBuildBuild, 4 lib, 5 cpio 6 }: 7 let 8 src = fetchFromGitHub { 9 name = "openwrt-source"; 10 repo = "openwrt"; 11 owner = "openwrt"; 12 rev = "8303e9b2a004a6c3754aaa1edb32cfc7c0cfe55b"; 13 hash = "sha256-ZsfCncw0oIhtjKvDQfYmaE/LYEa5eikq1xSjQPU1BdE="; 14 }; 15 # we don't use different kernel versions for monolith and mac80211 as 16 # openwrt does, so we also need an older openwrt version with 17 # the wireless patches that correspond to 6.12.x 18 oldSrc = fetchFromGitHub { 19 name = "openwrt-source"; 20 repo = "openwrt"; 21 owner = "openwrt"; 22 rev = "a85059438f2caed0d01a87fce9b8bd5bed134bb2"; 23 hash = "sha256-WE6MFvtr2mTnnVL9EqlGmWXEoYb6J24C74kK4bNw5qM="; 24 }; 25 kernelVersion = "6.12.113"; 26 kernelSeries = lib.versions.majorMinor kernelVersion; 27 doPatch = family: '' 28 tar -C ${src}/target/linux/generic/files -cf - . | tar xpf - 29 chmod -R u+w . 30 tar -C ${src}/target/linux/${family}/files -cf - . | tar xpf - 31 chmod -R u+w . 32 test -d ${src}/target/linux/${family}/files-${kernelSeries}/ && ( tar -C ${src}/target/linux/${family}/files-${kernelSeries} -cf - . | tar xpf -) 33 chmod -R u+w . 34 35 ensure_patch() { 36 echo Applying $1 37 # skip patches which are already applied by testing if they 38 # can be dry-run in reverse 39 patch --batch --forward -p1 < $1 || 40 patch --batch --reverse --dry-run -p1 < $1 41 42 } 43 patches() { 44 for i in $* ; do 45 ensure_patch $i 46 done 47 } 48 49 patches ${src}/target/linux/generic/backport-${kernelSeries}/*.patch 50 patches ${src}/target/linux/generic/pending-${kernelSeries}/*.patch 51 patches ${src}/target/linux/generic/hack-${kernelSeries}/*.patch 52 patches ${src}/target/linux/${family}/patches-${kernelSeries}/*.patch 53 ${lib.optionalString (family == "mediatek") "patches ${./fixup-731-v6.18-net-mediatek-wed-Introduce-MT7992-WED-support-to-MT7.patch}"} 54 55 for kconfig in $(find drivers/net/wireless/ -name Kconfig); do 56 sed -i.bak -E -e '/^((\s+))tristate/a\ 57 \tdepends on m' $kconfig 58 done 59 60 echo doPatch ${family} done 61 ''; 62 in 63 { 64 inherit src; 65 66 # The kernel sources typically used with this version of openwrt 67 # You can find this in `include/kernel-5.15` or similar in the 68 # openwrt sources 69 kernelSrc = pkgsBuildBuild.fetchurl { 70 name = "linux.tar.gz"; 71 url = "https://cdn.kernel.org/pub/linux/kernel/v${lib.versions.major kernelVersion}.x/linux-${kernelVersion}.tar.gz"; 72 hash = "sha256-QT99n8u9hcmAmHuMy2+yR+nKvZtf3MKS4twdVfQotj0="; 73 }; 74 inherit kernelVersion; 75 76 applyPatches.ath79 = doPatch "ath79"; 77 applyPatches.ramips = doPatch "ramips"; 78 applyPatches.mediatek = doPatch "mediatek"; # aarch64 79 applyPatches.mvebu = doPatch "mvebu"; # arm 80 81 applyPatches.rt2x00 = '' 82 PATH=${pkgsBuildBuild.patchutils}/bin:$PATH 83 for i in ${oldSrc}/package/kernel/mac80211/patches/rt2x00/6*.patch ; do 84 fixed=$(basename $i).fixed 85 sed '/depends on m/d' < $i | sed 's/CPTCFG_/CONFIG_/g' | recountdiff | filterdiff -x '*/local-symbols' > $fixed 86 echo Applying $fixed 87 88 case $fixed in 89 606-*|607-*) 90 ;; 91 611-*) 92 filterdiff -x '*/rt2x00.h' < $fixed | patch --forward -p1 93 ;; 94 609-*) 95 sed < $fixed -e 's/ralink,rt7620-wmac/ralink,rt7620-wifi/g' -e 's/ralink,rt2880-wmac/ralink,rt2880-wifi/g' | patch --forward -p1 96 ;; 97 *) 98 cat $fixed | patch --forward -p1 99 ;; 100 esac 101 done 102 ''; 103 }