summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
authorJeremy Fleischman <jeremyfleischman@gmail.com>2023-10-04 14:02:27 +0700
committerShahar "Dawn" Or <mightyiampresence@gmail.com>2023-11-16 21:24:05 +0700
commitd0bec347c4b29d84ddd901f31b7e4247a4c7a395 (patch)
treee6b100e8d783bc7af8b1c00a9686c7d2d6ae4c2d /pkgs/applications/science
parent0650d380c765a8cc438051b7b1cf038d0901f7f7 (diff)
downloadnixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar.gz
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar.bz2
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar.lz
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar.xz
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.tar.zst
nixpkgs-d0bec347c4b29d84ddd901f31b7e4247a4c7a395.zip
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>
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/electronics/kicad/addons/default.nix5
-rw-r--r--pkgs/applications/science/electronics/kicad/addons/kikit.nix52
-rw-r--r--pkgs/applications/science/electronics/kicad/base.nix2
-rw-r--r--pkgs/applications/science/electronics/kicad/default.nix53
-rw-r--r--pkgs/applications/science/electronics/kicad/runtime_stock_data_path.patch15
5 files changed, 126 insertions, 1 deletions
diff --git a/pkgs/applications/science/electronics/kicad/addons/default.nix b/pkgs/applications/science/electronics/kicad/addons/default.nix
new file mode 100644
index 00000000000..5170e7efce3
--- /dev/null
+++ b/pkgs/applications/science/electronics/kicad/addons/default.nix
@@ -0,0 +1,5 @@
+{ kicad }:
+{
+  kikit = kicad.callPackage ./kikit.nix { addonName = "kikit"; };
+  kikit-library = kicad.callPackage ./kikit.nix { addonName = "kikit-library"; };
+}
diff --git a/pkgs/applications/science/electronics/kicad/addons/kikit.nix b/pkgs/applications/science/electronics/kicad/addons/kikit.nix
new file mode 100644
index 00000000000..6e5fc5ad967
--- /dev/null
+++ b/pkgs/applications/science/electronics/kicad/addons/kikit.nix
@@ -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;
+  };
+}
diff --git a/pkgs/applications/science/electronics/kicad/base.nix b/pkgs/applications/science/electronics/kicad/base.nix
index 3403e410cf8..a2e5bbe72a5 100644
--- a/pkgs/applications/science/electronics/kicad/base.nix
+++ b/pkgs/applications/science/electronics/kicad/base.nix
@@ -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"
diff --git a/pkgs/applications/science/electronics/kicad/default.nix b/pkgs/applications/science/electronics/kicad/default.nix
index a49c813036d..c6c66839e4b 100644
--- a/pkgs/applications/science/electronics/kicad/default.nix
+++ b/pkgs/applications/science/electronics/kicad/default.nix
@@ -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"
diff --git a/pkgs/applications/science/electronics/kicad/runtime_stock_data_path.patch b/pkgs/applications/science/electronics/kicad/runtime_stock_data_path.patch
new file mode 100644
index 00000000000..16f7e493c62
--- /dev/null
+++ b/pkgs/applications/science/electronics/kicad/runtime_stock_data_path.patch
@@ -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