|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + python3, |
| 6 | + cmake, |
| 7 | + ninja, |
| 8 | + libsForQt5, |
| 9 | + SDL2, |
| 10 | + fox_1_6, |
| 11 | + replaceVars, |
| 12 | + llvmPackages, |
| 13 | + dfu-util, |
| 14 | + gtest, |
| 15 | + miniz, |
| 16 | + yaml-cpp, |
| 17 | + # List of targets to build simulators for |
| 18 | + targetsToBuild ? import ./targets.nix, |
| 19 | +}: |
| 20 | + |
| 21 | +let |
| 22 | + # Keep in sync with `cmake/FetchMaxLibQt.cmake`. |
| 23 | + maxlibqt = fetchFromGitHub { |
| 24 | + owner = "edgetx"; |
| 25 | + repo = "maxLibQt"; |
| 26 | + rev = "ac1988ffd005cd15a8449b92150ce6c08574a4f1"; |
| 27 | + hash = "sha256-u8e4qseU0+BJyZkV0JE4sUiXaFeIYvadkMTGXXiE2Kg="; |
| 28 | + }; |
| 29 | + |
| 30 | + pythonEnv = python3.withPackages ( |
| 31 | + pyPkgs: with pyPkgs; [ |
| 32 | + pillow |
| 33 | + lz4 |
| 34 | + jinja2 |
| 35 | + libclang |
| 36 | + ] |
| 37 | + ); |
| 38 | +in |
| 39 | + |
| 40 | +stdenv.mkDerivation (finalAttrs: { |
| 41 | + pname = "edgetx"; |
| 42 | + version = "2.11.0-rc3"; |
| 43 | + |
| 44 | + src = fetchFromGitHub { |
| 45 | + owner = "EdgeTX"; |
| 46 | + repo = "edgetx"; |
| 47 | + tag = "v${finalAttrs.version}"; |
| 48 | + fetchSubmodules = true; |
| 49 | + hash = "sha256-ipiGkc+R7/itmnRRrlrc4iXn+fLWm4OKc227NfevFhI="; |
| 50 | + }; |
| 51 | + |
| 52 | + nativeBuildInputs = [ |
| 53 | + cmake |
| 54 | + ninja |
| 55 | + pythonEnv |
| 56 | + libsForQt5.qttools |
| 57 | + libsForQt5.wrapQtAppsHook |
| 58 | + ]; |
| 59 | + |
| 60 | + buildInputs = [ |
| 61 | + libsForQt5.qtbase |
| 62 | + libsForQt5.qtmultimedia |
| 63 | + libsForQt5.qtserialport |
| 64 | + SDL2 |
| 65 | + fox_1_6 |
| 66 | + ]; |
| 67 | + |
| 68 | + patches = [ |
| 69 | + (replaceVars ./0001-libclang-paths.patch ( |
| 70 | + let |
| 71 | + llvmMajor = lib.versions.major llvmPackages.llvm.version; |
| 72 | + in |
| 73 | + { |
| 74 | + resourceDir = "${llvmPackages.clang.cc.lib}/lib/clang/${llvmMajor}"; |
| 75 | + libclang = "${lib.getLib llvmPackages.libclang}/lib/libclang.so"; |
| 76 | + libc-cflags = "${llvmPackages.clang}/nix-support/libc-cflags"; |
| 77 | + libcxx-cflags = "${llvmPackages.clang}/nix-support/libcxx-cxxflags"; |
| 78 | + } |
| 79 | + )) |
| 80 | + ]; |
| 81 | + |
| 82 | + postPatch = '' |
| 83 | + sed -i companion/src/burnconfigdialog.cpp \ |
| 84 | + -e 's|/usr/.*bin/dfu-util|${dfu-util}/bin/dfu-util|' |
| 85 | + patchShebangs companion/util radio/util |
| 86 | + ''; |
| 87 | + |
| 88 | + cmakeFlags = [ |
| 89 | + # Unvendoring these libraries is infeasible. At least lets reuse the same sources. |
| 90 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_GOOGLETEST" "${gtest.src}") |
| 91 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MINIZ" "${miniz.src}") |
| 92 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_YAML-CPP" "${yaml-cpp.src}") |
| 93 | + # Custom library https://github.com/edgetx/maxLibQt. |
| 94 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MAXLIBQT" "${maxlibqt}") |
| 95 | + (lib.cmakeFeature "DFU_UTIL_ROOT_DIR" "${lib.getBin dfu-util}/bin") |
| 96 | + # Superbuild machinery is only getting in the way. |
| 97 | + (lib.cmakeBool "EdgeTX_SUPERBUILD" false) |
| 98 | + # COMMON_OPTIONS from tools/build-companion.sh. |
| 99 | + (lib.cmakeBool "GVARS" true) |
| 100 | + (lib.cmakeBool "HELI" true) |
| 101 | + (lib.cmakeBool "LUA" true) |
| 102 | + # Build companion and not the firmware. |
| 103 | + (lib.cmakeBool "NATIVE_BUILD" true) |
| 104 | + # file RPATH_CHANGE could not write new RPATH. |
| 105 | + (lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true) |
| 106 | + ]; |
| 107 | + |
| 108 | + env = { |
| 109 | + EDGETX_VERSION_SUFFIX = "nixpkgs"; |
| 110 | + }; |
| 111 | + |
| 112 | + dontUseCmakeConfigure = true; |
| 113 | + # We invoke cmakeConfigurePhase multiple times, but only need this once. |
| 114 | + dontFixCmake = true; |
| 115 | + inherit targetsToBuild; |
| 116 | + __structuredAttrs = true; # To pass targetsToBuild as an array. |
| 117 | + |
| 118 | + configurePhase = '' |
| 119 | + runHook preConfigure |
| 120 | + prependToVar cmakeFlags "-GNinja" |
| 121 | + fixCmakeFiles . |
| 122 | + runHook postConfigure |
| 123 | + ''; |
| 124 | + |
| 125 | + buildPhase = '' |
| 126 | + runHook preBuild |
| 127 | +
|
| 128 | + cmakeCommonFlags="$''\{cmakeFlags[@]}" |
| 129 | + # This is the most sensible way to convert target name -> cmake options |
| 130 | + # aside from manually extracting bash variables from upstream's CI scripts |
| 131 | + # and converting that to nix expressions. Let's hope upstream doesn't break |
| 132 | + # this file too often. |
| 133 | + source $src/tools/build-common.sh |
| 134 | +
|
| 135 | + # Yes, this is really how upstream expects packaging to look like ¯\_(ツ)_/¯. |
| 136 | + # https://github.com/EdgeTX/edgetx/wiki/Build-Instructions-under-Ubuntu-20.04#building-companion-simulator-and-radio-simulator-libraries |
| 137 | + for plugin in "$''\{targetsToBuild[@]''\}" |
| 138 | + do |
| 139 | + # Variable modified by `get_target_build_options` from build-common.sh. |
| 140 | + local BUILD_OPTIONS="" |
| 141 | + get_target_build_options "$plugin" |
| 142 | + # With each invocation of `cmakeConfigurePhase` `cmakeFlags` gets |
| 143 | + # prepended to, so it has to be reset. |
| 144 | + cmakeFlags=() |
| 145 | + appendToVar cmakeFlags $cmakeCommonFlags $BUILD_OPTIONS |
| 146 | + pushd . |
| 147 | + cmakeConfigurePhase |
| 148 | + ninjaFlags=("libsimulator") |
| 149 | + ninjaBuildPhase |
| 150 | + rm CMakeCache.txt |
| 151 | + popd |
| 152 | + done |
| 153 | +
|
| 154 | + cmakeConfigurePhase |
| 155 | + ninjaFlags=() |
| 156 | + ninjaBuildPhase |
| 157 | +
|
| 158 | + runHook postBuild |
| 159 | + ''; |
| 160 | + |
| 161 | + meta = { |
| 162 | + description = "EdgeTX Companion transmitter support software"; |
| 163 | + longDescription = '' |
| 164 | + EdgeTX Companion is used for many different tasks like loading EdgeTX |
| 165 | + firmware to the radio, backing up model settings, editing settings and |
| 166 | + running radio simulators. |
| 167 | + ''; |
| 168 | + mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion finalAttrs.version)); |
| 169 | + homepage = "https://edgetx.org/"; |
| 170 | + license = lib.licenses.gpl2Only; |
| 171 | + platforms = [ |
| 172 | + "i686-linux" |
| 173 | + "x86_64-linux" |
| 174 | + "aarch64-linux" |
| 175 | + ]; |
| 176 | + maintainers = with lib.maintainers; [ |
| 177 | + elitak |
| 178 | + lopsided98 |
| 179 | + wucke13 |
| 180 | + xokdvium |
| 181 | + ]; |
| 182 | + }; |
| 183 | +}) |
0 commit comments