about summary refs log tree commit diff
path: root/pkgs/applications/radio/soapysdr
diff options
context:
space:
mode:
authorDoron Behar <doron.behar@gmail.com>2023-09-07 15:12:15 +0300
committerDoron Behar <doron.behar@gmail.com>2023-09-08 12:50:58 +0300
commit7bd68a8bde33873eea657cd79d745615b6ae412d (patch)
treeb40dbdefbe11cf54bef9b4f34b596cc896be517d /pkgs/applications/radio/soapysdr
parent7f2d93dda9b9a291b44878927d03faf66d0f7e12 (diff)
soapysdr: cleanup expression
- Format it with nixpkgs-fmt.
- Patch fixed upstream issue only once, using fetchpatch.
- Use `lib.optionals` consistently.
- Use `lib.pipe` to write `lndir` commands for postFixup.
- Use `finalAttrs.version` as much as possible.
- Use passthru.searchPath to expose it for other packages to use (like
  Gnuradio's wrapper).
Diffstat (limited to 'pkgs/applications/radio/soapysdr')
-rw-r--r--pkgs/applications/radio/soapysdr/default.nix97
-rw-r--r--pkgs/applications/radio/soapysdr/fix-pkgconfig.patch14
2 files changed, 57 insertions, 54 deletions
diff --git a/pkgs/applications/radio/soapysdr/default.nix b/pkgs/applications/radio/soapysdr/default.nix
index e11e2af401b9c..7e0c01c2f5f7c 100644
--- a/pkgs/applications/radio/soapysdr/default.nix
+++ b/pkgs/applications/radio/soapysdr/default.nix
@@ -1,66 +1,83 @@
-{ stdenv, lib, lndir, makeWrapper
-, fetchFromGitHub, cmake
-, libusb-compat-0_1, pkg-config
+{ stdenv
+, lib
+, fetchFromGitHub
+, fetchpatch
+, cmake
+, pkg-config
+, makeWrapper
+, libusb-compat-0_1
+, ncurses
 , usePython ? false
 , python ? null
-, ncurses, swig2
-, extraPackages ? []
-, testers
+, swig2
+, extraPackages ? [ ]
 , buildPackages
+, testers
 }:
 
-let
-
-  version = "0.8.1";
-  modulesVersion = with lib; versions.major version + "." + versions.minor version;
-  modulesPath = "lib/SoapySDR/modules" + modulesVersion;
-  extraPackagesSearchPath = lib.makeSearchPath modulesPath extraPackages;
-
-in stdenv.mkDerivation (finalAttrs: {
+stdenv.mkDerivation (finalAttrs: {
   pname = "soapysdr";
-  inherit version;
+  version = "0.8.1";
 
   src = fetchFromGitHub {
     owner = "pothosware";
     repo = "SoapySDR";
-    rev = "soapy-sdr-${version}";
+    rev = "soapy-sdr-${finalAttrs.version}";
     sha256 = "19f2x0pkxvf9figa0pl6xqlcz8fblvqb19mcnj632p0l8vk6qdv2";
   };
 
   patches = [
-    # see https://github.com/pothosware/SoapySDR/issues/352 for upstream issue
-    ./fix-pkgconfig.patch
+    # Fix for https://github.com/pothosware/SoapySDR/issues/352
+    (fetchpatch {
+      url = "https://github.com/pothosware/SoapySDR/commit/10c05b3e52caaa421147d6b4623eccd3fc3be3f4.patch";
+      hash = "sha256-D7so6NSZiU6SXbzns04Q4RjSZW0FJ+MYobvvVpVMjws=";
+    })
   ];
 
-  nativeBuildInputs = [ cmake makeWrapper pkg-config ];
-  buildInputs = [ libusb-compat-0_1 ncurses ]
-    ++ lib.optionals usePython [ python swig2 ];
+  nativeBuildInputs = [
+    cmake
+    pkg-config
+    makeWrapper
+  ];
+  buildInputs = [
+    libusb-compat-0_1
+    ncurses
+  ] ++ lib.optionals usePython [
+    python
+    swig2
+  ];
 
-  propagatedBuildInputs = lib.optional usePython python.pkgs.numpy;
+  propagatedBuildInputs = lib.optionals usePython [
+    python.pkgs.numpy
+  ];
 
   cmakeFlags = [
     "-DCMAKE_BUILD_TYPE=Release"
-  ] ++ lib.optional usePython "-DUSE_PYTHON_CONFIG=ON";
-
-  # https://github.com/pothosware/SoapySDR/issues/352
-  postPatch = ''
-    substituteInPlace lib/SoapySDR.in.pc \
-      --replace '$'{exec_prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@ \
-      --replace '$'{prefix}/@CMAKE_INSTALL_INCLUDEDIR@ @CMAKE_INSTALL_FULL_INCLUDEDIR@
-  '';
+  ] ++ lib.optionals usePython [
+    "-DUSE_PYTHON_CONFIG=ON"
+  ];
 
-  postFixup = lib.optionalString (lib.length extraPackages != 0) ''
+  postFixup = lib.optionalString (extraPackages != [ ]) (
     # Join all plugins via symlinking
-    for i in ${toString extraPackages}; do
-      ${buildPackages.xorg.lndir}/bin/lndir -silent $i $out
-    done
-    # Needed for at least the remote plugin server
-    for file in $out/bin/*; do
-        wrapProgram "$file" --prefix SOAPY_SDR_PLUGIN_PATH : ${lib.escapeShellArg extraPackagesSearchPath}
-    done
-  '';
+    lib.pipe extraPackages [
+      (map (pkg: ''
+        ${buildPackages.xorg.lndir}/bin/lndir -silent ${pkg} $out
+      ''))
+      lib.concatStrings
+    ] + ''
+      # Needed for at least the remote plugin server
+      for file in $out/bin/*; do
+          wrapProgram "$file" --prefix SOAPY_SDR_PLUGIN_PATH : ${lib.escapeShellArg (
+            lib.makeSearchPath finalAttrs.passthru.searchPath extraPackages
+          )}
+      done
+    ''
+  );
 
-  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+  passthru = {
+    tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+    searchPath = "lib/SoapySDR/modules${lib.versions.majorMinor finalAttrs.version}";
+  };
 
   meta = with lib; {
     homepage = "https://github.com/pothosware/SoapySDR";
diff --git a/pkgs/applications/radio/soapysdr/fix-pkgconfig.patch b/pkgs/applications/radio/soapysdr/fix-pkgconfig.patch
deleted file mode 100644
index d4b15e3f99bce..0000000000000
--- a/pkgs/applications/radio/soapysdr/fix-pkgconfig.patch
+++ /dev/null
@@ -1,14 +0,0 @@
-diff --git a/lib/SoapySDR.in.pc b/lib/SoapySDR.in.pc
-index a1ca698..fd2f4c0 100644
---- a/lib/SoapySDR.in.pc
-+++ b/lib/SoapySDR.in.pc
-@@ -1,7 +1,5 @@
--prefix=@CMAKE_INSTALL_PREFIX@
--exec_prefix=${prefix}
--libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
--includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
-+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
-+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
- 
- Name: Soapy SDR
- Description: Vendor and platform neutral SDR interface library.