about summary refs log tree commit diff
path: root/pkgs/applications/radio/sdrpp
diff options
context:
space:
mode:
authorNikolay Korotkiy <sikmir@gmail.com>2021-10-28 15:34:46 +0300
committerNikolay Korotkiy <sikmir@gmail.com>2021-10-29 03:10:26 +0300
commit049264c39b153a59c0bc01ed33e788ad0a3cf393 (patch)
tree586dea35959310e0973feae936f1d6dc34ba53db /pkgs/applications/radio/sdrpp
parent19b87ec97df2819e4f4862d1c7521a4fec2e20fc (diff)
sdrpp: enable on darwin
Diffstat (limited to 'pkgs/applications/radio/sdrpp')
-rw-r--r--pkgs/applications/radio/sdrpp/default.nix17
-rw-r--r--pkgs/applications/radio/sdrpp/runtime-prefix.patch60
2 files changed, 73 insertions, 4 deletions
diff --git a/pkgs/applications/radio/sdrpp/default.nix b/pkgs/applications/radio/sdrpp/default.nix
index 2324d400323ae..5a993f4fc1002 100644
--- a/pkgs/applications/radio/sdrpp/default.nix
+++ b/pkgs/applications/radio/sdrpp/default.nix
@@ -1,5 +1,5 @@
 { stdenv, lib, fetchFromGitHub, cmake, pkg-config
-, libX11, glfw, glew, fftwFloat, volk
+, libX11, glfw, glew, fftwFloat, volk, AppKit
 # Sources
 , airspy_source ? true, airspy
 , airspyhf_source ? true, airspyhf
@@ -13,7 +13,7 @@
 , sdrplay_source ? false, sdrplay
 , soapy_source ? true, soapysdr
 , spyserver_source ? true
-, plutosdr_source ? true, libiio, libad9361
+, plutosdr_source ? stdenv.isLinux, libiio, libad9361
 # Sinks
 , audio_sink ? true, rtaudio
 , portaudio_sink ? false, portaudio
@@ -42,9 +42,12 @@ stdenv.mkDerivation rec {
     hash = "sha256-g9tpWvVRMXRhPfgvOeJhX6IMouF9+tLUr9wo5r35i/c=";
   };
 
+  patches = [ ./runtime-prefix.patch ];
+
   postPatch = ''
     substituteInPlace CMakeLists.txt \
-      --replace "/usr" $out
+      --replace "/usr/share" "share" \
+      --replace "set(CMAKE_INSTALL_PREFIX" "#set(CMAKE_INSTALL_PREFIX"
     substituteInPlace decoder_modules/m17_decoder/src/m17dsp.h \
       --replace "codec2.h" "codec2/codec2.h"
   '';
@@ -52,6 +55,7 @@ stdenv.mkDerivation rec {
   nativeBuildInputs = [ cmake pkg-config ];
 
   buildInputs = [ glfw glew fftwFloat volk ]
+    ++ lib.optional stdenv.isDarwin AppKit
     ++ lib.optional stdenv.isLinux libX11
     ++ lib.optional airspy_source airspy
     ++ lib.optional airspyhf_source airspyhf
@@ -95,13 +99,18 @@ stdenv.mkDerivation rec {
     OPT_BUILD_RIGCTL_SERVER = rigctl_server;
   };
 
+  CXXFLAGS = lib.optional stdenv.cc.isClang "-std=c++17";
+  LDFLAGS = lib.optional stdenv.cc.isClang "-lc++fs";
+
   NIX_CFLAGS_COMPILE = "-fpermissive";
 
+  hardeningDisable = lib.optional stdenv.cc.isClang "format";
+
   meta = with lib; {
     description = "Cross-Platform SDR Software";
     homepage = "https://github.com/AlexandreRouma/SDRPlusPlus";
     license = licenses.gpl3Only;
-    platforms = platforms.linux;
+    platforms = platforms.unix;
     maintainers = with maintainers; [ sikmir ];
   };
 }
diff --git a/pkgs/applications/radio/sdrpp/runtime-prefix.patch b/pkgs/applications/radio/sdrpp/runtime-prefix.patch
new file mode 100644
index 0000000000000..55ecd8ce3eee0
--- /dev/null
+++ b/pkgs/applications/radio/sdrpp/runtime-prefix.patch
@@ -0,0 +1,60 @@
+From a80a739163d2013ec400223a68a387f4f9297b2a Mon Sep 17 00:00:00 2001
+From: Nikolay Korotkiy <sikmir@gmail.com>
+Date: Fri, 29 Oct 2021 01:38:21 +0300
+Subject: [PATCH] Fix sdrpp breaking every time the package is rebuilt.
+
+On NixOS, the INSTALL_PREFIX changes on every rebuild to the package, but sdrpp
+fills it in as part of the default config and then installs that config
+to the users home folder. Fix this by not substituting @INSTALL_PREFIX@ in the
+default config until runtime.
+---
+ core/src/core.cpp            | 8 ++++++--
+ core/src/gui/main_window.cpp | 6 ++++++
+ 2 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/core/src/core.cpp b/core/src/core.cpp
+index 9546e60..98d6065 100644
+--- a/core/src/core.cpp
++++ b/core/src/core.cpp
+@@ -242,8 +242,8 @@ int sdrpp_main(int argc, char *argv[]) {
+     defConfig["modulesDirectory"] = "./modules";
+     defConfig["resourcesDirectory"] = "./res";
+ #else
+-    defConfig["modulesDirectory"] = INSTALL_PREFIX "/lib/sdrpp/plugins";
+-    defConfig["resourcesDirectory"] = INSTALL_PREFIX "/share/sdrpp";
++    defConfig["modulesDirectory"] = "@prefix@/lib/sdrpp/plugins";
++    defConfig["resourcesDirectory"] = "@prefix@/share/sdrpp";
+ #endif
+ 
+     // Load config
+@@ -290,6 +290,10 @@ int sdrpp_main(int argc, char *argv[]) {
+     int winHeight = core::configManager.conf["windowSize"]["h"];
+     maximized = core::configManager.conf["maximized"];
+     std::string resDir = core::configManager.conf["resourcesDirectory"];
++    {
++        std::size_t pos = resDir.find("@prefix@");
++        if (pos != std::string::npos) resDir.replace(pos, 8, INSTALL_PREFIX);
++    }
+     json bandColors = core::configManager.conf["bandColors"];
+     core::configManager.release();
+ 
+diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp
+index 954dbd6..52f0eed 100644
+--- a/core/src/gui/main_window.cpp
++++ b/core/src/gui/main_window.cpp
+@@ -44,6 +44,12 @@ void MainWindow::init() {
+     json menuElements = core::configManager.conf["menuElements"];
+     std::string modulesDir = core::configManager.conf["modulesDirectory"];
+     std::string resourcesDir = core::configManager.conf["resourcesDirectory"];
++    {
++        std::size_t pos = modulesDir.find("@prefix@");
++        if (pos != std::string::npos) modulesDir.replace(pos, 8, INSTALL_PREFIX);
++        pos = resourcesDir.find("@prefix@");
++        if (pos != std::string::npos) resourcesDir.replace(pos, 8, INSTALL_PREFIX);
++    }
+     core::configManager.release();
+ 
+     // Load menu elements
+-- 
+2.33.0
+