Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 189 lines 6.1 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 fetchFromGitHub, 6 m4, 7 cmake, 8 perl, 9 writeScript, 10 enableUnstable ? false, 11}: 12 13let 14 stableVersion = "1.4.0"; 15in 16 17stdenv.mkDerivation (finalAttrs: { 18 pname = "ath9k-htc-blobless-firmware"; 19 version = if enableUnstable then "unstable-2022-05-22" else stableVersion; 20 21 src = fetchFromGitHub ( 22 { 23 owner = "qca"; 24 repo = "open-ath9k-htc-firmware"; 25 } 26 // ( 27 if enableUnstable then 28 { 29 rev = "d856466a068afe4069335257c0d28295ff777d92"; 30 hash = "sha256-9OE6qYGABeXjf1r/Depd+811EJ2e8I0Ni5ePHSOh9G4="; 31 } 32 else 33 { 34 rev = finalAttrs.version; 35 hash = "sha256-Q/A0ryIC5E1pt2Sh7o79gxHbe4OgdlrwflOWtxWSS5o="; 36 } 37 ) 38 ); 39 40 postPatch = '' 41 patchShebangs target_firmware/firmware-crc.pl 42 ''; 43 44 nativeBuildInputs = [ 45 m4 46 cmake 47 perl 48 ]; 49 50 env.NIX_CFLAGS_COMPILE = 51 # old libiberty emits fatal warnings 52 "-w" 53 # old gmp fails to compile with newer gcc 54 # FIXME remove when the normal version has moved on 55 + lib.optionalString (!enableUnstable) " -fpermissive"; 56 57 dontUseCmakeConfigure = true; 58 enableParallelBuilding = true; 59 60 # The firmware repository builds its own toolchain, with patches 61 # applied to the xtensa support in both gcc and binutils. 62 preBuild = 63 let 64 inherit (lib) 65 toUpper 66 splitString 67 last 68 listToAttrs 69 pipe 70 ; 71 inherit (builtins) map; 72 urls-and-hashes = import (./. + "/urls-and-hashes-${finalAttrs.version}.nix"); 73 make-links = 74 pipe 75 [ "gcc" "binutils" "gmp" "mpfr" "mpc" ] 76 [ 77 (map ( 78 vname: 79 fetchurl rec { 80 url = urls-and-hashes."${(toUpper vname) + "_URL"}"; 81 sha256 = urls-and-hashes."${(toUpper vname) + "_SUM"}" or ""; 82 name = last (splitString "/" url); 83 } 84 )) 85 (map (v: "ln -sT ${v} toolchain/dl/${v.name}")) 86 (lib.concatStringsSep "\n") 87 ]; 88 in 89 '' 90 mkdir -p toolchain/dl 91 ${make-links} 92 ''; 93 94 makeTargets = [ 95 "toolchain" 96 "firmware" 97 ]; 98 99 installPhase = '' 100 runHook preInstall 101 install -Dt "$out/lib/firmware/ath9k_htc/" target_firmware/*.fw 102 # make symlinks so that firmware will be automatically found 103 ln -s htc_7010.fw "$out/lib/firmware/ath9k_htc/htc_7010-${stableVersion}.fw" 104 ln -s htc_9271.fw "$out/lib/firmware/ath9k_htc/htc_9271-${stableVersion}.fw" 105 runHook postInstall 106 ''; 107 108 passthru = { 109 inherit (finalAttrs) src; 110 updateScript = writeScript "${finalAttrs.pname}-${finalAttrs.version}-updateScript" '' 111 nix-shell '<nixpkgs>' -A ${finalAttrs.pname}${lib.optionalString enableUnstable "-unstable"}.passthru.update \ 112 > pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-${finalAttrs.version}.nix 113 ''; 114 update = stdenv.mkDerivation { 115 name = "${finalAttrs.pname}-${finalAttrs.version}-update"; 116 shellHook = '' 117 echo 'rec {' 118 echo ' BASEDIR="$NIX_BUILD_TOP";' 119 make --dry-run --print-data-base -f ${finalAttrs.src}/Makefile download \ 120 | egrep '^[A-Z]+_(VER|URL|SUM|DIR) = ' \ 121 | sed 's_\([^ ]*\) = \(.*\)_\1 = "\2\";_' \ 122 | tr \( \{ \ 123 | tr \) \} 124 '' 125 # sha256 checksums were not added to upstream's Makefile until 126 # after the 1.4.0 release. The following line is needed for 127 # the `enableUnstable==false` build but not for the 128 # `enableUnstable==true` build. We can remove the lines below 129 # as soon as `enableUnstable==false` points to a version 130 # greater than 1.4.0. 131 + lib.optionalString (finalAttrs.version == "1.4.0") '' 132 echo 'GCC_SUM = "sha256-kuYcbcOgpEnmLXKjgYX9pVAWioZwLeoHEl69PsOZYoI=";' 133 echo 'MPFR_SUM = "sha256-e2bD8T3IOF8IJkyAWFPz4aju2rgHHVgvPmYZccms1f0=";' 134 echo 'MPC_SUM = "sha256-7VqBXP6lJdx3jfDLN0aLnBtVSq8w2TKLFDHKcFt0AP8=";' 135 echo 'GMP_SUM = "sha256-H1iKrMxBu5rtlG+f44Uhwm2LKQ0APF34B/ZWkPKq3sk=";' 136 echo 'BINUTILS_SUM = "sha256-KrLlsD4IbRLGKV+DGtrUaz4UEKOiNJM6Lo+sZssuehk=";' 137 '' 138 + '' 139 echo '}' 140 exit 141 ''; 142 }; 143 }; 144 145 meta = { 146 description = "Blobless, open source wifi firmware for ath9k_htc.ko"; 147 longDescription = '' 148 Firmware for Qualcomm Atheros cards which use the ath9k_htc.ko 149 Linux driver, supporting 802.11 abgn on both 2.4ghz and 5ghz 150 bands, 3x3-antenna MIMO, up to 600mbit/sec. 151 152 Most devices which use this driver are based on the Qualcomm 153 Atheros AR9271 chip, which is a PCIe device. If your device 154 is connected via USB, it will also include a Qualcomm Atheros 155 AR7010, which bridges from a USB gadget interface to a PCIe 156 host interface. This repository includes the firmware for 157 both chips. 158 159 This firmware is completely open source with no blobs, which 160 is quite rare in the wifi world. Wifi chips have their own 161 dedicated general-purpose CPUs. This source code allows you 162 to see what those CPUs are doing and modify their behavior. 163 ''; 164 license = with lib.licenses; [ 165 # see NOTICE.txt for details 166 bsd3 # almost everything; "the ClearBSD licence" 167 gpl2ClasspathPlus # **/*cmnos_printf.c, only three files 168 mit # **/xtos, **/xtensa 169 ]; 170 171 # release 1.4.0 vendors a GMP which uses an ancient version of 172 # autotools that does not work on aarch64 or powerpc. 173 # However, enableUnstable (unreleased upstream) works. 174 /* 175 # disabled until #195294 is merged 176 badPlatforms = 177 with lib.systems.inspect.patterns; 178 lib.optionals (!enableUnstable && lib.versionOlder finalAttrs.version "1.4.1") [ 179 isAarch64 180 isPower64 181 ]; 182 */ 183 184 sourceProvenance = [ lib.sourceTypes.fromSource ]; 185 homepage = "http://lists.infradead.org/mailman/listinfo/ath9k_htc_fw"; 186 downloadPage = "https://github.com/qca/open-ath9k-htc-firmware"; 187 changelog = "https://github.com/qca/open-ath9k-htc-firmware/tags"; 188 }; 189})