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