From 7d6cf9c926726ae770b2054f6e6e7b30373dcd46 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 25 May 2026 10:55:03 +0200 Subject: [PATCH] kicad: Fix rebuild when `compressStep = false` It does no longer rebuild as expected: > nix-instantiate --eval -E 'with import ./. {}; kicad.base.drvPath' "/nix/store/8b0wimhxyr3vlbxsr8xybnzaz06161k5-kicad-base-10.0.3.drv" > nix-instantiate --eval -E 'with import ./. {}; (kicad.override { compressStep = false; }).base.drvPath' "/nix/store/8b0wimhxyr3vlbxsr8xybnzaz06161k5-kicad-base-10.0.3.drv" --- pkgs/by-name/ki/kicad/base.nix | 9 ---- pkgs/by-name/ki/kicad/package.nix | 44 +++++++++++++------ .../ki/kicad/runtime_stock_data_path.patch | 12 ++++- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/pkgs/by-name/ki/kicad/base.nix b/pkgs/by-name/ki/kicad/base.nix index c43b90c1face..55976ff0e8c9 100644 --- a/pkgs/by-name/ki/kicad/base.nix +++ b/pkgs/by-name/ki/kicad/base.nix @@ -62,7 +62,6 @@ debug, sanitizeAddress, sanitizeThreads, - templateDir ? null, }: assert lib.assertMsg ( @@ -208,14 +207,6 @@ stdenv.mkDerivation (finalAttrs: { dontStrip = debug; - # KiCad looks for the stock library tables at - # KICAD_LIBRARY_DATA/template/{sym,fp}-lib-table, where KICAD_LIBRARY_DATA is - # compiled in as $out/share/kicad. Those files live in separate library packages. - postInstall = optionalString (templateDir != null) '' - rm -rf $out/share/kicad/template - ln -s ${templateDir} $out/share/kicad/template - ''; - meta = { description = "Just the built source without the libraries"; longDescription = '' diff --git a/pkgs/by-name/ki/kicad/package.nix b/pkgs/by-name/ki/kicad/package.nix index 9fc7856da47f..e9fe9c2ea104 100644 --- a/pkgs/by-name/ki/kicad/package.nix +++ b/pkgs/by-name/ki/kicad/package.nix @@ -186,7 +186,6 @@ stdenv.mkDerivation rec { inherit wxGTK python wxPython; inherit withNgspice withScripting withI18n; inherit debug sanitizeAddress sanitizeThreads; - templateDir = template_dir; }; inherit pname; @@ -221,6 +220,36 @@ stdenv.mkDerivation rec { "${symbols}/share/kicad/template" ]; }; + + # KiCad looks up its stock library tables relative to GetStockDataPath(), + # which our runtime_stock_data_path.patch lets us override via + # NIX_KICAD10_STOCK_DATA_PATH. We synthesise a directory that mirrors + # ${base}/share/kicad but replaces the upstream-installed (incomplete) + # template/ with the merged template_dir from the library packages. + # Doing this in the wrapper instead of in base.nix keeps the heavy + # kicad-base compile independent of the (cheap) library packages, so + # toggling overrides like compressStep doesn't force a base rebuild. + baseWithTemplate = runCommand "kicad-stock-data" { } '' + mkdir -p $out + for d in ${base}/share/kicad/*; do + name=$(basename "$d") + [ "$name" = template ] || ln -s "$d" "$out/$name" + done + ln -s ${template_dir} $out/template + ''; + + stockDataPath = + if addons == [ ] then + baseWithTemplate + else + symlinkJoin { + name = "kicad_stock_data_path"; + paths = [ + baseWithTemplate + "${addonsJoined}/share/kicad" + ]; + }; + # We are emulating wrapGAppsHook3, along with other variables to the wrapper makeWrapperArgs = with passthru.libraries; @@ -238,19 +267,8 @@ stdenv.mkDerivation rec { "--set-default KICAD10_FOOTPRINT_DIR ${footprints}/share/kicad/footprints" "--set-default KICAD10_SYMBOL_DIR ${symbols}/share/kicad/symbols" "--set-default KICAD10_TEMPLATE_DIR ${template_dir}" + "--set-default NIX_KICAD10_STOCK_DATA_PATH ${stockDataPath}" ] - ++ optionals (addons != [ ]) ( - let - stockDataPath = symlinkJoin { - name = "kicad_stock_data_path"; - paths = [ - "${base}/share/kicad" - "${addonsJoined}/share/kicad" - ]; - }; - in - [ "--set-default NIX_KICAD10_STOCK_DATA_PATH ${stockDataPath}" ] - ) ++ optionals with3d [ "--set-default KICAD10_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels" ] diff --git a/pkgs/by-name/ki/kicad/runtime_stock_data_path.patch b/pkgs/by-name/ki/kicad/runtime_stock_data_path.patch index 1b6eaead8c28..0ef3544d3fcf 100644 --- a/pkgs/by-name/ki/kicad/runtime_stock_data_path.patch +++ b/pkgs/by-name/ki/kicad/runtime_stock_data_path.patch @@ -1,5 +1,4 @@ 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 ) @@ -13,3 +12,14 @@ index a74cdd9..790cc58 100644 if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) { // Allow debugging from build dir by placing relevant files/folders in the build root +@@ -198,6 +202,10 @@ wxString PATHS::GetStockEDALibraryPath() + { + wxString path; + ++ if( wxGetEnv( wxT( "NIX_KICAD10_STOCK_DATA_PATH" ), &path ) ) { ++ return path; ++ } ++ + #if defined( __WXMAC__ ) + path = GetOSXKicadMachineDataDir(); + #elif defined( __WXMSW__ )