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