diff options
Diffstat (limited to 'nixpkgs/pkgs/applications/science/electronics/kicad/default.nix')
-rw-r--r-- | nixpkgs/pkgs/applications/science/electronics/kicad/default.nix | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/nixpkgs/pkgs/applications/science/electronics/kicad/default.nix b/nixpkgs/pkgs/applications/science/electronics/kicad/default.nix index a49c813036d3..c6c66839e4bc 100644 --- a/nixpkgs/pkgs/applications/science/electronics/kicad/default.nix +++ b/nixpkgs/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" |