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