liminix

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

default.nix (5040B)


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