nixpkgs/pkgs/applications/radio/gnuradio/wrapper.nix
Doron Behar 3becac02f8 gnuradio: rewrite
Write (similar) expressions for GNURadio 3.7 and 3.8 and make 3.8
available as `gnuradio`, and `gnuradio3_7` point to the 3.7 build.

Teach both 3.7 & 3.8 expressions accept a `features` attribute set, that
tells them what features to compile. There are dependencies within the
different features, and we rely on upstream's cmake scripts to make sure
the `configurePhase` will fail if a feature is not enabled and needed by
another feature.  All features are enabled by default.

Put shared Nix functions and attributes for both 3.7 and 3.8 in:
pkgs/applications/radio/gnuradio/shared.nix

Add 2 patches accepted upstream, that don't install some python related
examples if python-support is not enabled.

Remove cmake python reference in 3.8 with removeReferencesTo, if
python-support is turned off.

Update gqrx (reverse dependency) to use a build of gnuradio3_7 without
gui components and for it's gr-osmosdr as well.

Write an external, `wrapper.nix` (shared for both 3.7 and 3.8). Teach it
to handle extra `gr-` packages via `GRC_BLOCKS_PATH`. Likely enable it
to accept extra python packages. Wrap the executables with env vars
wrapGAppsHook and wrapQtAppsHook would have likely given them (hence,
fix #87510). Point `gnuradio` to the wrapped 3.8 derivation.

Add @doronbehar to maintainers of both 3.8 and 3.7.

dirty: use upstreamed patches
2020-12-05 13:23:00 +02:00

133 lines
4.0 KiB
Nix

{ stdenv
, unwrapped
, makeWrapper
# For lndir
, xorg
# For Emulating wrapGAppsHook
, gsettings-desktop-schemas
, glib
, hicolor-icon-theme
, pango
, json-glib
, dconf
, gobject-introspection
, librsvg
, gdk-pixbuf
, harfbuzz
, at-spi2-core
, atk
# For Adding additional GRC blocks
, extraPackages ? []
# For Adding additional python packaages
, extraPythonPackages ? []
# Allow to add whatever you want to the wrapper
, extraMakeWrapperArgs ? []
}:
let
pythonPkgs = extraPythonPackages
++ stdenv.lib.flatten (stdenv.lib.mapAttrsToList (
feat: info: (
if unwrapped.hasFeature feat unwrapped.features then
(if builtins.hasAttr "pythonRuntime" info then info.pythonRuntime else [])
else
[]
)
) unwrapped.featuresInfo)
++ stdenv.lib.optionals (unwrapped.hasFeature "python-support" unwrapped.features) [
# Add unwrapped itself as a python module
(unwrapped.python.pkgs.toPythonModule unwrapped)
]
;
python3Env = unwrapped.python.withPackages(ps: pythonPkgs);
name = (stdenv.lib.appendToName "wrapped" unwrapped).name;
makeWrapperArgs = builtins.concatStringsSep " " ([
]
# Emulating wrapGAppsHook & wrapQtAppsHook working together
++ stdenv.lib.optionals (
(unwrapped.hasFeature "gnuradio-companion" unwrapped.features)
|| (unwrapped.hasFeature "gr-qtgui" unwrapped.features)
) [
"--prefix" "XDG_DATA_DIRS" ":" "$out/share"
"--prefix" "XDG_DATA_DIRS" ":" "$out/share/gsettings-schemas/${name}"
"--prefix" "XDG_DATA_DIRS" ":" "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
"--prefix" "XDG_DATA_DIRS" ":" "${hicolor-icon-theme}/share"
# Needs to run `gsettings` on startup, see:
# https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1764890.html
"--prefix" "PATH" ":" "${stdenv.lib.getBin glib}/bin"
]
++ stdenv.lib.optionals (unwrapped.hasFeature "gnuradio-companion" unwrapped.features) [
"--set" "GDK_PIXBUF_MODULE_FILE" "${librsvg}/${gdk-pixbuf.moduleDir}.cache"
"--prefix" "GIO_EXTRA_MODULES" ":" "${stdenv.lib.getLib dconf}/lib/gio/modules"
"--prefix" "XDG_DATA_DIRS" ":" "${unwrapped.gtk}/share"
"--prefix" "XDG_DATA_DIRS" ":" "${unwrapped.gtk}/share/gsettings-schemas/${unwrapped.gtk.name}"
"--prefix" "GI_TYPELIB_PATH" ":" "${stdenv.lib.makeSearchPath "lib/girepository-1.0" [
unwrapped.gtk
gsettings-desktop-schemas
atk
# From some reason, if .out is not used, .bin is used, and we want
# what's in `.out`.
pango.out
gdk-pixbuf
json-glib
harfbuzz
librsvg
gobject-introspection
at-spi2-core
]}"
]
++ stdenv.lib.optionals (extraPackages != []) [
"--prefix" "GRC_BLOCKS_PATH" ":" "${stdenv.lib.makeSearchPath "share/gnuradio/grc/blocks" extraPackages}"
]
++ stdenv.lib.optionals (unwrapped.hasFeature "gr-qtgui" unwrapped.features)
# 3.7 builds with qt4
(if unwrapped.versionAttr.major == "3.8" then
[
"--prefix" "QT_PLUGIN_PATH" ":"
"${stdenv.lib.getBin unwrapped.qt.qtbase}/${unwrapped.qt.qtbase.qtPluginPrefix}"
"--prefix" "QML2_IMPORT_PATH" ":"
"${stdenv.lib.getBin unwrapped.qt.qtbase}/${unwrapped.qt.qtbase.qtQmlPrefix}"
]
else
# TODO: Add here qt4 related environment for 3.7?
[
]
)
++ extraMakeWrapperArgs
);
in
stdenv.mkDerivation {
inherit name;
buildInputs = [
makeWrapper
xorg.lndir
];
passthru = {
inherit python3Env pythonPkgs unwrapped;
};
buildCommand = ''
mkdir $out
cd $out
lndir -silent ${unwrapped}
for i in $out/bin/*; do
if [[ ! -x "$i" ]]; then
continue
fi
cp -L "$i" "$i".tmp
mv -f "$i".tmp "$i"
if head -1 "$i" | grep -q ${unwrapped.python}; then
substituteInPlace "$i" \
--replace ${unwrapped.python} ${python3Env}
fi
wrapProgram "$i" ${makeWrapperArgs}
done
'';
inherit (unwrapped) meta;
}