1{
2 lib,
3 stdenv,
4 cmake,
5 libGLU,
6 libGL,
7 zlib,
8 wxGTK,
9 gtk3,
10 libX11,
11 gettext,
12 glew,
13 glm,
14 cairo,
15 curl,
16 openssl,
17 boost,
18 pkg-config,
19 doxygen,
20 graphviz,
21 libpthreadstubs,
22 libXdmcp,
23 unixODBC,
24 libgit2,
25 libsecret,
26 libgcrypt,
27 libgpg-error,
28 ninja,
29
30 util-linux,
31 libselinux,
32 libsepol,
33 libthai,
34 libdatrie,
35 libxkbcommon,
36 libepoxy,
37 dbus,
38 at-spi2-core,
39 libXtst,
40 pcre2,
41 libdeflate,
42
43 swig,
44 python,
45 wxPython,
46 opencascade-occt_7_6,
47 libngspice,
48 valgrind,
49 protobuf_29,
50 nng,
51
52 stable,
53 testing,
54 baseName,
55 kicadSrc,
56 kicadVersion,
57 withNgspice,
58 withScripting,
59 withI18n,
60 debug,
61 sanitizeAddress,
62 sanitizeThreads,
63}:
64
65assert lib.assertMsg (
66 !(sanitizeAddress && sanitizeThreads)
67) "'sanitizeAddress' and 'sanitizeThreads' are mutually exclusive, use one.";
68assert testing -> !stable -> throw "testing implies stable and cannot be used with stable = false";
69
70let
71 opencascade-occt = opencascade-occt_7_6;
72 inherit (lib) optional optionals optionalString;
73in
74stdenv.mkDerivation rec {
75 pname = "kicad-base";
76 version = if (stable) then kicadVersion else builtins.substring 0 10 src.rev;
77
78 src = kicadSrc;
79
80 patches = [
81 # upstream issue 12941 (attempted to upstream, but appreciably unacceptable)
82 ./writable.patch
83 # https://gitlab.com/kicad/code/kicad/-/issues/15687
84 ./runtime_stock_data_path.patch
85 ];
86
87 # tagged releases don't have "unknown"
88 # kicad testing and nightlies use git describe --dirty
89 # nix removes .git, so its approximated here
90 postPatch = lib.optionalString (!stable || testing) ''
91 substituteInPlace cmake/KiCadVersion.cmake \
92 --replace "unknown" "${builtins.substring 0 10 src.rev}"
93
94 substituteInPlace cmake/CreateGitVersionHeader.cmake \
95 --replace "0000000000000000000000000000000000000000" "${src.rev}"
96 '';
97
98 preConfigure = optional (debug) ''
99 export CFLAGS="''${CFLAGS:-} -Og -ggdb"
100 export CXXFLAGS="''${CXXFLAGS:-} -Og -ggdb"
101 '';
102
103 cmakeFlags = [
104 "-DKICAD_USE_EGL=ON"
105 "-DOCC_INCLUDE_DIR=${opencascade-occt}/include/opencascade"
106 # https://gitlab.com/kicad/code/kicad/-/issues/17133
107 "-DCMAKE_CTEST_ARGUMENTS='--exclude-regex;qa_spice'"
108 "-DKICAD_USE_CMAKE_FINDPROTOBUF=OFF"
109 ]
110 ++ optional (
111 stdenv.hostPlatform.system == "aarch64-linux"
112 ) "-DCMAKE_CTEST_ARGUMENTS=--exclude-regex;'qa_spice|qa_cli'"
113 ++ optional (stable && !withNgspice) "-DKICAD_SPICE=OFF"
114 ++ optionals (!withScripting) [
115 "-DKICAD_SCRIPTING_WXPYTHON=OFF"
116 ]
117 ++ optionals (withI18n) [
118 "-DKICAD_BUILD_I18N=ON"
119 ]
120 ++ optionals (!doInstallCheck) [
121 "-DKICAD_BUILD_QA_TESTS=OFF"
122 ]
123 ++ optionals (debug) [
124 "-DKICAD_STDLIB_DEBUG=ON"
125 "-DKICAD_USE_VALGRIND=ON"
126 ]
127 ++ optionals (sanitizeAddress) [
128 "-DKICAD_SANITIZE_ADDRESS=ON"
129 ]
130 ++ optionals (sanitizeThreads) [
131 "-DKICAD_SANITIZE_THREADS=ON"
132 ];
133
134 cmakeBuildType = if debug then "Debug" else "Release";
135
136 nativeBuildInputs = [
137 cmake
138 ninja
139 doxygen
140 graphviz
141 pkg-config
142 libgit2
143 libsecret
144 libgcrypt
145 libgpg-error
146 ]
147 # wanted by configuration on linux, doesn't seem to affect performance
148 # no effect on closure size
149 ++ optionals (stdenv.hostPlatform.isLinux) [
150 util-linux
151 libselinux
152 libsepol
153 libthai
154 libdatrie
155 libxkbcommon
156 libepoxy
157 dbus
158 at-spi2-core
159 libXtst
160 pcre2
161 ];
162
163 buildInputs = [
164 libGLU
165 libGL
166 zlib
167 libX11
168 wxGTK
169 gtk3
170 libXdmcp
171 gettext
172 glew
173 glm
174 libpthreadstubs
175 cairo
176 curl
177 openssl
178 boost
179 swig
180 python
181 unixODBC
182 libdeflate
183 opencascade-occt
184 protobuf_29
185
186 # This would otherwise cause a linking requirement for mbedtls.
187 (nng.override { mbedtlsSupport = false; })
188 ]
189 ++ optional (withScripting) wxPython
190 ++ optional (withNgspice) libngspice
191 ++ optional (debug) valgrind;
192
193 # some ngspice tests attempt to write to $HOME/.cache/
194 # this could be and was resolved with XDG_CACHE_HOME = "$TMP";
195 # but failing tests still attempt to create $HOME
196 # and the newer CLI tests seem to also use $HOME...
197 HOME = "$TMP";
198
199 # debug builds fail all but the python test
200 doInstallCheck = !(debug);
201 installCheckTarget = "test";
202
203 nativeInstallCheckInputs = [
204 (python.withPackages (
205 ps: with ps; [
206 numpy
207 pytest
208 cairosvg
209 pytest-image-diff
210 ]
211 ))
212 ];
213
214 dontStrip = debug;
215
216 meta = {
217 description = "Just the built source without the libraries";
218 longDescription = ''
219 Just the build products, the libraries are passed via an env var in the wrapper, default.nix
220 '';
221 homepage = "https://www.kicad.org/";
222 license = lib.licenses.gpl3Plus;
223 platforms = lib.platforms.all;
224 broken = stdenv.hostPlatform.isDarwin;
225 };
226}