From c9fcee93a0b8ece1ab6be312865e426d712bd8ec Mon Sep 17 00:00:00 2001 From: "randomizedcoder dave.seddon.ca@gmail.com" Date: Mon, 5 Jan 2026 08:16:04 -0800 Subject: [PATCH] flake.nix: add macOS (Darwin) support - Add platform detection for Darwin vs Linux - Handle different libdfuprog paths and extensions (.so/.dylib) - Use appropriate library path env var (LD_LIBRARY_PATH/DYLD_LIBRARY_PATH) - Handle binary name differences (labrador/Labrador) - Install icons and desktop files only on Linux - Use sysctl fallback for CPU count on macOS - Update platforms to include darwin --- flake.nix | 89 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/flake.nix b/flake.nix index 15e1a62d..0d3b9fa1 100644 --- a/flake.nix +++ b/flake.nix @@ -13,13 +13,28 @@ inherit system; }; - # Map Nix system to Qt arch naming - qtArch = { + inherit (pkgs) lib stdenv; + + # Platform detection + isDarwin = stdenv.isDarwin; + isLinux = stdenv.isLinux; + + # Map Nix system to architecture names used in bundled libdfuprog (Linux only) + dfuprogArch = { "x86_64-linux" = "x86_64"; "aarch64-linux" = "arm64"; "i686-linux" = "i386"; "armv7l-linux" = "arm"; - }.${system} or "x86_64"; + }.${system} or null; + + # Library file extension differs between platforms + libExt = if isDarwin then "dylib" else "so"; + + # Build directory differs between platforms + buildDir = if isDarwin then "build_mac" else "build_linux"; + + # Library path environment variable differs between platforms + libPathVar = if isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; in { @@ -48,8 +63,8 @@ # OpenMP support for fftw3_omp llvmPackages.openmp - - # For building + ] ++ lib.optionals isLinux [ + # For building on Linux gcc ]; @@ -59,10 +74,12 @@ echo "║ EspoTek Labrador Development Environment ║" echo "╚══════════════════════════════════════════════════════════════════╝" echo "" + echo "Platform: ${if isDarwin then "macOS" else "Linux"}" + echo "" echo "To build and install locally:" echo " cd Desktop_Interface" echo " qmake PREFIX=\$PWD/_install" - echo " make -j\$(nproc)" + echo " make -j\$(nproc 2>/dev/null || sysctl -n hw.ncpu)" echo " make install" echo "" echo "To run after installing:" @@ -72,7 +89,11 @@ echo "" # Ensure the bundled libdfuprog can be found - export LD_LIBRARY_PATH="$PWD/Desktop_Interface/build_linux/libdfuprog/lib/${qtArch}:$LD_LIBRARY_PATH" + ${if isDarwin then '' + export DYLD_LIBRARY_PATH="$PWD/Desktop_Interface/${buildDir}/libdfuprog/lib:$DYLD_LIBRARY_PATH" + '' else '' + export LD_LIBRARY_PATH="$PWD/Desktop_Interface/${buildDir}/libdfuprog/lib/${dfuprogArch}:$LD_LIBRARY_PATH" + ''} # Help Qt find plugins export QT_PLUGIN_PATH="${pkgs.qt5.qtbase}/${pkgs.qt5.qtbase.qtPluginPrefix}" @@ -104,15 +125,22 @@ llvmPackages.openmp ]; - # Patch the .pro file to use system libraries and skip udev rules installation preConfigure = '' cd Desktop_Interface # Create a library path for the bundled libdfuprog mkdir -p $out/lib - # Copy the appropriate libdfuprog for this architecture - cp build_linux/libdfuprog/lib/${qtArch}/libdfuprog-0.9.so $out/lib/ + # Copy the appropriate libdfuprog for this platform/architecture + ${if isDarwin then '' + if [ -f "${buildDir}/libdfuprog/lib/libdfuprog-0.9.${libExt}" ]; then + cp ${buildDir}/libdfuprog/lib/libdfuprog-0.9.${libExt} $out/lib/ + fi + '' else if dfuprogArch != null then '' + if [ -f "${buildDir}/libdfuprog/lib/${dfuprogArch}/libdfuprog-0.9.${libExt}" ]; then + cp ${buildDir}/libdfuprog/lib/${dfuprogArch}/libdfuprog-0.9.${libExt} $out/lib/ + fi + '' else ""} ''; configurePhase = '' @@ -130,9 +158,13 @@ installPhase = '' runHook preInstall - # Install binary + # Install binary (name differs on macOS) mkdir -p $out/bin - cp labrador $out/bin/ + if [ -f labrador ]; then + cp labrador $out/bin/ + elif [ -f Labrador ]; then + cp Labrador $out/bin/labrador + fi # Install firmware mkdir -p $out/share/EspoTek/Labrador/firmware @@ -142,32 +174,41 @@ mkdir -p $out/share/EspoTek/Labrador/waveforms cp resources/waveforms/* $out/share/EspoTek/Labrador/waveforms/ - # Install icons - mkdir -p $out/share/icons/hicolor/48x48/apps - mkdir -p $out/share/icons/hicolor/256x256/apps - cp build_linux/icon48/espotek-labrador.png $out/share/icons/hicolor/48x48/apps/ - cp build_linux/icon256/espotek-labrador.png $out/share/icons/hicolor/256x256/apps/ + ${lib.optionalString isLinux '' + # Install icons (Linux only) + mkdir -p $out/share/icons/hicolor/48x48/apps + mkdir -p $out/share/icons/hicolor/256x256/apps + cp build_linux/icon48/espotek-labrador.png $out/share/icons/hicolor/48x48/apps/ + cp build_linux/icon256/espotek-labrador.png $out/share/icons/hicolor/256x256/apps/ - # Install desktop file - mkdir -p $out/share/applications - cp build_linux/espotek-labrador.desktop $out/share/applications/ + # Install desktop file (Linux only) + mkdir -p $out/share/applications + cp build_linux/espotek-labrador.desktop $out/share/applications/ + ''} runHook postInstall ''; # Wrap the executable to find libdfuprog - preFixup = '' + preFixup = if isDarwin then '' + qtWrapperArgs+=(--prefix DYLD_LIBRARY_PATH : "$out/lib") + '' else '' qtWrapperArgs+=(--prefix LD_LIBRARY_PATH : "$out/lib") ''; meta = with pkgs.lib; { description = "EspoTek Labrador - oscilloscope, signal generator, logic analyzer, and more"; + longDescription = '' + The EspoTek Labrador is an open-source board that turns your PC into a + full-featured electronics lab bench, complete with oscilloscope, signal + generator, logic analyzer, and more. This package provides the Qt5 + desktop application for interfacing with the Labrador hardware. + ''; homepage = "https://github.com/espotek-org/Labrador"; - license = licenses.gpl3; - platforms = platforms.linux; + license = licenses.gpl3Only; + platforms = platforms.linux ++ platforms.darwin; mainProgram = "labrador"; }; }; }); } -