1{
2 lib,
3 stdenv,
4 # The unwrapped gnuradio derivation
5 unwrapped,
6 # If it's a minimal build, we don't want to wrap it with lndir and
7 # wrapProgram..
8 doWrap ? true,
9 # For the wrapper
10 makeWrapper,
11 # For lndir
12 xorg,
13 # To define a the gnuradio.pkgs scope
14 newScope,
15 # For Emulating wrapGAppsHook3
16 gsettings-desktop-schemas,
17 glib,
18 hicolor-icon-theme,
19 pango,
20 json-glib,
21 dconf,
22 gobject-introspection,
23 librsvg,
24 gdk-pixbuf,
25 harfbuzz,
26 at-spi2-core,
27 atk,
28 # For Adding additional GRC blocks
29 extraPackages ? [ ],
30 # For Adding additional python packaages
31 extraPythonPackages ? [ ],
32 soapysdr, # For it's passthru.searchPath
33 # soapysdr plugins we add by default. Ideally, we should have a
34 # soapysdrPackages = soapysdr.pkgs attribute set, but until now this wasn't
35 # crucial.
36 soapyairspy,
37 soapyaudio,
38 soapybladerf,
39 soapyhackrf,
40 soapyplutosdr,
41 soapyremote,
42 soapyrtlsdr,
43 soapyuhd,
44 # For adding / changing soapysdr packages, like soapsdr-with-plugins does
45 extraSoapySdrPackages ? [
46 soapyairspy
47 soapyaudio
48 soapybladerf
49 soapyhackrf
50 soapyplutosdr
51 soapyremote
52 soapyrtlsdr
53 soapyuhd
54 ],
55 # Allow to add whatever you want to the wrapper
56 extraMakeWrapperArgs ? [ ],
57}:
58
59let
60 # We don't check if `python-support` feature is on, as it's unlikely someone
61 # may wish to wrap GR without python support.
62 pythonPkgs =
63 extraPythonPackages
64 ++ [ (unwrapped.python.pkgs.toPythonModule unwrapped) ]
65 ++ unwrapped.passthru.uhd.pythonPath
66 ++ lib.optionals (unwrapped.passthru.uhd.pythonPath != [ ]) [
67 (unwrapped.python.pkgs.toPythonModule unwrapped.passthru.uhd)
68 ]
69 # Add the extraPackages as python modules as well
70 ++ (builtins.map unwrapped.python.pkgs.toPythonModule extraPackages)
71 ++ lib.flatten (
72 lib.mapAttrsToList (
73 feat: info:
74 (lib.optionals (
75 (unwrapped.hasFeature feat) && (builtins.hasAttr "pythonRuntime" info)
76 ) info.pythonRuntime)
77 ) unwrapped.featuresInfo
78 );
79 pythonEnv = unwrapped.python.withPackages (ps: pythonPkgs);
80
81 pname = unwrapped.pname + "-wrapped";
82 inherit (unwrapped) version;
83 makeWrapperArgs = builtins.concatStringsSep " " (
84 [
85 ]
86 # Emulating wrapGAppsHook3 & wrapQtAppsHook working together
87 ++
88 lib.optionals ((unwrapped.hasFeature "gnuradio-companion") || (unwrapped.hasFeature "gr-qtgui"))
89 [
90 "--prefix"
91 "XDG_DATA_DIRS"
92 ":"
93 "$out/share"
94 "--prefix"
95 "XDG_DATA_DIRS"
96 ":"
97 "$out/share/gsettings-schemas/${pname}"
98 "--prefix"
99 "XDG_DATA_DIRS"
100 ":"
101 "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
102 "--prefix"
103 "XDG_DATA_DIRS"
104 ":"
105 "${hicolor-icon-theme}/share"
106 # Needs to run `gsettings` on startup, see:
107 # https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1764890.html
108 "--prefix"
109 "PATH"
110 ":"
111 "${lib.getBin glib}/bin"
112 ]
113 ++ lib.optionals (unwrapped.hasFeature "gnuradio-companion") [
114 "--set"
115 "GDK_PIXBUF_MODULE_FILE"
116 "${librsvg}/${gdk-pixbuf.moduleDir}.cache"
117 "--prefix"
118 "GIO_EXTRA_MODULES"
119 ":"
120 "${lib.getLib dconf}/lib/gio/modules"
121 "--prefix"
122 "XDG_DATA_DIRS"
123 ":"
124 "${unwrapped.gtk}/share"
125 "--prefix"
126 "XDG_DATA_DIRS"
127 ":"
128 "${unwrapped.gtk}/share/gsettings-schemas/${unwrapped.gtk.name}"
129 "--prefix"
130 "GI_TYPELIB_PATH"
131 ":"
132 "${lib.makeSearchPath "lib/girepository-1.0" [
133 (lib.getLib glib)
134 unwrapped.gtk
135 gsettings-desktop-schemas
136 atk
137 # From some reason, if .out is not used, .bin is used, and we want
138 # what's in `.out`.
139 pango.out
140 gdk-pixbuf
141 json-glib
142 harfbuzz
143 librsvg
144 gobject-introspection
145 at-spi2-core
146 ]}"
147 ]
148 ++ lib.optionals (extraPackages != [ ]) [
149 "--prefix"
150 "GRC_BLOCKS_PATH"
151 ":"
152 "${lib.makeSearchPath "share/gnuradio/grc/blocks" extraPackages}"
153 ]
154 ++ lib.optionals (extraSoapySdrPackages != [ ]) [
155 "--prefix"
156 "SOAPY_SDR_PLUGIN_PATH"
157 ":"
158 "${lib.makeSearchPath soapysdr.passthru.searchPath extraSoapySdrPackages}"
159 ]
160 ++
161 lib.optionals (unwrapped.hasFeature "gr-qtgui")
162 # 3.7 builds with qt4
163 (
164 if lib.versionAtLeast unwrapped.versionAttr.major "3.8" then
165 [
166 "--prefix"
167 "QT_PLUGIN_PATH"
168 ":"
169 "${lib.makeSearchPath unwrapped.qt.qtbase.qtPluginPrefix (
170 builtins.map lib.getBin (
171 [
172 unwrapped.qt.qtbase
173 ]
174 ++ lib.optionals stdenv.hostPlatform.isLinux [
175 unwrapped.qt.qtwayland
176 ]
177 )
178 )}"
179 "--prefix"
180 "QML2_IMPORT_PATH"
181 ":"
182 "${lib.makeSearchPath unwrapped.qt.qtbase.qtQmlPrefix (
183 builtins.map lib.getBin (
184 [
185 unwrapped.qt.qtbase
186 ]
187 ++ lib.optionals stdenv.hostPlatform.isLinux [
188 unwrapped.qt.qtwayland
189 ]
190 )
191 )}"
192 ]
193 else
194 # Add here qt4 related environment for 3.7?
195 [
196
197 ]
198 )
199 ++ extraMakeWrapperArgs
200 );
201
202 packages = import ../../../top-level/gnuradio-packages.nix {
203 inherit lib stdenv newScope;
204 gnuradio = unwrapped;
205 };
206 passthru = unwrapped.passthru // {
207 inherit
208 pythonEnv
209 pythonPkgs
210 unwrapped
211 ;
212 pkgs = packages;
213 };
214 self =
215 if doWrap then
216 stdenv.mkDerivation {
217 inherit pname version passthru;
218 nativeBuildInputs = [ makeWrapper ];
219 buildInputs = [
220 xorg.lndir
221 ];
222 buildCommand = ''
223 mkdir $out
224 cd $out
225 lndir -silent ${unwrapped}
226 ${lib.optionalString (extraPackages != [ ]) (
227 builtins.concatStringsSep "\n" (
228 builtins.map (pkg: ''
229 if [[ -d ${lib.getBin pkg}/bin/ ]]; then
230 lndir -silent ${pkg}/bin ./bin
231 fi
232 '') extraPackages
233 )
234 )}
235 for i in $out/bin/*; do
236 if [[ ! -x "$i" ]]; then
237 continue
238 fi
239 cp -L "$i" "$i".tmp
240 mv -f "$i".tmp "$i"
241 if head -1 "$i" | grep -q ${unwrapped.python}; then
242 substituteInPlace "$i" \
243 --replace ${unwrapped.python} ${pythonEnv}
244 fi
245 wrapProgram "$i" ${makeWrapperArgs}
246 done
247 '';
248 inherit (unwrapped) meta;
249 }
250 else
251 unwrapped.overrideAttrs (_: {
252 inherit passthru;
253 });
254in
255self