2021-02-23 16:08:16 +00:00
{ lib
, stdenv
2020-03-09 12:16:25 +00:00
, fetchurl
, fetchFromGitHub
, cmake
2021-01-17 02:09:27 +00:00
, pkg-config
2020-03-09 15:21:20 +00:00
# See https://files.ettus.com/manual_archive/v3.15.0.0/html/page_build_guide.html for dependencies explanations
2020-03-09 12:16:25 +00:00
, boost
2020-03-09 15:21:20 +00:00
, enableLibuhd_C_api ? true
# requires numpy
, enableLibuhd_Python_api ? false
2021-02-23 16:08:16 +00:00
, python3
2020-03-09 15:21:20 +00:00
, enableExamples ? false
, enableUtils ? false
, enableLiberio ? false
2021-02-23 16:08:16 +00:00
, liberio
, libusb1
2020-03-09 15:21:20 +00:00
, enableDpdk ? false
2021-02-23 16:08:16 +00:00
, dpdk
2020-03-09 15:21:20 +00:00
# Devices
, enableOctoClock ? true
, enableMpmd ? true
, enableB100 ? true
, enableB200 ? true
, enableUsrp1 ? true
, enableUsrp2 ? true
, enableX300 ? true
, enableN230 ? true
, enableN300 ? true
, enableN320 ? true
, enableE300 ? true
, enableE320 ? true
2020-03-09 12:16:25 +00:00
} :
2013-05-02 13:27:11 +00:00
2020-03-09 15:21:20 +00:00
let
onOffBool = b : if b then " O N " else " O F F " ;
2021-01-15 05:42:41 +00:00
inherit ( lib ) optionals ;
2020-03-09 15:21:20 +00:00
in
2020-03-09 12:06:14 +00:00
stdenv . mkDerivation rec {
pname = " u h d " ;
2013-05-02 13:27:11 +00:00
# UHD seems to use three different version number styles: x.y.z, xxx_yyy_zzz
2018-03-29 01:14:08 +00:00
# and xxx.yyy.zzz. Hrmpf... style keeps changing
2021-02-23 16:08:16 +00:00
version = " 4 . 0 . 0 . 0 " ;
2013-05-02 13:27:11 +00:00
2016-03-22 00:15:40 +00:00
src = fetchFromGitHub {
owner = " E t t u s R e s e a r c h " ;
repo = " u h d " ;
2020-03-09 12:06:14 +00:00
rev = " v ${ version } " ;
2021-02-23 16:08:16 +00:00
sha256 = " N C y i I 4 p I P w 0 n B R F d U G p g Z / x 2 m W z + Q m 7 8 Z G A C U n S b G S s = " ;
2020-03-09 12:06:14 +00:00
} ;
# Firmware images are downloaded (pre-built) from the respective release on Github
uhdImagesSrc = fetchurl {
url = " h t t p s : / / g i t h u b . c o m / E t t u s R e s e a r c h / u h d / r e l e a s e s / d o w n l o a d / v ${ version } / u h d - i m a g e s _ ${ version } . t a r . x z " ;
2021-02-23 16:08:16 +00:00
sha256 = " X f x 0 b s H U Q 5 + D p + x k 0 s V W W P 8 3 o y X Q c U H 5 A X 4 P N E E 7 f Y 4 = " ;
2013-05-02 13:27:11 +00:00
} ;
2020-03-09 12:16:25 +00:00
cmakeFlags = [
2020-03-09 15:21:20 +00:00
" - D E N A B L E _ L I B U H D = O N "
" - D E N A B L E _ U S B = O N "
" - D E N A B L E _ T E S T S = O N " # This installs tests as well so we delete them via postPhases
" - D E N A B L E _ E X A M P L E S = ${ onOffBool enableExamples } "
" - D E N A B L E _ U T I L S = ${ onOffBool enableUtils } "
" - D E N A B L E _ L I B U H D _ C _ A P I = ${ onOffBool enableLibuhd_C_api } "
" - D E N A B L E _ L I B U H D _ P Y T H O N _ A P I = ${ onOffBool enableLibuhd_Python_api } "
" - D E N A B L E _ L I B E R I O = ${ onOffBool enableLiberio } "
" - D E N A B L E _ D P D K = ${ onOffBool enableDpdk } "
# Devices
" - D E N A B L E _ O C T O C L O C K = ${ onOffBool enableOctoClock } "
" - D E N A B L E _ M P M D = ${ onOffBool enableMpmd } "
" - D E N A B L E _ B 1 0 0 = ${ onOffBool enableB100 } "
" - D E N A B L E _ B 2 0 0 = ${ onOffBool enableB200 } "
" - D E N A B L E _ U S R P 1 = ${ onOffBool enableUsrp1 } "
" - D E N A B L E _ U S R P 2 = ${ onOffBool enableUsrp2 } "
" - D E N A B L E _ X 3 0 0 = ${ onOffBool enableX300 } "
" - D E N A B L E _ N 2 3 0 = ${ onOffBool enableN230 } "
" - D E N A B L E _ N 3 0 0 = ${ onOffBool enableN300 } "
" - D E N A B L E _ N 3 2 0 = ${ onOffBool enableN320 } "
" - D E N A B L E _ E 3 0 0 = ${ onOffBool enableE300 } "
" - D E N A B L E _ E 3 2 0 = ${ onOffBool enableE320 } "
2020-03-09 12:16:25 +00:00
]
2020-03-09 12:31:30 +00:00
# TODO: Check if this still needed
2020-03-09 12:16:25 +00:00
# ABI differences GCC 7.1
# /nix/store/wd6r25miqbk9ia53pp669gn4wrg9n9cj-gcc-7.3.0/include/c++/7.3.0/bits/vector.tcc:394:7: note: parameter passing for argument of type 'std::vector<uhd::range_t>::iterator {aka __gnu_cxx::__normal_iterator<uhd::range_t*, std::vector<uhd::range_t> >}' changed in GCC 7.1
2021-01-15 05:42:41 +00:00
++ [ ( lib . optionalString stdenv . isAarch32 " - D C M A K E _ C X X _ F L A G S = - W n o - p s a b i " ) ]
2020-03-09 12:16:25 +00:00
;
2018-03-29 01:14:08 +00:00
2020-03-09 15:21:20 +00:00
# Python + Mako are always required for the build itself but not necessary for runtime.
2020-03-09 16:57:08 +00:00
pythonEnv = python3 . withPackages ( ps : with ps ; [ Mako ]
2020-03-09 15:21:20 +00:00
++ optionals ( enableLibuhd_Python_api ) [ numpy setuptools ]
++ optionals ( enableUtils ) [ requests six ]
) ;
2020-03-09 12:16:25 +00:00
nativeBuildInputs = [
cmake
2021-01-17 02:09:27 +00:00
pkg-config
2020-03-09 15:21:20 +00:00
]
# If both enableLibuhd_Python_api and enableUtils are off, we don't need
# pythonEnv in buildInputs as it's a 'build' dependency and not a runtime
# dependency
++ optionals ( ! enableLibuhd_Python_api && ! enableUtils ) [ pythonEnv ]
;
2019-10-30 23:47:28 +00:00
buildInputs = [
boost
2020-03-09 15:21:20 +00:00
libusb1
]
# However, if enableLibuhd_Python_api *or* enableUtils is on, we need
# pythonEnv for runtime as well. The utilities' runtime dependencies are
# handled at the environment
++ optionals ( enableLibuhd_Python_api || enableUtils ) [ pythonEnv ]
++ optionals ( enableLiberio ) [ liberio ]
++ optionals ( enableDpdk ) [ dpdk ]
;
doCheck = true ;
2013-05-02 13:27:11 +00:00
# Build only the host software
preConfigure = " c d h o s t " ;
2020-03-09 12:31:30 +00:00
# TODO: Check if this still needed, perhaps relevant:
# https://files.ettus.com/manual_archive/v3.15.0.0/html/page_build_guide.html#build_instructions_unix_arm
treewide: isArm -> isAarch32
Following legacy packing conventions, `isArm` was defined just for
32-bit ARM instruction set. This is confusing to non packagers though,
because Aarch64 is an ARM instruction set.
The official ARM overview for ARMv8[1] is surprisingly not confusing,
given the overall state of affairs for ARM naming conventions, and
offers us a solution. It divides the nomenclature into three levels:
```
ISA: ARMv8 {-A, -R, -M}
/ \
Mode: Aarch32 Aarch64
| / \
Encoding: A64 A32 T32
```
At the top is the overall v8 instruction set archicture. Second are the
two modes, defined by bitwidth but differing in other semantics too, and
buttom are the encodings, (hopefully?) isomorphic if they encode the
same mode.
The 32 bit encodings are mostly backwards compatible with previous
non-Thumb and Thumb encodings, and if so we can pun the mode names to
instead mean "sets of compatable or isomorphic encodings", and then
voilà we have nice names for 32-bit and 64-bit arm instruction sets
which do not use the word ARM so as to not confused either laymen or
experienced ARM packages.
[1]: https://developer.arm.com/products/architecture/a-profile
2018-03-20 02:41:06 +00:00
patches = if stdenv . isAarch32 then ./neon.patch else null ;
2013-05-02 13:27:11 +00:00
2020-03-09 16:30:33 +00:00
postPhases = [ " i n s t a l l F i r m w a r e " " r e m o v e I n s t a l l e d T e s t s " ]
++ optionals ( enableUtils ) [ " m o v e U d e v R u l e s " ]
;
2013-05-02 13:27:11 +00:00
2018-06-26 21:47:22 +00:00
# UHD expects images in `$CMAKE_INSTALL_PREFIX/share/uhd/images`
2013-05-02 13:27:11 +00:00
installFirmware = ''
2018-06-26 21:47:22 +00:00
mkdir - p " $ o u t / s h a r e / u h d / i m a g e s "
tar - - strip-components = 1 - xvf " ${ uhdImagesSrc } " - C " $ o u t / s h a r e / u h d / i m a g e s "
2013-05-02 13:27:11 +00:00
'' ;
2020-03-09 15:21:20 +00:00
# -DENABLE_TESTS=ON installs the tests, we don't need them in the output
removeInstalledTests = ''
rm - r $ out/lib/uhd/tests
'' ;
2020-03-09 16:30:33 +00:00
# Moves the udev rules to the standard location, needed only if utils are
# enabled
moveUdevRules = ''
mkdir - p $ out/lib/udev/rules.d
mv $ out/lib/uhd/utils/uhd-usrp.rules $ out/lib/udev/rules.d /
'' ;
2021-01-11 07:54:33 +00:00
meta = with lib ; {
2013-05-02 13:27:11 +00:00
description = " U S R P H a r d w a r e D r i v e r ( f o r S o f t w a r e D e f i n e d R a d i o ) " ;
longDescription = ''
The USRP Hardware Driver ( UHD ) software is the hardware driver for all
USRP ( Universal Software Radio Peripheral ) devices .
USRP devices are designed and sold by Ettus Research , LLC and its parent
company , National Instruments .
'' ;
2020-04-03 11:55:06 +00:00
homepage = " h t t p s : / / u h d . e t t u s . c o m / " ;
2013-05-02 13:27:11 +00:00
license = licenses . gpl3Plus ;
2017-05-26 03:15:15 +00:00
platforms = platforms . linux ++ platforms . darwin ;
2018-03-29 01:14:08 +00:00
maintainers = with maintainers ; [ bjornfor fpletz tomberek ] ;
2013-05-02 13:27:11 +00:00
} ;
}