liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

2512.nix (3527B)


      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 = "v25.12.3";
     13     hash = "sha256-POlPwrWHH6UPO6I0O9baFED7959vPkuoL1cZITktG9k=";
     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 = "c8eacec725dce34c7b621f00c9bce814fe413759";
     23     hash = "sha256-YTfAWmFPXPXFQ56QGRLgCc/QY+RndOdVdcgtBaZsh1E=";
     24   };
     25   kernelVersion = "6.12.85";
     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     mkdir backport_patches
     61     for f in ${oldSrc}/package/kernel/mac80211/patches/*.*; do
     62       out=backport_patches/`basename $f`
     63       sed < $f 's/CPTCFG_/CONFIG_/g' > $out
     64       ensure_patch $out
     65     done
     66   '';
     67 in
     68 {
     69   inherit src;
     70 
     71   # The kernel sources typically used with this version of openwrt
     72   # You can find this in `include/kernel-5.15` or similar in the
     73   # openwrt sources
     74   kernelSrc = pkgsBuildBuild.fetchurl {
     75     name = "linux.tar.gz";
     76     url = "https://cdn.kernel.org/pub/linux/kernel/v${lib.versions.major kernelVersion}.x/linux-${kernelVersion}.tar.gz";
     77     hash = "sha256-bRV7pa8ZHuWf7oSy4VZzqqjuI0emK1Vjr1wnmjg4M+s=";
     78   };
     79   inherit kernelVersion;
     80 
     81   applyPatches.ath79 = doPatch "ath79";
     82   applyPatches.ramips = doPatch "ramips";
     83   applyPatches.mediatek = doPatch "mediatek"; # aarch64
     84   applyPatches.mvebu = doPatch "mvebu"; # arm
     85 
     86   applyPatches.rt2x00 = ''
     87     PATH=${pkgsBuildBuild.patchutils}/bin:$PATH
     88     for i in ${src}/package/kernel/mac80211/patches/rt2x00/6*.patch ; do
     89       fixed=$(basename $i).fixed
     90       sed '/depends on m/d'  < $i | sed 's/CPTCFG_/CONFIG_/g' | recountdiff | filterdiff -x '*/local-symbols' > $fixed
     91       case $fixed in
     92         606-*)
     93           ;;
     94         611-*)
     95           filterdiff -x '*/rt2x00.h' < $fixed | patch --forward -p1
     96           ;;
     97         601-*|607-*)
     98           filterdiff -x '*/rt2x00_platform.h' < $fixed | patch --forward -p1
     99           ;;
    100         *)
    101           cat $fixed | patch --forward -p1
    102           ;;
    103       esac
    104     done
    105   '';
    106 }