liminix

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

default.nix (5461B)


      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     ]
    116     ++ (with buildPackages.pkgs; [
    117       bc
    118       bison
    119       flex
    120       pkg-config
    121       openssl
    122       which
    123       kmod
    124       cpio
    125     ]);
    126     inherit CC CROSS_COMPILE;
    127     ARCH = arch;
    128     dontStrip = true;
    129     dontPatchELF = true;
    130     phases = [
    131       "unpackPhase"
    132       "patchFromOpenwrt"
    133       "configurePhase"
    134       "checkConfigurationPhase"
    135       "buildPhase"
    136       "installPhase"
    137     ];
    138 
    139     patchFromOpenwrt = ''
    140       mac80211=${openwrtSrc}/package/kernel/mac80211
    141       echo $mac80211
    142       for i in $(ls $mac80211/patches/build/ | grep -v 015-ipw200); do
    143         echo $i; (patch -p1 -N <$mac80211/patches/build/$i)
    144       done
    145       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
    146         echo $i; (patch -p1 -N <$mac80211/patches/rt2x00/$i)
    147       done
    148       for i in $mac80211/patches/ath/*; do echo $i; (patch -p1 -N <$i) ;done
    149       for i in $mac80211/patches/ath9k/*; do echo $i; (patch -p1 -N <$i) ;done
    150     '';
    151 
    152     configurePhase = ''
    153       cp ${kconfigFile} .config
    154       cp ${kconfigFile} .config.orig
    155       chmod +w .config .config.orig
    156       make V=1 CC=${CC} SHELL=`type -p bash` LEX=flex KLIB_BUILD=${klibBuild} olddefconfig
    157     '';
    158 
    159     checkConfigurationPhase = ''
    160       echo Checking required config items:
    161       if comm -2 -3 <(awk -F= '/CPTCFG/ {print $1}' ${kconfigFile} |sort) <(awk -F= '/CPTCFG/ {print $1}' .config|sort) |grep '.'    ; then
    162         echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n"
    163         exit 0
    164       fi
    165       echo "OK"
    166     '';
    167 
    168     KBUILD_BUILD_HOST = "liminix.builder";
    169 
    170     buildPhase = ''
    171       patchShebangs scripts/
    172       echo  ${klibBuild}
    173       make V=1 SHELL=`type -p bash` KLIB_BUILD=${klibBuild} modules
    174       find . -name \*.ko | xargs ${CROSS_COMPILE}strip --strip-debug
    175     '';
    176 
    177     installPhase = ''
    178       mkdir -p $out/lib/modules/0.0
    179       find . -name \*.ko | cpio --make-directories -p $out/lib/modules/0.0
    180       depmod -b $out -v 0.0
    181       touch $out/load.sh
    182       for i in ${
    183         lib.concatStringsSep " " (
    184           map (
    185             d:
    186             let
    187               c = {
    188                 module = d;
    189               }
    190               // configs.${d};
    191             in
    192             c.module
    193           ) drivers
    194         )
    195       }; do
    196         modprobe -S 0.0 -d $out --show-depends $i >> $out/load.sh
    197       done
    198       tac < $out/load.sh | sed 's/^insmod/rmmod/g' > $out/unload.sh
    199     '';
    200   };
    201 in
    202 oneshot {
    203   name = "wlan.module";
    204   up = "sh ${module}/load.sh";
    205   down = "sh ${module}/unload.sh";
    206 }