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
2024-05-15 15:35:15 +00:00
, enablePythonApi ? true
2021-03-15 08:37:03 +00:00
, python3
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
2024-05-15 15:35:15 +00:00
inherit ( lib ) optionals cmakeBool ;
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 " ;
2023-10-19 13:55:26 +00:00
# NOTE: Use the following command to update the package, and the uhdImageSrc attribute:
#
# nix-shell maintainers/scripts/update.nix --argstr package uhd --argstr commit true
#
2024-01-02 11:29:13 +00:00
version = " 4 . 6 . 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-10-19 13:55:26 +00:00
# The updateScript relies on the `src` using `hash`, and not `sha256. To
# update the correct hash for the `src` vs the `uhdImagesSrc`
2024-01-02 11:29:13 +00:00
hash = " s h a 2 5 6 - 9 Z G t 0 Z r G b p r C m p A u O u e 6 p g 2 g l i u 4 M v l R F H G x y M J e K A c = " ;
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-10-19 13:55:26 +00:00
# Please don't convert this to a hash, in base64, see comment near src's
# hash.
2024-01-02 11:29:13 +00:00
sha256 = " 1 7 g 5 0 3 m h n d a a b r d l 7 q a i 3 r d b a f r 8 x x 8 a w s y r 7 h 2 b d z w z p r z m h 4 m 3 " ;
2023-10-19 13:55:26 +00:00
} ;
2024-05-15 15:35:15 +00:00
# This are the minimum required Python dependencies, this attribute might
# be useful if you want to build a development environment with a python
# interpreter able to import the uhd module.
pythonPath = optionals ( enablePythonApi || enableUtils ) [
python3 . pkgs . numpy
python3 . pkgs . setuptools
] ++ optionals ( enableUtils ) [
python3 . pkgs . requests
python3 . pkgs . six
/* T h e s e d e p s a r e n e e d e d f o r t h e u s r p _ h w d . p y u t i l i t y , h o w e v e r e v e n i f t h e y
would have been added here , the utility wouldn't have worked because it
depends on an old python library mprpc that is not supported for Python >
3 .8 . See also report upstream :
https://github.com/EttusResearch/uhd/issues/744
python3 . pkgs . gevent
python3 . pkgs . pyudev
python3 . pkgs . pyroute2
* /
] ;
2023-10-19 13:55:26 +00:00
passthru = {
2024-05-15 15:35:15 +00:00
runtimePython = python3 . withPackages ( ps : finalAttrs . pythonPath ) ;
2023-10-19 13:55:26 +00:00
updateScript = [
./update.sh
# Pass it this file name as argument
( builtins . unsafeGetAttrPos " p n a m e " finalAttrs . finalPackage ) . file
] ;
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 "
2024-05-15 15:35:15 +00:00
# Regardless of doCheck, we want to build the tests to help us gain
# confident that the package is OK.
" - D E N A B L E _ T E S T S = O N "
( cmakeBool " E N A B L E _ E X A M P L E S " enableExamples )
( cmakeBool " E N A B L E _ U T I L S " enableUtils )
( cmakeBool " E N A B L E _ C _ A P I " enableCApi )
( cmakeBool " E N A B L E _ P Y T H O N _ A P I " enablePythonApi )
/*
Otherwise python tests fail . Using a dedicated pythonEnv for either or both
nativeBuildInputs and buildInputs makes upstream's cmake scripts fail to
install the Python API as reported on our end at [ 1 ] ( we don't want
upstream to think we are in a virtual environment because we use
python3 . withPackages . . . ) .
Putting simply the python dependencies in the nativeBuildInputs and
buildInputs as they are now from some reason makes the ` python ` in the
checkPhase fail to find the python dependencies , as reported at [ 2 ] . Even
using nativeCheckInputs with the python dependencies , or using a
` python3 . withPackages ` wrapper in nativeCheckInputs , doesn't help , as the
` python ` found in $ PATH first is the one from nativeBuildInputs .
[ 1 ] : https://github.com/NixOS/nixpkgs/pull/307435
[ 2 ] : https://discourse.nixos.org/t/missing-python-package-in-checkphase/9168/
Hence we use upstream's provided cmake flag to control which python
interpreter they will use to run the the python tests .
* /
" - D R U N T I M E _ P Y T H O N _ E X E C U T A B L E = ${ lib . getExe finalAttrs . passthru . runtimePython } "
( cmakeBool " E N A B L E _ D P D K " enableDpdk )
2020-04-24 23:36:52 +00:00
# Devices
2024-05-15 15:35:15 +00:00
( cmakeBool " E N A B L E _ O C T O C L O C K " enableOctoClock )
( cmakeBool " E N A B L E _ M P M D " enableMpmd )
( cmakeBool " E N A B L E _ B 1 0 0 " enableB100 )
( cmakeBool " E N A B L E _ B 2 0 0 " enableB200 )
( cmakeBool " E N A B L E _ U S R P 1 " enableUsrp1 )
( cmakeBool " E N A B L E _ U S R P 2 " enableUsrp2 )
( cmakeBool " E N A B L E _ X 3 0 0 " enableX300 )
( cmakeBool " E N A B L E _ N 3 0 0 " enableN300 )
( cmakeBool " E N A B L E _ N 3 2 0 " enableN320 )
( cmakeBool " E N A B L E _ E 3 0 0 " enableE300 )
( cmakeBool " E N A B L E _ E 3 2 0 " enableE320 )
2020-04-24 23:36:52 +00:00
# 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
2024-05-15 15:35:15 +00:00
] ++ optionals 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
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.
2024-05-15 15:35:15 +00:00
python3
python3 . pkgs . mako
# We add this unconditionally, but actually run wrapPythonPrograms only if
# python utilities are enabled
python3 . pkgs . wrapPython
2023-04-29 16:46:19 +00:00
] ;
2024-05-15 15:35:15 +00:00
buildInputs = finalAttrs . pythonPath ++ [
2020-04-24 23:36:52 +00:00
boost
libusb1
2024-05-15 15:35:15 +00:00
] ++ optionals ( enableExamples ) [
ncurses ncurses . dev
] ++ optionals ( enableDpdk ) [
dpdk
] ;
2020-04-24 23:36:52 +00:00
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 " ;
2023-03-08 16:32:21 +00:00
patches = [
2024-05-15 15:35:15 +00:00
# Disable tests that fail in the sandbox, last checked at version 4.6.0.0
2023-03-08 16:32:21 +00:00
./no-adapter-tests.patch
] ;
2020-04-24 23:36:52 +00:00
2024-05-15 15:35:15 +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 && stdenv . hostPlatform . 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 /
'' ;
2024-05-15 15:35:15 +00:00
# Wrap the python utilities with our pythonPath definition
postFixup = lib . optionalString ( enablePythonApi && enableUtils ) ''
wrapPythonPrograms
'' ;
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
} )