18 gsettings-desktop-schemas,
27 withNgspice ? !stdenv.hostPlatform.isDarwin,
33 sanitizeAddress ? false,
34 sanitizeThreads ? false,
40 # `addons`: https://dev-docs.kicad.org/en/addons/
43 # kicad = pkgs.kicad.override {
44 # addons = with pkgs.kicadAddons; [ kikit kikit-library ];
48 # The `srcs` parameter can be used to override the kicad source code
49 # and all libraries, which are otherwise inaccessible
50 # to overlays since most of the kicad build expression has been
51 # refactored into base.nix, most of the library build expressions have
52 # been refactored into libraries.nix. Overrides are only applied when
53 # building `kicad-unstable`. The `srcs` parameter has
54 # no effect for stable `kicad`. `srcs` takes an attribute set in which
55 # any of the following attributes are meaningful (though none are
56 # mandatory): "kicad", "kicadVersion", "symbols", "templates",
57 # "footprints", "packages3d", and "libVersion". "kicadVersion" and
58 # "libVersion" should be set to a string with the desired value for
59 # the version attribute in kicad's `mkDerivation` and the version
60 # attribute in any of the library's `mkDerivation`, respectively.
61 # "kicad", "symbols", "templates", "footprints", and "packages3d"
62 # should be set to an appropriate fetcher (e.g. `fetchFromGitLab`).
63 # So, for example, a possible overlay for kicad is:
68 # kicad-unstable = (prev.kicad-unstable.override {
70 # kicadVersion = "2020-10-08";
71 # kicad = prev.fetchFromGitLab {
75 # rev = "fd22fe8e374ce71d57e9f683ba996651aa69fa4e";
76 # sha256 = "sha256-F8qugru/jU3DgZSpQXQhRGNFSk0ybFRkpyWb7HAGBdc=";
90 versionsImport = import ./versions.nix;
92 # versions.nix does not provide us with version, src and rev. We
93 # need to turn this into approprate fetcher calls.
94 kicadSrcFetch = fetchFromGitLab {
98 rev = versionsImport.${baseName}.kicadVersion.src.rev;
99 sha256 = versionsImport.${baseName}.kicadVersion.src.sha256;
107 repo = "kicad-${name}";
108 rev = versionsImport.${baseName}.libVersion.libSources.${name}.rev;
109 sha256 = versionsImport.${baseName}.libVersion.libSources.${name}.sha256;
112 # only override `src` or `version` if building `kicad-unstable` with
113 # the appropriate attribute defined in `srcs`.
114 srcOverridep = attr: (!stable && builtins.hasAttr attr srcs);
116 # use default source and version (as defined in versions.nix) by
117 # default, or use the appropriate attribute from `srcs` if building
118 # unstable with `srcs` properly defined.
119 kicadSrc = if srcOverridep "kicad" then srcs.kicad else kicadSrcFetch;
121 if srcOverridep "kicadVersion" then
124 versionsImport.${baseName}.kicadVersion.version;
126 libSrc = name: if srcOverridep name then srcs.${name} else libSrcFetch name;
127 # TODO does it make sense to only have one version for all libs?
129 if srcOverridep "libVersion" then
132 versionsImport.${baseName}.libVersion.version;
136 wxPython = python.pkgs.wxpython;
137 addonPath = "addon.zip";
138 addonsDrvs = map (pkg: pkg.override { inherit addonPath python3; }) addons;
141 runCommand "addonsJoined"
144 nativeBuildInputs = [
152 for pkg in $addonsDrvs; do
153 unzip $pkg/addon.zip -d unpacked
155 folder_name=$(jq .identifier unpacked/metadata.json --raw-output | tr . _)
156 for d in unpacked/*; do
158 dest=$out/share/kicad/scripting/$(basename $d)/$folder_name
159 mkdir -p $(dirname $dest)
175 stdenv.mkDerivation rec {
177 # Common libraries, referenced during runtime, via the wrapper.
178 passthru.libraries = callPackages ./libraries.nix { inherit libSrc; };
179 passthru.callPackage = newScope { inherit addonPath python3; };
180 base = callPackage ./base.nix {
181 inherit stable testing baseName;
182 inherit kicadSrc kicadVersion;
183 inherit wxGTK python wxPython;
184 inherit withNgspice withScripting withI18n;
185 inherit debug sanitizeAddress sanitizeThreads;
189 version = if (stable) then kicadVersion else builtins.substring 0 10 src.src.rev;
193 dontConfigure = true;
198 optionals (withScripting) [
205 nativeBuildInputs = [ makeWrapper ] ++ optionals (withScripting) [ python.pkgs.wrapPython ];
207 # KICAD7_TEMPLATE_DIR only works with a single path (it does not handle : separated paths)
208 # but it's used to find both the templates and the symbol/footprint library tables
209 # https://gitlab.com/kicad/code/kicad/-/issues/14792
210 template_dir = symlinkJoin {
211 name = "KiCad_template_dir";
212 paths = with passthru.libraries; [
213 "${templates}/share/kicad/template"
214 "${footprints}/share/kicad/template"
215 "${symbols}/share/kicad/template"
218 # We are emulating wrapGAppsHook3, along with other variables to the wrapper
220 with passthru.libraries;
222 "--prefix XDG_DATA_DIRS : ${base}/share"
223 "--prefix XDG_DATA_DIRS : ${hicolor-icon-theme}/share"
224 "--prefix XDG_DATA_DIRS : ${adwaita-icon-theme}/share"
225 "--prefix XDG_DATA_DIRS : ${gtk3}/share/gsettings-schemas/${gtk3.name}"
226 "--prefix XDG_DATA_DIRS : ${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
227 # wrapGAppsHook3 did these two as well, no idea if it matters...
228 "--prefix XDG_DATA_DIRS : ${cups}/share"
229 "--prefix GIO_EXTRA_MODULES : ${dconf}/lib/gio/modules"
230 # required to open a bug report link in firefox-wayland
231 "--set-default MOZ_DBUS_REMOTE 1"
232 "--set-default KICAD8_FOOTPRINT_DIR ${footprints}/share/kicad/footprints"
233 "--set-default KICAD8_SYMBOL_DIR ${symbols}/share/kicad/symbols"
234 "--set-default KICAD8_TEMPLATE_DIR ${template_dir}"
236 ++ optionals (addons != [ ]) (
238 stockDataPath = symlinkJoin {
239 name = "kicad_stock_data_path";
241 "${base}/share/kicad"
242 "${addonsJoined}/share/kicad"
246 [ "--set-default NIX_KICAD8_STOCK_DATA_PATH ${stockDataPath}" ]
248 ++ optionals (with3d) [
249 "--set-default KICAD8_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels"
251 ++ optionals (withNgspice) [ "--prefix LD_LIBRARY_PATH : ${libngspice}/lib" ]
253 # infinisil's workaround for #39493
254 ++ [ "--set GDK_PIXBUF_MODULE_FILE ${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ];
256 # why does $makeWrapperArgs have to be added explicitly?
257 # $out and $program_PYTHONPATH don't exist when makeWrapperArgs gets set?
260 bin = if stdenv.hostPlatform.isDarwin then "*.app/Contents/MacOS" else "bin";
278 (concatStringsSep "\n" (flatten [
281 (optionalString (withScripting) "buildPythonPath \"${base} $pythonPath\" \n")
283 # wrap each of the directly usable tools
286 "makeWrapper ${base}/${bin}/${tool} $out/bin/${tool} $makeWrapperArgs"
287 + optionalString (withScripting) " --set PYTHONPATH \"$program_PYTHONPATH\""
290 # link in the CLI utils
291 (map (util: "ln -s ${base}/${bin}/${util} $out/bin/${util}") utils)
293 "runHook postInstall"
298 ln -s ${base}/share/applications $out/share/applications
299 ln -s ${base}/share/icons $out/share/icons
300 ln -s ${base}/share/mime $out/share/mime
301 ln -s ${base}/share/metainfo $out/share/metainfo
304 passthru.updateScript = {
309 supportedFeatures = [ "commit" ];
316 "Open Source Electronics Design Automation suite"
317 else if (testing) then
318 "Open Source EDA suite, latest on stable branch"
320 "Open Source EDA suite, latest on master branch"
322 + (lib.optionalString (!with3d) ", without 3D models");
323 homepage = "https://www.kicad.org/";
325 KiCad is an open source software suite for Electronic Design Automation.
326 The Programs handle Schematic Capture, and PCB Layout with Gerber output.
328 license = lib.licenses.gpl3Plus;
329 maintainers = with lib.maintainers; [ evils ];
330 platforms = lib.platforms.all;
331 broken = stdenv.hostPlatform.isDarwin;
332 mainProgram = "kicad";