Commit d0bec347 authored by Jeremy Fleischman's avatar Jeremy Fleischman Committed by Shahar "Dawn" Or
Browse files

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: default avatarRohit <rohitsutradhar311@gmail.com>
Co-authored-by: default avatarJeremy Fleischman <jeremyfleischman@gmail.com>
Co-authored-by: default avatarShahar "Dawn" Or <mightyiampresence@gmail.com>
Co-authored-by: default avatarAlejandro Sanchez Medina <alejandrosanchzmedina@gmail.com>
Co-authored-by: default avatarMatúš Ferech <matus.ferech@gmail.com>
parent 0650d380
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
{ kicad }:
{
  kikit = kicad.callPackage ./kikit.nix { addonName = "kikit"; };
  kikit-library = kicad.callPackage ./kikit.nix { addonName = "kikit-library"; };
}
+52 −0
Original line number Diff line number Diff line
# 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;
  };
}
+2 −0
Original line number Diff line number Diff line
@@ -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"
+52 −1
Original line number Diff line number Diff line
{ 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"
+15 −0
Original line number Diff line number Diff line
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
Loading