1{
2 lib,
3 stdenv,
4 substitute,
5 fetchpatch,
6 fetchurl,
7 fetchFromGitHub,
8 cmake,
9 pkg-config,
10 # See https://files.ettus.com/manual_archive/v3.15.0.0/html/page_build_guide.html for dependencies explanations
11 boost,
12 ncurses,
13 enableCApi ? true,
14 enablePythonApi ? true,
15 python3,
16 enableExamples ? false,
17 enableUtils ? true,
18 libusb1,
19 # Disable dpdk for now due to compilation issues.
20 enableDpdk ? false,
21 dpdk,
22 # Devices
23 enableOctoClock ? true,
24 enableMpmd ? true,
25 enableB100 ? true,
26 enableB200 ? true,
27 enableUsrp1 ? true,
28 enableUsrp2 ? true,
29 enableX300 ? true,
30 enableN300 ? true,
31 enableN320 ? true,
32 enableE300 ? true,
33 enableE320 ? true,
34}:
35
36let
37 inherit (lib) optionals cmakeBool;
38in
39
40stdenv.mkDerivation (finalAttrs: {
41 pname = "uhd";
42 # NOTE: Use the following command to update the package, and the uhdImageSrc attribute:
43 #
44 # nix-shell maintainers/scripts/update.nix --argstr package uhd --argstr commit true
45 #
46 version = "4.8.0.0";
47
48 outputs = [
49 "out"
50 "dev"
51 ];
52
53 src = fetchFromGitHub {
54 owner = "EttusResearch";
55 repo = "uhd";
56 rev = "v${finalAttrs.version}";
57 # The updateScript relies on the `src` using `hash`, and not `sha256. To
58 # update the correct hash for the `src` vs the `uhdImagesSrc`
59 hash = "sha256-1HnXFeja4g1o64IPUkv/YyP/3upgYsjCVWal8t/hcuc=";
60 };
61 # Firmware images are downloaded (pre-built) from the respective release on Github
62 uhdImagesSrc = fetchurl {
63 url = "https://github.com/EttusResearch/uhd/releases/download/v${finalAttrs.version}/uhd-images_${finalAttrs.version}.tar.xz";
64 # Please don't convert this to a hash, in base64, see comment near src's
65 # hash.
66 sha256 = "0i5zagajj0hzdnavvzaixbn6nkh8p9aqw1lv1bj9lpbdh2wy4bk0";
67 };
68 # This are the minimum required Python dependencies, this attribute might
69 # be useful if you want to build a development environment with a python
70 # interpreter able to import the uhd module.
71 pythonPath =
72 optionals (enablePythonApi || enableUtils) [
73 python3.pkgs.numpy
74 python3.pkgs.setuptools
75 ]
76 ++ optionals (enableUtils) [
77 python3.pkgs.requests
78 python3.pkgs.six
79
80 /*
81 These deps are needed for the usrp_hwd.py utility, however even if they
82 would have been added here, the utility wouldn't have worked because it
83 depends on an old python library mprpc that is not supported for Python >
84 3.8. See also report upstream:
85 https://github.com/EttusResearch/uhd/issues/744
86
87 python3.pkgs.gevent
88 python3.pkgs.pyudev
89 python3.pkgs.pyroute2
90 */
91 ];
92 passthru = {
93 runtimePython = python3.withPackages (ps: finalAttrs.pythonPath);
94 updateScript = [
95 ./update.sh
96 # Pass it this file name as argument
97 (builtins.unsafeGetAttrPos "pname" finalAttrs.finalPackage).file
98 ];
99 };
100
101 cmakeFlags = [
102 "-DENABLE_LIBUHD=ON"
103 "-DENABLE_USB=ON"
104 # Regardless of doCheck, we want to build the tests to help us gain
105 # confident that the package is OK.
106 "-DENABLE_TESTS=ON"
107 (cmakeBool "ENABLE_EXAMPLES" enableExamples)
108 (cmakeBool "ENABLE_UTILS" enableUtils)
109 (cmakeBool "ENABLE_C_API" enableCApi)
110 (cmakeBool "ENABLE_PYTHON_API" enablePythonApi)
111 /*
112 Otherwise python tests fail. Using a dedicated pythonEnv for either or both
113 nativeBuildInputs and buildInputs makes upstream's cmake scripts fail to
114 install the Python API as reported on our end at [1] (we don't want
115 upstream to think we are in a virtual environment because we use
116 python3.withPackages...).
117
118 Putting simply the python dependencies in the nativeBuildInputs and
119 buildInputs as they are now from some reason makes the `python` in the
120 checkPhase fail to find the python dependencies, as reported at [2]. Even
121 using nativeCheckInputs with the python dependencies, or using a
122 `python3.withPackages` wrapper in nativeCheckInputs, doesn't help, as the
123 `python` found in $PATH first is the one from nativeBuildInputs.
124
125 [1]: https://github.com/NixOS/nixpkgs/pull/307435
126 [2]: https://discourse.nixos.org/t/missing-python-package-in-checkphase/9168/
127
128 Hence we use upstream's provided cmake flag to control which python
129 interpreter they will use to run the the python tests.
130 */
131 "-DRUNTIME_PYTHON_EXECUTABLE=${lib.getExe finalAttrs.passthru.runtimePython}"
132 (cmakeBool "ENABLE_DPDK" enableDpdk)
133 # Devices
134 (cmakeBool "ENABLE_OCTOCLOCK" enableOctoClock)
135 (cmakeBool "ENABLE_MPMD" enableMpmd)
136 (cmakeBool "ENABLE_B100" enableB100)
137 (cmakeBool "ENABLE_B200" enableB200)
138 (cmakeBool "ENABLE_USRP1" enableUsrp1)
139 (cmakeBool "ENABLE_USRP2" enableUsrp2)
140 (cmakeBool "ENABLE_X300" enableX300)
141 (cmakeBool "ENABLE_N300" enableN300)
142 (cmakeBool "ENABLE_N320" enableN320)
143 (cmakeBool "ENABLE_E300" enableE300)
144 (cmakeBool "ENABLE_E320" enableE320)
145 # TODO: Check if this still needed
146 # ABI differences GCC 7.1
147 # /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
148 ]
149 ++ optionals stdenv.hostPlatform.isAarch32 [
150 "-DCMAKE_CXX_FLAGS=-Wno-psabi"
151 ];
152
153 nativeBuildInputs = [
154 cmake
155 pkg-config
156 # Present both here and in buildInputs for cross compilation.
157 python3
158 python3.pkgs.mako
159 # We add this unconditionally, but actually run wrapPythonPrograms only if
160 # python utilities are enabled
161 python3.pkgs.wrapPython
162 ];
163 buildInputs =
164 finalAttrs.pythonPath
165 ++ [
166 boost
167 libusb1
168 ]
169 ++ optionals (enableExamples) [
170 ncurses
171 ncurses.dev
172 ]
173 ++ optionals (enableDpdk) [
174 dpdk
175 ];
176
177 # many tests fails on darwin, according to ofborg
178 doCheck = !stdenv.hostPlatform.isDarwin;
179
180 doInstallCheck = true;
181
182 # Build only the host software
183 preConfigure = "cd host";
184
185 postPhases = [
186 "installFirmware"
187 "removeInstalledTests"
188 ]
189 ++ optionals (enableUtils && stdenv.hostPlatform.isLinux) [
190 "moveUdevRules"
191 ];
192
193 # UHD expects images in `$CMAKE_INSTALL_PREFIX/share/uhd/images`
194 installFirmware = ''
195 mkdir -p "$out/share/uhd/images"
196 tar --strip-components=1 -xvf "${finalAttrs.uhdImagesSrc}" -C "$out/share/uhd/images"
197 '';
198
199 # -DENABLE_TESTS=ON installs the tests, we don't need them in the output
200 removeInstalledTests = ''
201 rm -r $out/lib/uhd/tests
202 '';
203
204 # Moves the udev rules to the standard location, needed only if utils are
205 # enabled
206 moveUdevRules = ''
207 mkdir -p $out/lib/udev/rules.d
208 mv $out/lib/uhd/utils/uhd-usrp.rules $out/lib/udev/rules.d/
209 '';
210
211 # Wrap the python utilities with our pythonPath definition
212 postFixup = lib.optionalString (enablePythonApi && enableUtils) ''
213 wrapPythonPrograms
214 '';
215 disallowedReferences = optionals (!enablePythonApi && !enableUtils) [
216 python3
217 ];
218
219 meta = with lib; {
220 description = "USRP Hardware Driver (for Software Defined Radio)";
221 longDescription = ''
222 The USRP Hardware Driver (UHD) software is the hardware driver for all
223 USRP (Universal Software Radio Peripheral) devices.
224
225 USRP devices are designed and sold by Ettus Research, LLC and its parent
226 company, National Instruments.
227 '';
228 homepage = "https://uhd.ettus.com/";
229 license = licenses.gpl3Plus;
230 platforms = platforms.linux ++ platforms.darwin;
231 maintainers = with maintainers; [
232 bjornfor
233 fpletz
234 tomberek
235 doronbehar
236 ];
237 };
238})