2021-01-17 00:15:33 +00:00
|
|
|
{ lib, stdenv
|
2020-10-16 20:44:37 +00:00
|
|
|
, fetchFromGitLab
|
2021-05-20 23:08:51 +00:00
|
|
|
, gnome
|
2021-03-19 17:17:44 +00:00
|
|
|
, dconf
|
2022-11-04 12:27:35 +00:00
|
|
|
, wxGTK32
|
2022-10-30 15:09:59 +00:00
|
|
|
, gtk3
|
2020-08-20 17:08:02 +00:00
|
|
|
, makeWrapper
|
2020-10-16 20:44:37 +00:00
|
|
|
, gsettings-desktop-schemas
|
|
|
|
, hicolor-icon-theme
|
|
|
|
, callPackage
|
|
|
|
, callPackages
|
|
|
|
, librsvg
|
|
|
|
, cups
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
, pname ? "kicad"
|
2020-05-15 21:57:56 +00:00
|
|
|
, stable ? true
|
2023-02-02 18:25:31 +00:00
|
|
|
, withNgspice ? !stdenv.isDarwin
|
2020-10-16 20:44:37 +00:00
|
|
|
, libngspice
|
|
|
|
, withScripting ? true
|
|
|
|
, python3
|
|
|
|
, debug ? false
|
2021-05-20 23:08:51 +00:00
|
|
|
, sanitizeAddress ? false
|
|
|
|
, sanitizeThreads ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
, with3d ? true
|
2022-01-19 23:45:15 +00:00
|
|
|
, withI18n ? true
|
2020-10-16 20:44:37 +00:00
|
|
|
, srcs ? { }
|
2023-05-24 13:37:59 +00:00
|
|
|
, symlinkJoin
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
# The `srcs` parameter can be used to override the kicad source code
|
2021-12-30 13:39:12 +00:00
|
|
|
# and all libraries, which are otherwise inaccessible
|
2020-10-16 20:44:37 +00:00
|
|
|
# to overlays since most of the kicad build expression has been
|
|
|
|
# refactored into base.nix, most of the library build expressions have
|
2021-12-30 13:39:12 +00:00
|
|
|
# been refactored into libraries.nix. Overrides are only applied when
|
|
|
|
# building `kicad-unstable`. The `srcs` parameter has
|
|
|
|
# no effect for stable `kicad`. `srcs` takes an attribute set in which
|
2020-10-16 20:44:37 +00:00
|
|
|
# any of the following attributes are meaningful (though none are
|
2021-12-30 13:39:12 +00:00
|
|
|
# mandatory): "kicad", "kicadVersion", "symbols", "templates",
|
2020-10-16 20:44:37 +00:00
|
|
|
# "footprints", "packages3d", and "libVersion". "kicadVersion" and
|
|
|
|
# "libVersion" should be set to a string with the desired value for
|
|
|
|
# the version attribute in kicad's `mkDerivation` and the version
|
2021-12-30 13:39:12 +00:00
|
|
|
# attribute in any of the library's `mkDerivation`, respectively.
|
|
|
|
# "kicad", "symbols", "templates", "footprints", and "packages3d"
|
|
|
|
# should be set to an appropriate fetcher (e.g. `fetchFromGitLab`).
|
|
|
|
# So, for example, a possible overlay for kicad is:
|
2020-10-16 20:44:37 +00:00
|
|
|
#
|
|
|
|
# final: prev:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
# {
|
|
|
|
# kicad-unstable = (prev.kicad-unstable.override {
|
|
|
|
# srcs = {
|
|
|
|
# kicadVersion = "2020-10-08";
|
|
|
|
# kicad = prev.fetchFromGitLab {
|
|
|
|
# group = "kicad";
|
|
|
|
# owner = "code";
|
|
|
|
# repo = "kicad";
|
|
|
|
# rev = "fd22fe8e374ce71d57e9f683ba996651aa69fa4e";
|
|
|
|
# sha256 = "sha256-F8qugru/jU3DgZSpQXQhRGNFSk0ybFRkpyWb7HAGBdc=";
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
# });
|
|
|
|
# }
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
let
|
2020-04-24 23:36:52 +00:00
|
|
|
baseName = if (stable) then "kicad" else "kicad-unstable";
|
2020-10-16 20:44:37 +00:00
|
|
|
versionsImport = import ./versions.nix;
|
|
|
|
|
|
|
|
# versions.nix does not provide us with version, src and rev. We
|
|
|
|
# need to turn this into approprate fetcher calls.
|
|
|
|
kicadSrcFetch = fetchFromGitLab {
|
|
|
|
group = "kicad";
|
|
|
|
owner = "code";
|
|
|
|
repo = "kicad";
|
|
|
|
rev = versionsImport.${baseName}.kicadVersion.src.rev;
|
|
|
|
sha256 = versionsImport.${baseName}.kicadVersion.src.sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
libSrcFetch = name: fetchFromGitLab {
|
|
|
|
group = "kicad";
|
|
|
|
owner = "libraries";
|
|
|
|
repo = "kicad-${name}";
|
|
|
|
rev = versionsImport.${baseName}.libVersion.libSources.${name}.rev;
|
|
|
|
sha256 = versionsImport.${baseName}.libVersion.libSources.${name}.sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# only override `src` or `version` if building `kicad-unstable` with
|
|
|
|
# the appropriate attribute defined in `srcs`.
|
|
|
|
srcOverridep = attr: (!stable && builtins.hasAttr attr srcs);
|
|
|
|
|
|
|
|
# use default source and version (as defined in versions.nix) by
|
|
|
|
# default, or use the appropriate attribute from `srcs` if building
|
|
|
|
# unstable with `srcs` properly defined.
|
|
|
|
kicadSrc =
|
|
|
|
if srcOverridep "kicad" then srcs.kicad
|
|
|
|
else kicadSrcFetch;
|
|
|
|
kicadVersion =
|
|
|
|
if srcOverridep "kicadVersion" then srcs.kicadVersion
|
|
|
|
else versionsImport.${baseName}.kicadVersion.version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
libSrc = name: if srcOverridep name then srcs.${name} else libSrcFetch name;
|
|
|
|
# TODO does it make sense to only have one version for all libs?
|
|
|
|
libVersion =
|
|
|
|
if srcOverridep "libVersion" then srcs.libVersion
|
|
|
|
else versionsImport.${baseName}.libVersion.version;
|
|
|
|
|
2022-11-04 12:27:35 +00:00
|
|
|
wxGTK = wxGTK32;
|
2020-04-24 23:36:52 +00:00
|
|
|
python = python3;
|
2022-11-04 12:27:35 +00:00
|
|
|
wxPython = python.pkgs.wxPython_4_2;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-17 00:15:33 +00:00
|
|
|
inherit (lib) concatStringsSep flatten optionalString optionals;
|
2020-05-15 21:57:56 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
# Common libraries, referenced during runtime, via the wrapper.
|
2021-05-20 23:08:51 +00:00
|
|
|
passthru.libraries = callPackages ./libraries.nix { inherit libSrc; };
|
2020-04-24 23:36:52 +00:00
|
|
|
base = callPackage ./base.nix {
|
2020-10-16 20:44:37 +00:00
|
|
|
inherit stable baseName;
|
|
|
|
inherit kicadSrc kicadVersion;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit wxGTK python wxPython;
|
2023-04-12 12:48:02 +00:00
|
|
|
inherit withNgspice withScripting withI18n;
|
2021-05-20 23:08:51 +00:00
|
|
|
inherit debug sanitizeAddress sanitizeThreads;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inherit pname;
|
2021-05-20 23:08:51 +00:00
|
|
|
version = if (stable) then kicadVersion else builtins.substring 0 10 src.src.rev;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = base;
|
|
|
|
dontUnpack = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
dontBuild = true;
|
|
|
|
dontFixup = true;
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
pythonPath = optionals (withScripting)
|
2023-04-12 12:48:02 +00:00
|
|
|
[ wxPython python.pkgs.six python.pkgs.requests ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
2020-10-16 20:44:37 +00:00
|
|
|
++ optionals (withScripting)
|
|
|
|
[ python.pkgs.wrapPython ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
# KICAD7_TEMPLATE_DIR only works with a single path (it does not handle : separated paths)
|
|
|
|
# but it's used to find both the templates and the symbol/footprint library tables
|
|
|
|
# https://gitlab.com/kicad/code/kicad/-/issues/14792
|
|
|
|
template_dir = symlinkJoin {
|
|
|
|
name = "KiCad_template_dir";
|
|
|
|
paths = with passthru.libraries; [
|
|
|
|
"${templates}/share/kicad/template"
|
|
|
|
"${footprints}/share/kicad/template"
|
|
|
|
"${symbols}/share/kicad/template"
|
|
|
|
];
|
|
|
|
};
|
2022-12-28 21:21:41 +00:00
|
|
|
# We are emulating wrapGAppsHook, along with other variables to the wrapper
|
2020-05-15 21:57:56 +00:00
|
|
|
makeWrapperArgs = with passthru.libraries; [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--prefix XDG_DATA_DIRS : ${base}/share"
|
|
|
|
"--prefix XDG_DATA_DIRS : ${hicolor-icon-theme}/share"
|
2021-05-20 23:08:51 +00:00
|
|
|
"--prefix XDG_DATA_DIRS : ${gnome.adwaita-icon-theme}/share"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--prefix XDG_DATA_DIRS : ${gtk3}/share/gsettings-schemas/${gtk3.name}"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--prefix XDG_DATA_DIRS : ${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
|
|
|
|
# wrapGAppsHook did these two as well, no idea if it matters...
|
|
|
|
"--prefix XDG_DATA_DIRS : ${cups}/share"
|
2021-03-19 17:17:44 +00:00
|
|
|
"--prefix GIO_EXTRA_MODULES : ${dconf}/lib/gio/modules"
|
2021-05-20 23:08:51 +00:00
|
|
|
# required to open a bug report link in firefox-wayland
|
|
|
|
"--set-default MOZ_DBUS_REMOTE 1"
|
2023-02-16 17:41:37 +00:00
|
|
|
"--set-default KICAD7_FOOTPRINT_DIR ${footprints}/share/kicad/footprints"
|
|
|
|
"--set-default KICAD7_SYMBOL_DIR ${symbols}/share/kicad/symbols"
|
2023-05-24 13:37:59 +00:00
|
|
|
"--set-default KICAD7_TEMPLATE_DIR ${template_dir}"
|
2021-05-20 23:08:51 +00:00
|
|
|
]
|
2021-12-30 13:39:12 +00:00
|
|
|
++ optionals (with3d)
|
2021-05-20 23:08:51 +00:00
|
|
|
[
|
2023-02-16 17:41:37 +00:00
|
|
|
"--set-default KICAD7_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels"
|
2021-05-20 23:08:51 +00:00
|
|
|
]
|
2020-10-16 20:44:37 +00:00
|
|
|
++ optionals (withNgspice) [ "--prefix LD_LIBRARY_PATH : ${libngspice}/lib" ]
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# infinisil's workaround for #39493
|
|
|
|
++ [ "--set GDK_PIXBUF_MODULE_FILE ${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ]
|
|
|
|
;
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
# why does $makeWrapperArgs have to be added explicitly?
|
2020-04-24 23:36:52 +00:00
|
|
|
# $out and $program_PYTHONPATH don't exist when makeWrapperArgs gets set?
|
2020-10-16 20:44:37 +00:00
|
|
|
installPhase =
|
2020-05-15 21:57:56 +00:00
|
|
|
let
|
2023-02-02 18:25:31 +00:00
|
|
|
bin = if stdenv.isDarwin then "*.app/Contents/MacOS" else "bin";
|
2020-05-15 21:57:56 +00:00
|
|
|
tools = [ "kicad" "pcbnew" "eeschema" "gerbview" "pcb_calculator" "pl_editor" "bitmap2component" ];
|
2023-02-16 17:41:37 +00:00
|
|
|
utils = [ "dxf2idf" "idf2vrml" "idfcyl" "idfrect" "kicad-cli" ];
|
2020-05-15 21:57:56 +00:00
|
|
|
in
|
2020-10-16 20:44:37 +00:00
|
|
|
(concatStringsSep "\n"
|
|
|
|
(flatten [
|
2021-04-22 02:08:21 +00:00
|
|
|
"runHook preInstall"
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
(optionalString (withScripting) "buildPythonPath \"${base} $pythonPath\" \n")
|
2020-05-15 21:57:56 +00:00
|
|
|
|
|
|
|
# wrap each of the directly usable tools
|
2020-10-16 20:44:37 +00:00
|
|
|
(map
|
2023-02-02 18:25:31 +00:00
|
|
|
(tool: "makeWrapper ${base}/${bin}/${tool} $out/bin/${tool} $makeWrapperArgs"
|
2020-10-16 20:44:37 +00:00
|
|
|
+ optionalString (withScripting) " --set PYTHONPATH \"$program_PYTHONPATH\""
|
|
|
|
)
|
|
|
|
tools)
|
2020-05-15 21:57:56 +00:00
|
|
|
|
|
|
|
# link in the CLI utils
|
2023-02-02 18:25:31 +00:00
|
|
|
(map (util: "ln -s ${base}/${bin}/${util} $out/bin/${util}") utils)
|
2021-04-22 02:08:21 +00:00
|
|
|
|
|
|
|
"runHook postInstall"
|
2020-05-15 21:57:56 +00:00
|
|
|
])
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
;
|
|
|
|
|
2021-04-22 02:08:21 +00:00
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/share
|
|
|
|
ln -s ${base}/share/applications $out/share/applications
|
|
|
|
ln -s ${base}/share/icons $out/share/icons
|
|
|
|
ln -s ${base}/share/mime $out/share/mime
|
2021-05-20 23:08:51 +00:00
|
|
|
ln -s ${base}/share/metainfo $out/share/metainfo
|
2021-04-22 02:08:21 +00:00
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# can't run this for each pname
|
|
|
|
# stable and unstable are in the same versions.nix
|
|
|
|
# and kicad-small reuses stable
|
|
|
|
# with "all" it updates both, run it manually if you don't want that
|
|
|
|
# and can't git commit if this could be running in parallel with other scripts
|
|
|
|
passthru.updateScript = [ ./update.sh "all" ];
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
meta = rec {
|
|
|
|
description = (if (stable)
|
2020-10-16 20:44:37 +00:00
|
|
|
then "Open Source Electronics Design Automation suite"
|
|
|
|
else "Open Source EDA suite, development build")
|
2023-02-16 17:41:37 +00:00
|
|
|
+ (lib.optionalString (!with3d) ", without 3D models");
|
2021-10-17 09:34:42 +00:00
|
|
|
homepage = "https://www.kicad.org/";
|
2020-04-24 23:36:52 +00:00
|
|
|
longDescription = ''
|
|
|
|
KiCad is an open source software suite for Electronic Design Automation.
|
|
|
|
The Programs handle Schematic Capture, and PCB Layout with Gerber output.
|
|
|
|
'';
|
2021-04-22 02:08:21 +00:00
|
|
|
license = lib.licenses.gpl3Plus;
|
2023-10-09 19:29:22 +00:00
|
|
|
maintainers = with lib.maintainers; [ evils ];
|
2021-01-17 00:15:33 +00:00
|
|
|
platforms = lib.platforms.all;
|
2023-02-02 18:25:31 +00:00
|
|
|
broken = stdenv.isDarwin;
|
2022-12-28 21:21:41 +00:00
|
|
|
mainProgram = "kicad";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|