kicadAddons.kikit,kicadAddons.kikit-library: init at 1.3.0

Create a new kicadAddons package set, and a mechanism to override
kicad to bundle addons.

Co-authored-by: Rohit <rohitsutradhar311@gmail.com>
Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
Co-authored-by: Alejandro Sanchez Medina <alejandrosanchzmedina@gmail.com>
Co-authored-by: Matúš Ferech <matus.ferech@gmail.com>
This commit is contained in:
Jeremy Fleischman 2023-10-04 14:02:27 +07:00 committed by Shahar "Dawn" Or
parent 0650d380c7
commit d0bec347c4
6 changed files with 128 additions and 1 deletions

View File

@ -0,0 +1,5 @@
{ kicad }:
{
kikit = kicad.callPackage ./kikit.nix { addonName = "kikit"; };
kikit-library = kicad.callPackage ./kikit.nix { addonName = "kikit-library"; };
}

View File

@ -0,0 +1,52 @@
# For building the multiple addons that are in the kikit repo.
{ stdenv
, bc
, kikit
, zip
, python3
, addonName
, addonPath
}:
let
# This python is only used when building the package, it's not the python
# environment that will ultimately run the code packaged here. The python env defined
# in KiCad will import the python code packaged here when KiCad starts up.
python = python3.withPackages (ps: with ps; [ click ]);
kikit-module = python3.pkgs.toPythonModule (kikit.override { inherit python3; });
# The following different addons can be built from the same source.
targetSpecs = {
"kikit" = {
makeTarget = "pcm-kikit";
resultZip = "pcm-kikit.zip";
description = "KiCad plugin and a CLI tool to automate several tasks in a standard KiCad workflow";
};
"kikit-library" = {
makeTarget = "pcm-lib";
resultZip = "pcm-kikit-lib.zip";
description = "KiKit uses these symbols and footprints to annotate your boards (e.g., to place a tab in a panel).";
};
};
targetSpec = targetSpecs.${addonName};
in
stdenv.mkDerivation {
name = "kicadaddon-${addonName}";
inherit (kikit-module) src version;
nativeBuildInputs = [ python bc zip ];
propagatedBuildInputs = [ kikit-module ];
buildPhase = ''
patchShebangs scripts/setJson.py
make ${targetSpec.makeTarget}
'';
installPhase = ''
mkdir $out
mv build/${targetSpec.resultZip} $out/${addonPath}
'';
meta = kikit-module.meta // {
description = targetSpec.description;
};
}

View File

@ -69,6 +69,8 @@ stdenv.mkDerivation rec {
patches = [
# upstream issue 12941 (attempted to upstream, but appreciably unacceptable)
./writable.patch
# https://gitlab.com/kicad/code/kicad/-/issues/15687
./runtime_stock_data_path.patch
];
# tagged releases don't have "unknown"

View File

@ -1,4 +1,6 @@
{ lib, stdenv
, runCommand
, newScope
, fetchFromGitLab
, gnome
, dconf
@ -11,6 +13,8 @@
, callPackages
, librsvg
, cups
, unzip
, jq
, pname ? "kicad"
, stable ? true
@ -18,6 +22,7 @@
, libngspice
, withScripting ? true
, python3
, addons ? [ ]
, debug ? false
, sanitizeAddress ? false
, sanitizeThreads ? false
@ -27,6 +32,14 @@
, symlinkJoin
}:
# `addons`: https://dev-docs.kicad.org/en/addons/
#
# ```nix
# kicad = pkgs.kicad.override {
# addons = with pkgs.kicadAddons; [ kikit kikit-library ];
# };
# ```
# The `srcs` parameter can be used to override the kicad source code
# and all libraries, which are otherwise inaccessible
# to overlays since most of the kicad build expression has been
@ -106,6 +119,32 @@ let
wxGTK = wxGTK32;
python = python3;
wxPython = python.pkgs.wxPython_4_2;
addonPath = "addon.zip";
addonsDrvs = map (pkg: pkg.override { inherit addonPath python3; }) addons;
addonsJoined =
runCommand "addonsJoined"
{
inherit addonsDrvs;
nativeBuildInputs = [ unzip jq ];
} ''
mkdir $out
for pkg in $addonsDrvs; do
unzip $pkg/addon.zip -d unpacked
folder_name=$(jq .identifier unpacked/metadata.json --raw-output | tr . _)
for d in unpacked/*; do
if [ -d "$d" ]; then
dest=$out/share/kicad/scripting/$(basename $d)/$folder_name
mkdir -p $(dirname $dest)
mv $d $dest
fi
done
rm -r unpacked
done
'';
inherit (lib) concatStringsSep flatten optionalString optionals;
in
@ -113,6 +152,7 @@ stdenv.mkDerivation rec {
# Common libraries, referenced during runtime, via the wrapper.
passthru.libraries = callPackages ./libraries.nix { inherit libSrc; };
passthru.callPackage = newScope { inherit addonPath python3; };
base = callPackage ./base.nix {
inherit stable baseName;
inherit kicadSrc kicadVersion;
@ -131,7 +171,7 @@ stdenv.mkDerivation rec {
dontFixup = true;
pythonPath = optionals (withScripting)
[ wxPython python.pkgs.six python.pkgs.requests ];
[ wxPython python.pkgs.six python.pkgs.requests ] ++ addonsDrvs;
nativeBuildInputs = [ makeWrapper ]
++ optionals (withScripting)
@ -164,6 +204,17 @@ stdenv.mkDerivation rec {
"--set-default KICAD7_SYMBOL_DIR ${symbols}/share/kicad/symbols"
"--set-default KICAD7_TEMPLATE_DIR ${template_dir}"
]
++ optionals (addons != [ ]) (
let stockDataPath = symlinkJoin {
name = "kicad_stock_data_path";
paths = [
"${base}/share/kicad"
"${addonsJoined}/share/kicad"
];
};
in
[ "--set-default NIX_KICAD7_STOCK_DATA_PATH ${stockDataPath}" ]
)
++ optionals (with3d)
[
"--set-default KICAD7_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels"

View File

@ -0,0 +1,15 @@
diff --git a/common/paths.cpp b/common/paths.cpp
index a74cdd9..790cc58 100644
--- a/common/paths.cpp
+++ b/common/paths.cpp
@@ -151,6 +151,10 @@ wxString PATHS::GetStockDataPath( bool aRespectRunFromBuildDir )
{
wxString path;
+ if( wxGetEnv( wxT( "NIX_KICAD7_STOCK_DATA_PATH" ), &path ) ) {
+ return path;
+ }
+
if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
{
// Allow debugging from build dir by placing relevant files/folders in the build root

View File

@ -39768,6 +39768,8 @@ with pkgs;
with3d = false;
};
kicadAddons = recurseIntoAttrs (callPackage ../applications/science/electronics/kicad/addons {});
librepcb = libsForQt5.callPackage ../applications/science/electronics/librepcb { };
ngspice = libngspice.override {