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