default.nix (5373B)
1 # make out-of-tree modules given a backported kernel source tree 2 3 { 4 extraConfig ? {} 5 , drivers ? [ ] 6 , kernel-backport 7 , stdenv 8 , writeText 9 , klibBuild ? null 10 , buildPackages 11 , fetchFromGitHub 12 13 , liminix 14 , lib 15 }: 16 let 17 arch = stdenv.hostPlatform.linuxArch; 18 openwrtSrc = fetchFromGitHub { 19 name = "openwrt-source"; 20 repo = "openwrt"; 21 owner = "openwrt"; 22 rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; 23 hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; 24 }; 25 inherit (liminix.services) oneshot longrun; 26 inherit (lib.lists) foldl; 27 configs = { 28 ath9k.kconfig = { 29 WLAN_VENDOR_ATH = "y"; 30 ATH_COMMON = "m"; 31 ATH9K = "m"; 32 ATH9K_AHB = "y"; 33 BACKPORTED_ATH9K_AHB = "y"; 34 }; 35 ath9k_pci = { 36 module = "ath9k"; 37 kconfig = { 38 WLAN_VENDOR_ATH = "y"; 39 ATH_COMMON = "m"; 40 ATH9K = "m"; 41 ATH9K_PCI = "y"; 42 }; 43 }; 44 ath10k_pci.kconfig = { 45 WLAN_VENDOR_ATH = "y"; 46 ATH_COMMON = "m"; 47 ATH10K = "m"; 48 ATH10K_PCI = "y"; 49 ATH10K_DEBUG = "y"; 50 }; 51 rt2800soc.kconfig = { 52 WLAN_VENDOR_RALINK = "y"; 53 RT2800SOC = "m"; 54 RT2X00 = "m"; 55 }; 56 mt7603e.kconfig = { # XXX find a better name for this 57 WLAN_VENDOR_RALINK = "y"; 58 WLAN_VENDOR_MEDIATEK = "y"; 59 MT7603E = "y"; 60 }; 61 62 mt7915e.kconfig = { 63 MT7915E = "m"; 64 }; 65 mt7615e.kconfig = { 66 MT7615E = "m"; 67 MT7622_WMAC = "y"; 68 }; 69 mac80211_hwsim.kconfig = { 70 MAC80211_HWSIM = "y"; 71 }; 72 }; 73 kconfig = (foldl (config: d: (config // configs.${d}.kconfig)) { 74 WLAN = "y"; 75 CFG80211 = "m"; 76 MAC80211 = "m"; 77 78 # (nixwrt comment) I am reluctant to have to enable this but 79 # can't transmit on 5GHz bands without it (they are all marked 80 # NO-IR) 81 CFG80211_CERTIFICATION_ONUS = "y"; 82 # (nixwrt comment) can't get signed regdb to work rn, it just 83 # gives me "loaded regulatory.db is malformed or signature is 84 # missing/invalid" 85 CFG80211_REQUIRE_SIGNED_REGDB = "n"; # depends on ONUS 86 87 CFG80211_CRDA_SUPPORT = "n"; 88 89 MAC80211_MESH = "y"; 90 } drivers) // extraConfig; 91 92 writeConfig = name : config: writeText name 93 (builtins.concatStringsSep 94 "\n" 95 (lib.mapAttrsToList 96 (name: value: (if value == "n" then "# CPTCFG_${name} is not set" else "CPTCFG_${name}=${value}")) 97 config 98 )); 99 kconfigFile = writeConfig "backports_kconfig" kconfig; 100 src = kernel-backport; 101 CROSS_COMPILE = stdenv.cc.bintools.targetPrefix; 102 CC = "${buildPackages.stdenv.cc}/bin/gcc"; 103 module = stdenv.mkDerivation { 104 name = "mac80211"; 105 inherit src; 106 107 hardeningDisable = ["all"]; 108 nativeBuildInputs = [buildPackages.stdenv.cc] ++ 109 (with buildPackages.pkgs; 110 [bc bison flex pkg-config openssl 111 which kmod cpio 112 ]); 113 inherit CC CROSS_COMPILE; 114 ARCH = arch; 115 dontStrip = true; 116 dontPatchELF = true; 117 phases = [ 118 "unpackPhase" 119 "patchFromOpenwrt" 120 "configurePhase" 121 "checkConfigurationPhase" 122 "buildPhase" 123 "installPhase" 124 ]; 125 126 patchFromOpenwrt = '' 127 mac80211=${openwrtSrc}/package/kernel/mac80211 128 echo $mac80211 129 for i in $(ls $mac80211/patches/build/ | grep -v 015-ipw200); do 130 echo $i; (patch -p1 -N <$mac80211/patches/build/$i) 131 done 132 for i in $(ls $mac80211/patches/rt2x00/ | grep -v 009-rt2x00-don-t | grep -v 013-rt2x00-set-correct | grep -v 014 | grep -v 015 | grep -v 016); do 133 echo $i; (patch -p1 -N <$mac80211/patches/rt2x00/$i) 134 done 135 for i in $mac80211/patches/ath/*; do echo $i; (patch -p1 -N <$i) ;done 136 for i in $mac80211/patches/ath9k/*; do echo $i; (patch -p1 -N <$i) ;done 137 ''; 138 139 configurePhase = '' 140 cp ${kconfigFile} .config 141 cp ${kconfigFile} .config.orig 142 chmod +w .config .config.orig 143 make V=1 CC=${CC} SHELL=`type -p bash` LEX=flex KLIB_BUILD=${klibBuild} olddefconfig 144 ''; 145 146 checkConfigurationPhase = '' 147 echo Checking required config items: 148 if comm -2 -3 <(awk -F= '/CPTCFG/ {print $1}' ${kconfigFile} |sort) <(awk -F= '/CPTCFG/ {print $1}' .config|sort) |grep '.' ; then 149 echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n" 150 exit 0 151 fi 152 echo "OK" 153 ''; 154 155 KBUILD_BUILD_HOST = "liminix.builder"; 156 157 buildPhase = '' 158 patchShebangs scripts/ 159 echo ${klibBuild} 160 make V=1 SHELL=`type -p bash` KLIB_BUILD=${klibBuild} modules 161 find . -name \*.ko | xargs ${CROSS_COMPILE}strip --strip-debug 162 ''; 163 164 installPhase = '' 165 mkdir -p $out/lib/modules/0.0 166 find . -name \*.ko | cpio --make-directories -p $out/lib/modules/0.0 167 depmod -b $out -v 0.0 168 touch $out/load.sh 169 for i in ${lib.concatStringsSep " " 170 (map 171 (d: let c = { module = d; } // configs.${d} ; 172 in c.module) 173 drivers)}; do 174 modprobe -S 0.0 -d $out --show-depends $i >> $out/load.sh 175 done 176 tac < $out/load.sh | sed 's/^insmod/rmmod/g' > $out/unload.sh 177 ''; 178 }; 179 in oneshot { 180 name = "wlan.module"; 181 up = "sh ${module}/load.sh"; 182 down = "sh ${module}/unload.sh"; 183 }