16 , gsettings-desktop-schemas
25 , withNgspice ? !stdenv.hostPlatform.isDarwin
27 , withScripting ? true
31 , sanitizeAddress ? false
32 , sanitizeThreads ? false
38 # `addons`: https://dev-docs.kicad.org/en/addons/
41 # kicad = pkgs.kicad.override {
42 # addons = with pkgs.kicadAddons; [ kikit kikit-library ];
46 # The `srcs` parameter can be used to override the kicad source code
47 # and all libraries, which are otherwise inaccessible
48 # to overlays since most of the kicad build expression has been
49 # refactored into base.nix, most of the library build expressions have
50 # been refactored into libraries.nix. Overrides are only applied when
51 # building `kicad-unstable`. The `srcs` parameter has
52 # no effect for stable `kicad`. `srcs` takes an attribute set in which
53 # any of the following attributes are meaningful (though none are
54 # mandatory): "kicad", "kicadVersion", "symbols", "templates",
55 # "footprints", "packages3d", and "libVersion". "kicadVersion" and
56 # "libVersion" should be set to a string with the desired value for
57 # the version attribute in kicad's `mkDerivation` and the version
58 # attribute in any of the library's `mkDerivation`, respectively.
59 # "kicad", "symbols", "templates", "footprints", and "packages3d"
60 # should be set to an appropriate fetcher (e.g. `fetchFromGitLab`).
61 # So, for example, a possible overlay for kicad is:
66 # kicad-unstable = (prev.kicad-unstable.override {
68 # kicadVersion = "2020-10-08";
69 # kicad = prev.fetchFromGitLab {
73 # rev = "fd22fe8e374ce71d57e9f683ba996651aa69fa4e";
74 # sha256 = "sha256-F8qugru/jU3DgZSpQXQhRGNFSk0ybFRkpyWb7HAGBdc=";
81 baseName = if (testing) then "kicad-testing"
82 else if (stable) then "kicad"
83 else "kicad-unstable";
84 versionsImport = import ./versions.nix;
86 # versions.nix does not provide us with version, src and rev. We
87 # need to turn this into approprate fetcher calls.
88 kicadSrcFetch = fetchFromGitLab {
92 rev = versionsImport.${baseName}.kicadVersion.src.rev;
93 sha256 = versionsImport.${baseName}.kicadVersion.src.sha256;
96 libSrcFetch = name: fetchFromGitLab {
99 repo = "kicad-${name}";
100 rev = versionsImport.${baseName}.libVersion.libSources.${name}.rev;
101 sha256 = versionsImport.${baseName}.libVersion.libSources.${name}.sha256;
104 # only override `src` or `version` if building `kicad-unstable` with
105 # the appropriate attribute defined in `srcs`.
106 srcOverridep = attr: (!stable && builtins.hasAttr attr srcs);
108 # use default source and version (as defined in versions.nix) by
109 # default, or use the appropriate attribute from `srcs` if building
110 # unstable with `srcs` properly defined.
112 if srcOverridep "kicad" then srcs.kicad
115 if srcOverridep "kicadVersion" then srcs.kicadVersion
116 else versionsImport.${baseName}.kicadVersion.version;
118 libSrc = name: if srcOverridep name then srcs.${name} else libSrcFetch name;
119 # TODO does it make sense to only have one version for all libs?
121 if srcOverridep "libVersion" then srcs.libVersion
122 else versionsImport.${baseName}.libVersion.version;
126 wxPython = python.pkgs.wxpython;
127 addonPath = "addon.zip";
128 addonsDrvs = map (pkg: pkg.override { inherit addonPath python3; }) addons;
131 runCommand "addonsJoined"
134 nativeBuildInputs = [ unzip jq ];
138 for pkg in $addonsDrvs; do
139 unzip $pkg/addon.zip -d unpacked
141 folder_name=$(jq .identifier unpacked/metadata.json --raw-output | tr . _)
142 for d in unpacked/*; do
144 dest=$out/share/kicad/scripting/$(basename $d)/$folder_name
145 mkdir -p $(dirname $dest)
154 inherit (lib) concatStringsSep flatten optionalString optionals;
156 stdenv.mkDerivation rec {
158 # Common libraries, referenced during runtime, via the wrapper.
159 passthru.libraries = callPackages ./libraries.nix { inherit libSrc; };
160 passthru.callPackage = newScope { inherit addonPath python3; };
161 base = callPackage ./base.nix {
162 inherit stable testing baseName;
163 inherit kicadSrc kicadVersion;
164 inherit wxGTK python wxPython;
165 inherit withNgspice withScripting withI18n;
166 inherit debug sanitizeAddress sanitizeThreads;
170 version = if (stable) then kicadVersion else builtins.substring 0 10 src.src.rev;
174 dontConfigure = true;
178 pythonPath = optionals (withScripting)
179 [ wxPython python.pkgs.six python.pkgs.requests ] ++ addonsDrvs;
181 nativeBuildInputs = [ makeWrapper ]
182 ++ optionals (withScripting)
183 [ python.pkgs.wrapPython ];
185 # KICAD7_TEMPLATE_DIR only works with a single path (it does not handle : separated paths)
186 # but it's used to find both the templates and the symbol/footprint library tables
187 # https://gitlab.com/kicad/code/kicad/-/issues/14792
188 template_dir = symlinkJoin {
189 name = "KiCad_template_dir";
190 paths = with passthru.libraries; [
191 "${templates}/share/kicad/template"
192 "${footprints}/share/kicad/template"
193 "${symbols}/share/kicad/template"
196 # We are emulating wrapGAppsHook3, along with other variables to the wrapper
197 makeWrapperArgs = with passthru.libraries; [
198 "--prefix XDG_DATA_DIRS : ${base}/share"
199 "--prefix XDG_DATA_DIRS : ${hicolor-icon-theme}/share"
200 "--prefix XDG_DATA_DIRS : ${adwaita-icon-theme}/share"
201 "--prefix XDG_DATA_DIRS : ${gtk3}/share/gsettings-schemas/${gtk3.name}"
202 "--prefix XDG_DATA_DIRS : ${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
203 # wrapGAppsHook3 did these two as well, no idea if it matters...
204 "--prefix XDG_DATA_DIRS : ${cups}/share"
205 "--prefix GIO_EXTRA_MODULES : ${dconf}/lib/gio/modules"
206 # required to open a bug report link in firefox-wayland
207 "--set-default MOZ_DBUS_REMOTE 1"
208 "--set-default KICAD8_FOOTPRINT_DIR ${footprints}/share/kicad/footprints"
209 "--set-default KICAD8_SYMBOL_DIR ${symbols}/share/kicad/symbols"
210 "--set-default KICAD8_TEMPLATE_DIR ${template_dir}"
212 ++ optionals (addons != [ ]) (
213 let stockDataPath = symlinkJoin {
214 name = "kicad_stock_data_path";
216 "${base}/share/kicad"
217 "${addonsJoined}/share/kicad"
221 [ "--set-default NIX_KICAD8_STOCK_DATA_PATH ${stockDataPath}" ]
223 ++ optionals (with3d)
225 "--set-default KICAD8_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels"
227 ++ optionals (withNgspice) [ "--prefix LD_LIBRARY_PATH : ${libngspice}/lib" ]
229 # infinisil's workaround for #39493
230 ++ [ "--set GDK_PIXBUF_MODULE_FILE ${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ]
233 # why does $makeWrapperArgs have to be added explicitly?
234 # $out and $program_PYTHONPATH don't exist when makeWrapperArgs gets set?
237 bin = if stdenv.hostPlatform.isDarwin then "*.app/Contents/MacOS" else "bin";
238 tools = [ "kicad" "pcbnew" "eeschema" "gerbview" "pcb_calculator" "pl_editor" "bitmap2component" ];
239 utils = [ "dxf2idf" "idf2vrml" "idfcyl" "idfrect" "kicad-cli" ];
241 (concatStringsSep "\n"
245 (optionalString (withScripting) "buildPythonPath \"${base} $pythonPath\" \n")
247 # wrap each of the directly usable tools
249 (tool: "makeWrapper ${base}/${bin}/${tool} $out/bin/${tool} $makeWrapperArgs"
250 + optionalString (withScripting) " --set PYTHONPATH \"$program_PYTHONPATH\""
254 # link in the CLI utils
255 (map (util: "ln -s ${base}/${bin}/${util} $out/bin/${util}") utils)
257 "runHook postInstall"
264 ln -s ${base}/share/applications $out/share/applications
265 ln -s ${base}/share/icons $out/share/icons
266 ln -s ${base}/share/mime $out/share/mime
267 ln -s ${base}/share/metainfo $out/share/metainfo
270 passthru.updateScript = {
271 command = [ ./update.sh "${pname}" ];
272 supportedFeatures = [ "commit" ];
276 description = (if (stable)
277 then "Open Source Electronics Design Automation suite"
278 else if (testing) then "Open Source EDA suite, latest on stable branch"
279 else "Open Source EDA suite, latest on master branch")
280 + (lib.optionalString (!with3d) ", without 3D models");
281 homepage = "https://www.kicad.org/";
283 KiCad is an open source software suite for Electronic Design Automation.
284 The Programs handle Schematic Capture, and PCB Layout with Gerber output.
286 license = lib.licenses.gpl3Plus;
287 maintainers = with lib.maintainers; [ evils ];
288 platforms = lib.platforms.all;
289 broken = stdenv.hostPlatform.isDarwin;
290 mainProgram = "kicad";