default.nix (5463B)
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; 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 = { 57 # XXX find a better name for this 58 WLAN_VENDOR_RALINK = "y"; 59 WLAN_VENDOR_MEDIATEK = "y"; 60 MT7603E = "y"; 61 }; 62 63 mt7915e.kconfig = { 64 MT7915E = "m"; 65 }; 66 mt7615e.kconfig = { 67 MT7615E = "m"; 68 MT7622_WMAC = "y"; 69 }; 70 mac80211_hwsim.kconfig = { 71 MAC80211_HWSIM = "y"; 72 }; 73 }; 74 kconfig = 75 (foldl (config: d: (config // configs.${d}.kconfig)) { 76 WLAN = "y"; 77 CFG80211 = "m"; 78 MAC80211 = "m"; 79 80 # (nixwrt comment) I am reluctant to have to enable this but 81 # can't transmit on 5GHz bands without it (they are all marked 82 # NO-IR) 83 CFG80211_CERTIFICATION_ONUS = "y"; 84 # (nixwrt comment) can't get signed regdb to work rn, it just 85 # gives me "loaded regulatory.db is malformed or signature is 86 # missing/invalid" 87 CFG80211_REQUIRE_SIGNED_REGDB = "n"; # depends on ONUS 88 89 CFG80211_CRDA_SUPPORT = "n"; 90 91 MAC80211_MESH = "y"; 92 } drivers) 93 // extraConfig; 94 95 writeConfig = 96 name: config: 97 writeText name ( 98 builtins.concatStringsSep "\n" ( 99 lib.mapAttrsToList ( 100 name: value: (if value == "n" then "# CPTCFG_${name} is not set" else "CPTCFG_${name}=${value}") 101 ) config 102 ) 103 ); 104 kconfigFile = writeConfig "backports_kconfig" kconfig; 105 src = kernel-backport; 106 CROSS_COMPILE = stdenv.cc.bintools.targetPrefix; 107 CC = "${buildPackages.stdenv.cc}/bin/gcc"; 108 module = stdenv.mkDerivation { 109 name = "mac80211"; 110 inherit src; 111 112 hardeningDisable = [ "all" ]; 113 nativeBuildInputs = 114 [ buildPackages.stdenv.cc ] 115 ++ (with buildPackages.pkgs; [ 116 bc 117 bison 118 flex 119 pkg-config 120 openssl 121 which 122 kmod 123 cpio 124 ]); 125 inherit CC CROSS_COMPILE; 126 ARCH = arch; 127 dontStrip = true; 128 dontPatchELF = true; 129 phases = [ 130 "unpackPhase" 131 "patchFromOpenwrt" 132 "configurePhase" 133 "checkConfigurationPhase" 134 "buildPhase" 135 "installPhase" 136 ]; 137 138 patchFromOpenwrt = '' 139 mac80211=${openwrtSrc}/package/kernel/mac80211 140 echo $mac80211 141 for i in $(ls $mac80211/patches/build/ | grep -v 015-ipw200); do 142 echo $i; (patch -p1 -N <$mac80211/patches/build/$i) 143 done 144 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 145 echo $i; (patch -p1 -N <$mac80211/patches/rt2x00/$i) 146 done 147 for i in $mac80211/patches/ath/*; do echo $i; (patch -p1 -N <$i) ;done 148 for i in $mac80211/patches/ath9k/*; do echo $i; (patch -p1 -N <$i) ;done 149 ''; 150 151 configurePhase = '' 152 cp ${kconfigFile} .config 153 cp ${kconfigFile} .config.orig 154 chmod +w .config .config.orig 155 make V=1 CC=${CC} SHELL=`type -p bash` LEX=flex KLIB_BUILD=${klibBuild} olddefconfig 156 ''; 157 158 checkConfigurationPhase = '' 159 echo Checking required config items: 160 if comm -2 -3 <(awk -F= '/CPTCFG/ {print $1}' ${kconfigFile} |sort) <(awk -F= '/CPTCFG/ {print $1}' .config|sort) |grep '.' ; then 161 echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n" 162 exit 0 163 fi 164 echo "OK" 165 ''; 166 167 KBUILD_BUILD_HOST = "liminix.builder"; 168 169 buildPhase = '' 170 patchShebangs scripts/ 171 echo ${klibBuild} 172 make V=1 SHELL=`type -p bash` KLIB_BUILD=${klibBuild} modules 173 find . -name \*.ko | xargs ${CROSS_COMPILE}strip --strip-debug 174 ''; 175 176 installPhase = '' 177 mkdir -p $out/lib/modules/0.0 178 find . -name \*.ko | cpio --make-directories -p $out/lib/modules/0.0 179 depmod -b $out -v 0.0 180 touch $out/load.sh 181 for i in ${ 182 lib.concatStringsSep " " ( 183 map ( 184 d: 185 let 186 c = { 187 module = d; 188 } // configs.${d}; 189 in 190 c.module 191 ) drivers 192 ) 193 }; do 194 modprobe -S 0.0 -d $out --show-depends $i >> $out/load.sh 195 done 196 tac < $out/load.sh | sed 's/^insmod/rmmod/g' > $out/unload.sh 197 ''; 198 }; 199 in 200 oneshot { 201 name = "wlan.module"; 202 up = "sh ${module}/load.sh"; 203 down = "sh ${module}/unload.sh"; 204 }