2021-03-15 08:37:03 +00:00
{ lib
, stdenv
2020-04-24 23:36:52 +00:00
, fetchurl
, fetchFromGitHub
, cmake
2021-02-05 17:12:51 +00:00
, pkg-config
2020-04-24 23:36:52 +00:00
# See https://files.ettus.com/manual_archive/v3.15.0.0/html/page_build_guide.html for dependencies explanations
, boost
2023-03-24 00:07:29 +00:00
, ncurses
2021-12-26 17:43:05 +00:00
, enableCApi ? true
2023-10-09 19:29:22 +00:00
# Although we handle the Python API's dependencies in pythonEnvArg, this
# feature is currently disabled as upstream attempts to run `python setup.py
# install` by itself, and it fails because the Python's environment's prefix is
# not a writable directly. Adding support for this feature would require using
# python's pypa/build nad pypa/install hooks directly, and currently it is hard
# to do that because it all happens after a long buildPhase of the C API.
2021-12-26 17:43:05 +00:00
, enablePythonApi ? false
2021-03-15 08:37:03 +00:00
, python3
2023-04-29 16:46:19 +00:00
, buildPackages
2020-04-24 23:36:52 +00:00
, enableExamples ? false
2023-10-09 19:29:22 +00:00
, enableUtils ? true
2021-03-15 08:37:03 +00:00
, libusb1
2023-10-09 19:29:22 +00:00
# Disable dpdk for now due to compilation issues.
2020-04-24 23:36:52 +00:00
, enableDpdk ? false
2021-03-15 08:37:03 +00:00
, dpdk
2020-04-24 23:36:52 +00:00
# Devices
, enableOctoClock ? true
, enableMpmd ? true
, enableB100 ? true
, enableB200 ? true
, enableUsrp1 ? true
, enableUsrp2 ? true
, enableX300 ? true
, enableN300 ? true
, enableN320 ? true
, enableE300 ? true
, enableE320 ? true
} :
let
onOffBool = b : if b then " O N " else " O F F " ;
2021-01-15 22:18:51 +00:00
inherit ( lib ) optionals ;
2023-04-29 16:46:19 +00:00
# Later used in pythonEnv generation. Python + mako are always required for the build itself but not necessary for runtime.
pythonEnvArg = ( ps : with ps ; [ mako ]
++ optionals ( enablePythonApi ) [ numpy setuptools ]
++ optionals ( enableUtils ) [ requests six ]
) ;
2020-04-24 23:36:52 +00:00
in
2023-10-09 19:29:22 +00:00
stdenv . mkDerivation ( finalAttrs : {
2020-04-24 23:36:52 +00:00
pname = " u h d " ;
# UHD seems to use three different version number styles: x.y.z, xxx_yyy_zzz
# and xxx.yyy.zzz. Hrmpf... style keeps changing
2023-03-08 16:32:21 +00:00
version = " 4 . 4 . 0 . 0 " ;
2020-04-24 23:36:52 +00:00
2022-04-27 09:35:20 +00:00
outputs = [ " o u t " " d e v " ] ;
2020-04-24 23:36:52 +00:00
src = fetchFromGitHub {
owner = " E t t u s R e s e a r c h " ;
repo = " u h d " ;
2023-10-09 19:29:22 +00:00
rev = " v ${ finalAttrs . version } " ;
2023-03-08 16:32:21 +00:00
sha256 = " s h a 2 5 6 - k h V O H l v a c Z c 4 E M g 4 m 5 5 r x E q P v L Y 1 x U R p A f O W 9 0 5 / 3 j g = " ;
2020-04-24 23:36:52 +00:00
} ;
# Firmware images are downloaded (pre-built) from the respective release on Github
uhdImagesSrc = fetchurl {
2023-10-09 19:29:22 +00:00
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 ${ finalAttrs . version } / u h d - i m a g e s _ ${ finalAttrs . version } . t a r . x z " ;
2023-03-08 16:32:21 +00:00
sha256 = " V 8 l d W 8 b v Y W b r D A v p W p H c M e L f 9 Y v F 8 P I r u D A y N K / b r u 4 = " ;
2020-04-24 23:36:52 +00:00
} ;
2023-10-09 19:29:22 +00:00
# TODO: Add passthru.updateScript that will update both of the above hashes...
2020-04-24 23:36:52 +00:00
cmakeFlags = [
" - 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 } "
2021-12-26 17:43:05 +00:00
" - D E N A B L E _ C _ A P I = ${ onOffBool enableCApi } "
" - D E N A B L E _ P Y T H O N _ A P I = ${ onOffBool enablePythonApi } "
2020-04-24 23:36:52 +00:00
" - 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 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 } "
]
# TODO: Check if this still needed
# 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 22:18:51 +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-04-24 23:36:52 +00:00
;
2023-04-29 16:46:19 +00:00
pythonEnv = python3 . withPackages pythonEnvArg ;
2020-04-24 23:36:52 +00:00
nativeBuildInputs = [
cmake
2021-02-05 17:12:51 +00:00
pkg-config
2023-04-29 16:46:19 +00:00
# Present both here and in buildInputs for cross compilation.
( buildPackages . python3 . withPackages pythonEnvArg )
] ;
2020-04-24 23:36:52 +00:00
buildInputs = [
boost
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
2023-03-24 00:07:29 +00:00
++ optionals ( enableExamples ) [ ncurses ncurses . dev ]
2023-10-09 19:29:22 +00:00
++ optionals ( enablePythonApi || enableUtils ) [ finalAttrs . pythonEnv ]
2020-04-24 23:36:52 +00:00
++ optionals ( enableDpdk ) [ dpdk ]
;
2021-12-26 17:43:05 +00:00
# many tests fails on darwin, according to ofborg
doCheck = ! stdenv . isDarwin ;
2020-04-24 23:36:52 +00:00
# Build only the host software
preConfigure = " c d h o s t " ;
# 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
2023-03-08 16:32:21 +00:00
patches = [
# Disable tests that fail in the sandbox
./no-adapter-tests.patch
] ;
2020-04-24 23:36:52 +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 " ]
2023-03-24 00:07:29 +00:00
++ optionals ( enableUtils && stdenv . targetPlatform . isLinux ) [ " m o v e U d e v R u l e s " ]
2020-04-24 23:36:52 +00:00
;
# UHD expects images in `$CMAKE_INSTALL_PREFIX/share/uhd/images`
installFirmware = ''
mkdir - p " $ o u t / s h a r e / u h d / i m a g e s "
2023-10-09 19:29:22 +00:00
tar - - strip-components = 1 - xvf " ${ finalAttrs . uhdImagesSrc } " - C " $ o u t / s h a r e / u h d / i m a g e s "
2020-04-24 23:36:52 +00:00
'' ;
# -DENABLE_TESTS=ON installs the tests, we don't need them in the output
removeInstalledTests = ''
rm - r $ out/lib/uhd/tests
'' ;
# 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 /
'' ;
2023-10-09 19:29:22 +00:00
disallowedReferences = optionals ( ! enablePythonApi && ! enableUtils ) [
python3
] ;
2021-01-15 22:18:51 +00:00
meta = with lib ; {
2020-04-24 23:36:52 +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 .
'' ;
homepage = " h t t p s : / / u h d . e t t u s . c o m / " ;
license = licenses . gpl3Plus ;
platforms = platforms . linux ++ platforms . darwin ;
2021-12-26 17:43:05 +00:00
maintainers = with maintainers ; [ bjornfor fpletz tomberek doronbehar ] ;
2020-04-24 23:36:52 +00:00
} ;
2023-10-09 19:29:22 +00:00
} )