Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 65 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -48,8 +63,8 @@

# OpenMP support for fftw3_omp
llvmPackages.openmp

# For building
] ++ lib.optionals isLinux [
# For building on Linux
gcc
];

Expand All @@ -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:"
Expand All @@ -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}"
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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
Expand All @@ -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";
};
};
});
}

Loading