Merge pull request #100066 from matthuszagh/kicad-srcs

This commit is contained in:
Doron Behar 2020-10-12 22:55:16 +03:00 committed by GitHub
commit 58b8ae4127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 231 additions and 131 deletions

View File

@ -71,6 +71,17 @@
for consistency with other X11 resources. for consistency with other X11 resources.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
A number of options have been renamed in the kicad interface. <literal>oceSupport</literal>
has been renamed to <literal>withOCE</literal>, <literal>withOCCT</literal> has been renamed
to <literal>withOCC</literal>, <literal>ngspiceSupport</literal> has been renamed to
<literal>withNgspice</literal>, and <literal>scriptingSupport</literal> has been renamed to
<literal>withScripting</literal>. Additionally, <literal>kicad/base.nix</literal> no longer
provides default argument values since these are provided by
<literal>kicad/default.nix</literal>.
</para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>

View File

@ -1,5 +1,4 @@
{ lib { stdenv
, stdenv
, fetchFromGitLab , fetchFromGitLab
, cmake , cmake
, libGLU , libGLU
@ -21,54 +20,40 @@
, libXdmcp , libXdmcp
, fetchpatch , fetchpatch
, lndir , lndir
, callPackages , callPackage
, stable ? true , stable
, baseName ? "kicad" , baseName
, versions ? { } , kicadSrc
, oceSupport ? false , kicadVersion
, i18n
, withOCE
, opencascade , opencascade
, withOCCT ? true , withOCC
, opencascade-occt , opencascade-occt
, ngspiceSupport ? true , withNgspice
, libngspice , libngspice
, scriptingSupport ? true , withScripting
, swig , swig
, python , python
, wxPython , wxPython
, debug ? false , debug
, valgrind , valgrind
, withI18n ? true , withI18n
, gtk3 , gtk3
}: }:
assert ngspiceSupport -> libngspice != null; assert stdenv.lib.asserts.assertMsg (!(withOCE && stdenv.isAarch64)) "OCE fails a test on Aarch64";
assert stdenv.lib.asserts.assertMsg (!(withOCC && withOCE))
with lib; "Only one of OCC and OCE may be enabled";
let let
versionConfig = versions.${baseName}; inherit (stdenv.lib) optional optionals;
# oce on aarch64 fails a test
withOCE = oceSupport && !stdenv.isAarch64;
withOCC = (withOCCT && !withOCE) || (oceSupport && stdenv.isAarch64);
libraries = callPackages ./libraries.nix versionConfig.libVersion;
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
i18n = libraries.i18n;
pname = "kicad-base"; pname = "kicad-base";
version = "${builtins.substring 0 10 versions.${baseName}.kicadVersion.src.rev}"; version = kicadVersion;
src = fetchFromGitLab ( src = kicadSrc;
{
group = "kicad";
owner = "code";
repo = "kicad";
} // versionConfig.kicadVersion.src
);
# quick fix for #72248 # quick fix for #72248
# should be removed if a a more permanent fix is published # should be removed if a a more permanent fix is published
@ -94,15 +79,15 @@ stdenv.mkDerivation rec {
makeFlags = optional (debug) [ "CFLAGS+=-Og" "CFLAGS+=-ggdb" ]; makeFlags = optional (debug) [ "CFLAGS+=-Og" "CFLAGS+=-ggdb" ];
cmakeFlags = cmakeFlags =
optionals (scriptingSupport) [ optionals (withScripting) [
"-DKICAD_SCRIPTING=ON" "-DKICAD_SCRIPTING=ON"
"-DKICAD_SCRIPTING_MODULES=ON" "-DKICAD_SCRIPTING_MODULES=ON"
"-DKICAD_SCRIPTING_PYTHON3=ON" "-DKICAD_SCRIPTING_PYTHON3=ON"
"-DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON" "-DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON"
] ]
++ optional (!scriptingSupport) ++ optional (!withScripting)
"-DKICAD_SCRIPTING=OFF" "-DKICAD_SCRIPTING=OFF"
++ optional (ngspiceSupport) "-DKICAD_SPICE=ON" ++ optional (withNgspice) "-DKICAD_SPICE=ON"
++ optional (!withOCE) "-DKICAD_USE_OCE=OFF" ++ optional (!withOCE) "-DKICAD_USE_OCE=OFF"
++ optional (!withOCC) "-DKICAD_USE_OCC=OFF" ++ optional (!withOCC) "-DKICAD_USE_OCC=OFF"
++ optionals (withOCE) [ ++ optionals (withOCE) [
@ -140,8 +125,8 @@ stdenv.mkDerivation rec {
boost boost
gtk3 gtk3
] ]
++ optionals (scriptingSupport) [ swig python wxPython ] ++ optionals (withScripting) [ swig python wxPython ]
++ optional (ngspiceSupport) libngspice ++ optional (withNgspice) libngspice
++ optional (withOCE) opencascade ++ optional (withOCE) opencascade
++ optional (withOCC) opencascade-occt ++ optional (withOCC) opencascade-occt
++ optional (debug) valgrind ++ optional (debug) valgrind
@ -166,7 +151,7 @@ stdenv.mkDerivation rec {
the libraries are passed via an env var in the wrapper, default.nix the libraries are passed via an env var in the wrapper, default.nix
''; '';
homepage = "https://www.kicad-pcb.org/"; homepage = "https://www.kicad-pcb.org/";
license = licenses.agpl3; license = stdenv.lib.licenses.agpl3;
platforms = platforms.all; platforms = stdenv.lib.platforms.all;
}; };
} }

