7 # See https://files.ettus.com/manual_archive/v3.15.0.0/html/page_build_guide.html for dependencies explanations
11 , enablePythonApi ? true
13 , enableExamples ? false
16 # Disable dpdk for now due to compilation issues.
20 , enableOctoClock ? true
34 inherit (lib) optionals cmakeBool;
37 stdenv.mkDerivation (finalAttrs: {
39 # NOTE: Use the following command to update the package, and the uhdImageSrc attribute:
41 # nix-shell maintainers/scripts/update.nix --argstr package uhd --argstr commit true
45 outputs = [ "out" "dev" ];
47 src = fetchFromGitHub {
48 owner = "EttusResearch";
50 rev = "v${finalAttrs.version}";
51 # The updateScript relies on the `src` using `hash`, and not `sha256. To
52 # update the correct hash for the `src` vs the `uhdImagesSrc`
53 hash = "sha256-TX1iLs941z8sZY0yQEXuy9jGgsn6HU4uqIdxJmNNahU=";
55 # Firmware images are downloaded (pre-built) from the respective release on Github
56 uhdImagesSrc = fetchurl {
57 url = "https://github.com/EttusResearch/uhd/releases/download/v${finalAttrs.version}/uhd-images_${finalAttrs.version}.tar.xz";
58 # Please don't convert this to a hash, in base64, see comment near src's
60 sha256 = "17g503mhndaabrdl7qai3rdbafr8xx8awsyr7h2bdzwzprzmh4m3";
62 # This are the minimum required Python dependencies, this attribute might
63 # be useful if you want to build a development environment with a python
64 # interpreter able to import the uhd module.
65 pythonPath = optionals (enablePythonApi || enableUtils) [
67 python3.pkgs.setuptools
68 ] ++ optionals (enableUtils) [
72 /* These deps are needed for the usrp_hwd.py utility, however even if they
73 would have been added here, the utility wouldn't have worked because it
74 depends on an old python library mprpc that is not supported for Python >
75 3.8. See also report upstream:
76 https://github.com/EttusResearch/uhd/issues/744
85 runtimePython = python3.withPackages (ps: finalAttrs.pythonPath);
88 # Pass it this file name as argument
89 (builtins.unsafeGetAttrPos "pname" finalAttrs.finalPackage).file
96 # Regardless of doCheck, we want to build the tests to help us gain
97 # confident that the package is OK.
99 (cmakeBool "ENABLE_EXAMPLES" enableExamples)
100 (cmakeBool "ENABLE_UTILS" enableUtils)
101 (cmakeBool "ENABLE_C_API" enableCApi)
102 (cmakeBool "ENABLE_PYTHON_API" enablePythonApi)
105 Otherwise python tests fail. Using a dedicated pythonEnv for either or both
106 nativeBuildInputs and buildInputs makes upstream's cmake scripts fail to
107 install the Python API as reported on our end at [1] (we don't want
108 upstream to think we are in a virtual environment because we use
109 python3.withPackages...).
111 Putting simply the python dependencies in the nativeBuildInputs and
112 buildInputs as they are now from some reason makes the `python` in the
113 checkPhase fail to find the python dependencies, as reported at [2]. Even
114 using nativeCheckInputs with the python dependencies, or using a
115 `python3.withPackages` wrapper in nativeCheckInputs, doesn't help, as the
116 `python` found in $PATH first is the one from nativeBuildInputs.
118 [1]: https://github.com/NixOS/nixpkgs/pull/307435
119 [2]: https://discourse.nixos.org/t/missing-python-package-in-checkphase/9168/
121 Hence we use upstream's provided cmake flag to control which python
122 interpreter they will use to run the the python tests.
125 "-DRUNTIME_PYTHON_EXECUTABLE=${lib.getExe finalAttrs.passthru.runtimePython}"
126 (cmakeBool "ENABLE_DPDK" enableDpdk)
128 (cmakeBool "ENABLE_OCTOCLOCK" enableOctoClock)
129 (cmakeBool "ENABLE_MPMD" enableMpmd)
130 (cmakeBool "ENABLE_B100" enableB100)
131 (cmakeBool "ENABLE_B200" enableB200)
132 (cmakeBool "ENABLE_USRP1" enableUsrp1)
133 (cmakeBool "ENABLE_USRP2" enableUsrp2)
134 (cmakeBool "ENABLE_X300" enableX300)
135 (cmakeBool "ENABLE_N300" enableN300)
136 (cmakeBool "ENABLE_N320" enableN320)
137 (cmakeBool "ENABLE_E300" enableE300)
138 (cmakeBool "ENABLE_E320" enableE320)
139 # TODO: Check if this still needed
140 # ABI differences GCC 7.1
141 # /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
142 ] ++ optionals stdenv.hostPlatform.isAarch32 [
143 "-DCMAKE_CXX_FLAGS=-Wno-psabi"
146 nativeBuildInputs = [
149 # Present both here and in buildInputs for cross compilation.
152 # We add this unconditionally, but actually run wrapPythonPrograms only if
153 # python utilities are enabled
154 python3.pkgs.wrapPython
156 buildInputs = finalAttrs.pythonPath ++ [
159 ] ++ optionals (enableExamples) [
161 ] ++ optionals (enableDpdk) [
165 # many tests fails on darwin, according to ofborg
166 doCheck = !stdenv.hostPlatform.isDarwin;
168 # Build only the host software
169 preConfigure = "cd host";
171 # Disable tests that fail in the sandbox, last checked at version 4.6.0.0
172 ./no-adapter-tests.patch
177 "removeInstalledTests"
178 ] ++ optionals (enableUtils && stdenv.hostPlatform.isLinux) [
182 # UHD expects images in `$CMAKE_INSTALL_PREFIX/share/uhd/images`
184 mkdir -p "$out/share/uhd/images"
185 tar --strip-components=1 -xvf "${finalAttrs.uhdImagesSrc}" -C "$out/share/uhd/images"
188 # -DENABLE_TESTS=ON installs the tests, we don't need them in the output
189 removeInstalledTests = ''
190 rm -r $out/lib/uhd/tests
193 # Moves the udev rules to the standard location, needed only if utils are
196 mkdir -p $out/lib/udev/rules.d
197 mv $out/lib/uhd/utils/uhd-usrp.rules $out/lib/udev/rules.d/
200 # Wrap the python utilities with our pythonPath definition
201 postFixup = lib.optionalString (enablePythonApi && enableUtils) ''
204 disallowedReferences = optionals (!enablePythonApi && !enableUtils) [
209 description = "USRP Hardware Driver (for Software Defined Radio)";
211 The USRP Hardware Driver (UHD) software is the hardware driver for all
212 USRP (Universal Software Radio Peripheral) devices.
214 USRP devices are designed and sold by Ettus Research, LLC and its parent
215 company, National Instruments.
217 homepage = "https://uhd.ettus.com/";
218 license = licenses.gpl3Plus;
219 platforms = platforms.linux ++ platforms.darwin;
220 maintainers = with maintainers; [ bjornfor fpletz tomberek doronbehar ];