nixpkgs/pkgs/applications/radio/gnuradio/shared.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

136 lines
4.2 KiB
Nix

{ stdenv
, python
, qt
, gtk
, removeReferencesTo
, featuresInfo
, features
, versionAttr
, sourceSha256
# If overriden. No need to set default values, as they are given defaults in
# the main expressions
, overrideSrc
, fetchFromGitHub
, fetchSubmodules
}:
let
lib = stdenv.lib;
in rec {
version = builtins.concatStringsSep "." (
lib.attrVals [ "major" "minor" "patch" ] versionAttr
);
src = if overrideSrc != {} then
overrideSrc
else
fetchFromGitHub {
repo = "gnuradio";
owner = "gnuradio";
rev = "v${version}";
sha256 = sourceSha256;
inherit fetchSubmodules;
}
;
# Check if a feature is enabled, while defaulting to true if feat is not
# specified.
hasFeature = feat: features: (
if builtins.hasAttr feat features then
features.${feat}
else
true
);
nativeBuildInputs = lib.flatten (lib.mapAttrsToList (
feat: info: (
if hasFeature feat features then
(if builtins.hasAttr "native" info then info.native else []) ++
(if builtins.hasAttr "pythonNative" info then info.pythonNative else [])
else
[]
)
) featuresInfo);
buildInputs = lib.flatten (lib.mapAttrsToList (
feat: info: (
if hasFeature feat features then
(if builtins.hasAttr "runtime" info then info.runtime else []) ++
(if builtins.hasAttr "pythonRuntime" info then info.pythonRuntime else [])
else
[]
)
) featuresInfo);
cmakeFlags = lib.mapAttrsToList (
feat: info: (
if feat == "basic" then
# Abuse this unavoidable "iteration" to set this flag which we want as
# well - it means: Don't turn on features just because their deps are
# satisfied, let only our cmakeFlags decide.
"-DENABLE_DEFAULT=OFF"
else
if hasFeature feat features then
"-DENABLE_${info.cmakeEnableFlag}=ON"
else
"-DENABLE_${info.cmakeEnableFlag}=OFF"
)) featuresInfo
;
disallowedReferences = [
# TODO: Should this be conditional?
stdenv.cc
stdenv.cc.cc
]
# If python-support is disabled, we probably don't want it referenced
++ lib.optionals (!hasFeature "python-support" features) [ python ]
;
# Gcc references from examples
stripDebugList = [ "lib" "bin" ]
++ lib.optionals (hasFeature "gr-audio" features) [ "share/gnuradio/examples/audio" ]
++ lib.optionals (hasFeature "gr-uhd" features) [ "share/gnuradio/examples/uhd" ]
++ lib.optionals (hasFeature "gr-qtgui" features) [ "share/gnuradio/examples/qt-gui" ]
;
postInstall = ''
''
# Gcc references
+ lib.optionalString (hasFeature "volk" features) ''
${removeReferencesTo}/bin/remove-references-to -t ${stdenv.cc} $(readlink -f $out/lib/libvolk.so)
''
+ lib.optionalString (hasFeature "gnuradio-runtime" features) ''
${removeReferencesTo}/bin/remove-references-to -t ${stdenv.cc} $(readlink -f $out/lib/libgnuradio-runtime.so)
''
;
# NOTE: Outputs are disabled due to upstream not using GNU InstallDIrs cmake
# module. It's not that bad since it's a development package for most
# purposes. If closure size needs to be reduced, features should be disabled
# via an override.
passthru = {
inherit
hasFeature
versionAttr
features
featuresInfo
python
qt
gtk
;
};
# Wrapping is done with an external wrapper
dontWrapPythonPrograms = true;
# Tests should succeed, but it's hard to get LD_LIBRARY_PATH right in order
# for it to happen.
doCheck = false;
meta = with lib; {
description = "Software Defined Radio (SDR) software";
longDescription = ''
GNU Radio is a free & open-source software development toolkit that
provides signal processing blocks to implement software radios. It can be
used with readily-available low-cost external RF hardware to create
software-defined radios, or without hardware in a simulation-like
environment. It is widely used in hobbyist, academic and commercial
environments to support both wireless communications research and
real-world radio systems.
'';
homepage = "https://www.gnuradio.org";
license = licenses.gpl3;
platforms = platforms.unix;
maintainers = with maintainers; [ doronbehar bjornfor fpletz ];
};
}