View File

@ -1,52 +1,176 @@
{ lib, stdenv, gnome3, wxGTK30, wxGTK31 { stdenv
, fetchFromGitLab
, gnome3
, wxGTK30
, wxGTK31
, makeWrapper , makeWrapper
, gsettings-desktop-schemas, hicolor-icon-theme , gsettings-desktop-schemas
, callPackage, callPackages , hicolor-icon-theme
, librsvg, cups , callPackage
, callPackages
, librsvg
, cups
, pname ? "kicad" , pname ? "kicad"
, stable ? true , stable ? true
, oceSupport ? false, opencascade , oceSupport ? false
, withOCCT ? true, opencascade-occt , withOCE ? false
, ngspiceSupport ? true, libngspice , opencascade
, scriptingSupport ? true, swig, python3 , withOCCT ? false
, debug ? false, valgrind , withOCC ? true
, opencascade-occt
, ngspiceSupport ? false
, withNgspice ? true
, libngspice
, scriptingSupport ? false
, withScripting ? true
, swig
, python3
, debug ? false
, valgrind
, with3d ? true , with3d ? true
, withI18n ? true , withI18n ? true
, srcs ? { }
}: }:
assert ngspiceSupport -> libngspice != null; # The `srcs` parameter can be used to override the kicad source code
# and all libraries (including i18n), which are otherwise inaccessible
# to overlays since most of the kicad build expression has been
# refactored into base.nix, most of the library build expressions have
# been refactored into libraries.nix, and most the i18n build
# expression has been refactored into i18n.nix. Overrides are only
# applied when building `kicad-unstable`. The `srcs` parameter has no
# effect for stable `kicad`. `srcs` takes an attribute set in which
# any of the following attributes are meaningful (though none are
# mandatory): "kicad", "kicadVersion", "i18n", "symbols", "templates",
# "footprints", "packages3d", and "libVersion". "kicadVersion" and
# "libVersion" should be set to a string with the desired value for
# the version attribute in kicad's `mkDerivation` and the version
# attribute in any of the library's or i18n's `mkDerivation`,
# respectively. "kicad", "i18n", "symbols", "templates", "footprints",
# and "packages3d" should be set to an appropriate fetcher (e.g.,
# `fetchFromGitLab`). So, for example, a possible overlay for kicad
# is:
#
# final: prev:
with lib; # {
# kicad-unstable = (prev.kicad-unstable.override {
# srcs = {
# kicadVersion = "2020-10-08";
# kicad = prev.fetchFromGitLab {
# group = "kicad";
# owner = "code";
# repo = "kicad";
# rev = "fd22fe8e374ce71d57e9f683ba996651aa69fa4e";
# sha256 = "sha256-F8qugru/jU3DgZSpQXQhRGNFSk0ybFRkpyWb7HAGBdc=";
# };
# };
# });
# }
assert withNgspice -> libngspice != null;
assert stdenv.lib.assertMsg (!ngspiceSupport)
"`nspiceSupport` was renamed to `withNgspice` for the sake of consistency with other kicad nix arguments.";
assert stdenv.lib.assertMsg (!oceSupport)
"`oceSupport` was renamed to `withOCE` for the sake of consistency with other kicad nix arguments.";
assert stdenv.lib.assertMsg (!scriptingSupport)
"`scriptingSupport` was renamed to `withScripting` for the sake of consistency with other kicad nix arguments.";
assert stdenv.lib.assertMsg (!withOCCT)
"`withOCCT` was renamed to `withOCC` for the sake of consistency with upstream cmake options.";
let let
baseName = if (stable) then "kicad" else "kicad-unstable"; baseName = if (stable) then "kicad" else "kicad-unstable";
versionsImport = import ./versions.nix;
versions = import ./versions.nix; # versions.nix does not provide us with version, src and rev. We
versionConfig = versions.${baseName}; # need to turn this into approprate fetcher calls.
kicadSrcFetch = fetchFromGitLab {
group = "kicad";
owner = "code";
repo = "kicad";
rev = versionsImport.${baseName}.kicadVersion.src.rev;
sha256 = versionsImport.${baseName}.kicadVersion.src.sha256;
};
wxGTK = if (stable) i18nSrcFetch = fetchFromGitLab {
group = "kicad";
owner = "code";
repo = "kicad-i18n";
rev = versionsImport.${baseName}.libVersion.libSources.i18n.rev;
sha256 = versionsImport.${baseName}.libVersion.libSources.i18n.sha256;
};
libSrcFetch = name: fetchFromGitLab {
group = "kicad";
owner = "libraries";
repo = "kicad-${name}";
rev = versionsImport.${baseName}.libVersion.libSources.${name}.rev;
sha256 = versionsImport.${baseName}.libVersion.libSources.${name}.sha256;
};
# only override `src` or `version` if building `kicad-unstable` with
# the appropriate attribute defined in `srcs`.
srcOverridep = attr: (!stable && builtins.hasAttr attr srcs);
# use default source and version (as defined in versions.nix) by
# default, or use the appropriate attribute from `srcs` if building
# unstable with `srcs` properly defined.
kicadSrc =
if srcOverridep "kicad" then srcs.kicad
else kicadSrcFetch;
kicadVersion =
if srcOverridep "kicadVersion" then srcs.kicadVersion
else versionsImport.${baseName}.kicadVersion.version;
i18nSrc = if srcOverridep "i18n" then srcs.i18n else i18nSrcFetch;
i18nVersion =
if srcOverridep "i18nVersion" then srcs.i18nVersion
else versionsImport.${baseName}.libVersion.version;
libSrc = name: if srcOverridep name then srcs.${name} else libSrcFetch name;
# TODO does it make sense to only have one version for all libs?
libVersion =
if srcOverridep "libVersion" then srcs.libVersion
else versionsImport.${baseName}.libVersion.version;
wxGTK =
if (stable)
# wxGTK3x may default to withGtk2 = false, see #73145 # wxGTK3x may default to withGtk2 = false, see #73145
then wxGTK30.override { withGtk2 = false; } then
wxGTK30.override
{
withGtk2 = false;
}
# wxGTK31 currently introduces an issue with opening the python interpreter in pcbnew # wxGTK31 currently introduces an issue with opening the python interpreter in pcbnew
# but brings high DPI support? # but brings high DPI support?
else wxGTK31.override { withGtk2 = false; }; else
wxGTK31.override {
withGtk2 = false;
};
python = python3; python = python3;
wxPython = python.pkgs.wxPython_4_0; wxPython = python.pkgs.wxPython_4_0;
inherit (stdenv.lib) concatStringsSep flatten optionalString optionals;
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
passthru.libraries = callPackages ./libraries.nix versionConfig.libVersion; # Common libraries, referenced during runtime, via the wrapper.
passthru.libraries = callPackages ./libraries.nix { inherit libSrc libVersion; };
passthru.i18n = callPackage ./i18n.nix {
src = i18nSrc;
version = i18nVersion;
};
base = callPackage ./base.nix { base = callPackage ./base.nix {
inherit versions stable baseName; inherit stable baseName;
inherit kicadSrc kicadVersion;
inherit (passthru) i18n;
inherit wxGTK python wxPython; inherit wxGTK python wxPython;
inherit debug withI18n withOCCT oceSupport ngspiceSupport scriptingSupport; inherit debug withI18n withOCC withOCE withNgspice withScripting;
}; };
inherit pname; inherit pname;
version = versions.${baseName}.kicadVersion.version; version = kicadVersion;
src = base; src = base;
dontUnpack = true; dontUnpack = true;
@ -54,15 +178,15 @@ stdenv.mkDerivation rec {
dontBuild = true; dontBuild = true;
dontFixup = true; dontFixup = true;
pythonPath = optionals (scriptingSupport) pythonPath = optionals (withScripting)
[ wxPython python.pkgs.six ]; [ wxPython python.pkgs.six ];
nativeBuildInputs = [ makeWrapper ] nativeBuildInputs = [ makeWrapper ]
++ optionals (scriptingSupport) ++ optionals (withScripting)
[ python.pkgs.wrapPython ]; [ python.pkgs.wrapPython ];
# wrapGAppsHook added the equivalent to ${base}/share # We are emulating wrapGAppsHook, along with other variables to the
# though i noticed no difference without it # wrapper
makeWrapperArgs = with passthru.libraries; [ makeWrapperArgs = with passthru.libraries; [
"--prefix XDG_DATA_DIRS : ${base}/share" "--prefix XDG_DATA_DIRS : ${base}/share"
"--prefix XDG_DATA_DIRS : ${hicolor-icon-theme}/share" "--prefix XDG_DATA_DIRS : ${hicolor-icon-theme}/share"
@ -80,7 +204,7 @@ stdenv.mkDerivation rec {
"--prefix KICAD_TEMPLATE_DIR : ${footprints}/share/kicad/template" "--prefix KICAD_TEMPLATE_DIR : ${footprints}/share/kicad/template"
] ]
++ optionals (with3d) [ "--set KISYS3DMOD ${packages3d}/share/kicad/modules/packages3d" ] ++ optionals (with3d) [ "--set KISYS3DMOD ${packages3d}/share/kicad/modules/packages3d" ]
++ optionals (ngspiceSupport) [ "--prefix LD_LIBRARY_PATH : ${libngspice}/lib" ] ++ optionals (withNgspice) [ "--prefix LD_LIBRARY_PATH : ${libngspice}/lib" ]
# infinisil's workaround for #39493 # infinisil's workaround for #39493
++ [ "--set GDK_PIXBUF_MODULE_FILE ${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ] ++ [ "--set GDK_PIXBUF_MODULE_FILE ${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ]
@ -89,22 +213,24 @@ stdenv.mkDerivation rec {
# why does $makeWrapperArgs have to be added explicitly? # why does $makeWrapperArgs have to be added explicitly?
# $out and $program_PYTHONPATH don't exist when makeWrapperArgs gets set? # $out and $program_PYTHONPATH don't exist when makeWrapperArgs gets set?
# kicad-ogltest's source seems to indicate that crashing is expected behaviour... # kicad-ogltest's source seems to indicate that crashing is expected behaviour...
installPhase = with lib; installPhase =
let let
tools = [ "kicad" "pcbnew" "eeschema" "gerbview" "pcb_calculator" "pl_editor" "bitmap2component" ]; tools = [ "kicad" "pcbnew" "eeschema" "gerbview" "pcb_calculator" "pl_editor" "bitmap2component" ];
utils = [ "dxf2idf" "idf2vrml" "idfcyl" "idfrect" "kicad2step" "kicad-ogltest" ]; utils = [ "dxf2idf" "idf2vrml" "idfcyl" "idfrect" "kicad2step" "kicad-ogltest" ];
in in
( concatStringsSep "\n" (concatStringsSep "\n"
( flatten [ (flatten [
( optionalString (scriptingSupport) "buildPythonPath \"${base} $pythonPath\" \n" ) (optionalString (withScripting) "buildPythonPath \"${base} $pythonPath\" \n")
# wrap each of the directly usable tools # wrap each of the directly usable tools
( map ( tool: "makeWrapper ${base}/bin/${tool} $out/bin/${tool} $makeWrapperArgs" (map
+ optionalString (scriptingSupport) " --set PYTHONPATH \"$program_PYTHONPATH\"" (tool: "makeWrapper ${base}/bin/${tool} $out/bin/${tool} $makeWrapperArgs"
) tools ) + optionalString (withScripting) " --set PYTHONPATH \"$program_PYTHONPATH\""
)
tools)
# link in the CLI utils # link in the CLI utils
( map ( util: "ln -s ${base}/bin/${util} $out/bin/${util}" ) utils ) (map (util: "ln -s ${base}/bin/${util} $out/bin/${util}") utils)
]) ])
) )
; ;
@ -118,15 +244,15 @@ stdenv.mkDerivation rec {
meta = rec { meta = rec {
description = (if (stable) description = (if (stable)
then "Open Source Electronics Design Automation suite" then "Open Source Electronics Design Automation suite"
else "Open Source EDA suite, development build") else "Open Source EDA suite, development build")
+ (if (!with3d) then ", without 3D models" else ""); + (if (!with3d) then ", without 3D models" else "");
homepage = "https://www.kicad-pcb.org/"; homepage = "https://www.kicad-pcb.org/";
longDescription = '' longDescription = ''
KiCad is an open source software suite for Electronic Design Automation. KiCad is an open source software suite for Electronic Design Automation.
The Programs handle Schematic Capture, and PCB Layout with Gerber output. The Programs handle Schematic Capture, and PCB Layout with Gerber output.
''; '';
license = licenses.agpl3; license = stdenv.lib.licenses.agpl3;
# berce seems inactive... # berce seems inactive...
maintainers = with stdenv.lib.maintainers; [ evils kiwi berce ]; maintainers = with stdenv.lib.maintainers; [ evils kiwi berce ];
# kicad is cross platform # kicad is cross platform

View File

@ -0,0 +1,18 @@
{ stdenv
, cmake
, gettext
, src
, version
}:
stdenv.mkDerivation {
inherit src version;
pname = "kicad-i18n";
nativeBuildInputs = [ cmake gettext ];
meta = with stdenv.lib; {
license = licenses.gpl2; # https://github.com/KiCad/kicad-i18n/issues/3
platforms = platforms.all;
};
}

View File

@ -1,39 +1,25 @@
{ lib, stdenv, cmake, gettext { stdenv
, fetchFromGitHub, fetchFromGitLab , cmake
, version, libSources , gettext
, libSrc
, libVersion
}: }:
# callPackage libraries {
# version = "unstable";
# libs.symbols = {
# rev = "09f9..";
# sha256 = "...";
# };
# };
with lib;
let let
mkLib = name: mkLib = name:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "kicad-${name}"; pname = "kicad-${name}";
# Use the revision instead of `version` (which is an ISO 8601 date) version = libVersion;
# to prevent duplicating the library when just the date changed
version = "${builtins.substring 0 10 libSources.${name}.rev}"; src = libSrc name;
src = fetchFromGitHub (
{
owner = "KiCad";
repo = "kicad-${name}";
rev = version;
inherit name;
} // (libSources.${name} or { })
);
nativeBuildInputs = [ cmake ]; nativeBuildInputs = [ cmake ];
meta = rec { meta = rec {
license = licenses.cc-by-sa-40; license = stdenv.lib.licenses.cc-by-sa-40;
platforms = stdenv.lib.platforms.all; platforms = stdenv.lib.platforms.all;
# the 3d models are a ~1 GiB download and occupy ~5 GiB in store. # the 3d models are a ~1 GiB download and occupy ~5 GiB in store.
# this would exceed the hydra output limit # this would exceed the hydra output limit
hydraPlatforms = if (name == "packages3d" ) then [ ] else platforms; hydraPlatforms = if (name == "packages3d") then [ ] else platforms;
}; };
}; };
in in
@ -42,30 +28,4 @@ in
templates = mkLib "templates"; templates = mkLib "templates";
footprints = mkLib "footprints"; footprints = mkLib "footprints";
packages3d = mkLib "packages3d"; packages3d = mkLib "packages3d";
# i18n is a special case, not actually a library
# more a part of kicad proper, but also optional and separate
# since their move to gitlab they're keeping it in a separate path
# kicad has no way to find i18n except through a path relative to its install path
# therefore this is being linked into ${kicad-base}/share/
# and defined here to make use of the rev & sha256's brought here for the libs
i18n = let name = "i18n"; in
stdenv.mkDerivation {
pname = "kicad-${name}";
version = "${builtins.substring 0 10 libSources.${name}.rev}";
src = fetchFromGitLab (
{
group = "kicad";
owner = "code";
repo = "kicad-${name}";
rev = version;
inherit name;
} // (libSources.${name} or { })
);
nativeBuildInputs = [ cmake gettext ];
meta = {
license = licenses.gpl2; # https://github.com/KiCad/kicad-i18n/issues/3
platforms = stdenv.lib.platforms.all;
};
};
} }