1{
2 lib,
3 stdenv,
4 python,
5 qt,
6 gtk,
7 removeReferencesTo,
8 featuresInfo,
9 features,
10 version,
11 sourceSha256,
12 # If overridden. No need to set default values, as they are given defaults in
13 # the main expressions
14 overrideSrc,
15 fetchFromGitHub,
16}:
17
18let
19 # Check if a feature is enabled, while defaulting to true if feat is not
20 # specified.
21 hasFeature = feat: (if builtins.hasAttr feat features then features.${feat} else true);
22 versionAttr = {
23 major = builtins.concatStringsSep "." (lib.take 2 (lib.splitVersion version));
24 minor = builtins.elemAt (lib.splitVersion version) 2;
25 patch = builtins.elemAt (lib.splitVersion version) 3;
26 };
27in
28{
29 src =
30 if overrideSrc != { } then
31 overrideSrc
32 else
33 fetchFromGitHub {
34 repo = "gnuradio";
35 owner = "gnuradio";
36 rev = "v${version}";
37 sha256 = sourceSha256;
38 };
39 nativeBuildInputs = [
40 removeReferencesTo
41 ]
42 ++ lib.flatten (
43 lib.mapAttrsToList (
44 feat: info:
45 (lib.optionals (hasFeature feat) (
46 (lib.optionals (builtins.hasAttr "native" info) info.native)
47 ++ (lib.optionals (builtins.hasAttr "pythonNative" info) info.pythonNative)
48 ))
49 ) featuresInfo
50 );
51 buildInputs = lib.flatten (
52 lib.mapAttrsToList (
53 feat: info:
54 (lib.optionals (hasFeature feat) (
55 (lib.optionals (builtins.hasAttr "runtime" info) info.runtime)
56 ++ (lib.optionals (builtins.hasAttr "pythonRuntime" info) info.pythonRuntime)
57 ))
58 ) featuresInfo
59 );
60 cmakeFlags = lib.mapAttrsToList (
61 feat: info:
62 (
63 if feat == "basic" then
64 # Abuse this unavoidable "iteration" to set this flag which we want as
65 # well - it means: Don't turn on features just because their deps are
66 # satisfied, let only our cmakeFlags decide.
67 "-DENABLE_DEFAULT=OFF"
68 else if hasFeature feat then
69 "-DENABLE_${info.cmakeEnableFlag}=ON"
70 else
71 "-DENABLE_${info.cmakeEnableFlag}=OFF"
72 )
73 ) featuresInfo;
74 disallowedReferences = [
75 # TODO: Should this be conditional?
76 stdenv.cc
77 stdenv.cc.cc
78 ]
79 # If python-support is disabled, we probably don't want it referenced
80 ++ lib.optionals (!hasFeature "python-support") [ python ];
81 # Gcc references from examples
82 stripDebugList = [
83 "lib"
84 "bin"
85 ]
86 ++ lib.optionals (hasFeature "gr-audio") [ "share/gnuradio/examples/audio" ]
87 ++ lib.optionals (hasFeature "gr-uhd") [ "share/gnuradio/examples/uhd" ]
88 ++ lib.optionals (hasFeature "gr-qtgui") [ "share/gnuradio/examples/qt-gui" ];
89 postInstall =
90 ""
91 # Gcc references
92 + lib.optionalString (hasFeature "gnuradio-runtime") ''
93 remove-references-to -t ${stdenv.cc} $(readlink -f $out/lib/libgnuradio-runtime${stdenv.hostPlatform.extensions.sharedLibrary})
94 ''
95 # Clang references in InstalledDir
96 + lib.optionalString (hasFeature "gnuradio-runtime" && stdenv.hostPlatform.isDarwin) ''
97 remove-references-to -t ${stdenv.cc.cc} $(readlink -f $out/lib/libgnuradio-runtime${stdenv.hostPlatform.extensions.sharedLibrary})
98 '';
99 # NOTE: Outputs are disabled due to upstream not using GNU InstallDIrs cmake
100 # module. It's not that bad since it's a development package for most
101 # purposes. If closure size needs to be reduced, features should be disabled
102 # via an override.
103 passthru = {
104 inherit
105 hasFeature
106 versionAttr
107 features
108 featuresInfo
109 python
110 ;
111 gnuradioOlder = lib.versionOlder versionAttr.major;
112 gnuradioAtLeast = lib.versionAtLeast versionAttr.major;
113 }
114 // lib.optionalAttrs (hasFeature "gr-qtgui") {
115 inherit qt;
116 }
117 // lib.optionalAttrs (hasFeature "gnuradio-companion") {
118 inherit gtk;
119 };
120 # Wrapping is done with an external wrapper
121 dontWrapPythonPrograms = true;
122 dontWrapQtApps = true;
123 # On darwin, it requires playing with DYLD_FALLBACK_LIBRARY_PATH to make if
124 # find libgnuradio-runtim.3.*.dylib .
125 doCheck = !stdenv.hostPlatform.isDarwin;
126 preCheck = ''
127 export HOME=$(mktemp -d)
128 export QT_QPA_PLATFORM=offscreen
129 export QT_PLUGIN_PATH="${qt.qtbase.bin}/${qt.qtbase.qtPluginPrefix}"
130 '';
131
132 meta = {
133 description = "Software Defined Radio (SDR) software";
134 mainProgram = "gnuradio-config-info";
135 longDescription = ''
136 GNU Radio is a free & open-source software development toolkit that
137 provides signal processing blocks to implement software radios. It can be
138 used with readily-available low-cost external RF hardware to create
139 software-defined radios, or without hardware in a simulation-like
140 environment. It is widely used in hobbyist, academic and commercial
141 environments to support both wireless communications research and
142 real-world radio systems.
143 '';
144 homepage = "https://www.gnuradio.org";
145 license = lib.licenses.gpl3;
146 platforms = lib.platforms.unix;
147 maintainers = with lib.maintainers; [
148 doronbehar
149 bjornfor
150 fpletz
151 jiegec
152 ];
153 };
154}