diff --git a/pills/12-inputs-design-pattern.xml b/pills/12-inputs-design-pattern.xml index 5195ba3..97b9f08 100644 --- a/pills/12-inputs-design-pattern.xml +++ b/pills/12-inputs-design-pattern.xml @@ -56,7 +56,7 @@ We have packaged GNU hello world, imagine you would like to package something else for creating at least a repository of two projects :-) . I chose graphviz, which uses the standard autotools build system, requires no patching and dependencies are optional. - Download graphviz from here. The graphviz.nix expression is straightforward: + Download graphviz from here. The graphviz.nix expression is straightforward: @@ -70,33 +70,28 @@ Remember, in autotools.nix there's a buildInputs variable which gets concatenated to baseInputs. That would be the perfect place to add a build dependency. We created that variable exactly for this reason to be overridable from package expressions. - This 2.38 version of graphviz has several plugins to output png. For simplicity, we will use libgd. + This 2.49 version of graphviz has several plugins to output png. For simplicity, we will use libgd.
Digression about gcc and ld wrappers - The gd, jpeg, fontconfig and bzip2 libraries (dependencies of gd) don't use pkg-config to specify which flags to pass to the compiler. Since there's no global location for libraries, we need to tell gcc and ld where to find includes and libs. + The graphviz configure script uses pkg-config to specify which flags to pass to the compiler. Since there's no global location for libraries, we need to tell pkg-config where to find pkg-config description files, in order to enable it to tell the configure script where to find headers and libraries. - The nixpkgs provides gcc and binutils, which we are currently using for our packaging. It also provides wrappers for them which allow passing extra arguments to gcc and ld, bypassing the project build systems: - - NIX_CFLAGS_COMPILE: extra flags to gcc at compile time - NIX_LDFLAGS: extra flags to ld - + In classic POSIX systems, pkg-config just finds the + .pc files of all installed libraries in system folders + like /usr/lib/pkgconfig, but we don't have that in + the nix sandbox. The nix way to educate pkg-config + about the existence of libraries is the environment variable + PKG_CONFIG_PATH. What can we do about it? We can employ the same trick we did for PATH: automatically filling the variables from buildInputs. This is the relevant snippet of setup.sh: - Now adding derivations to buildInputs will add their lib, include and bin paths automatically in setup.sh. - - - The -rpath flag in ld is needed because at runtime, the executable must use exactly that version of the library. - - - If unneeded paths are specified, the fixup phase will shrink the rpath for us! + Now adding derivations to buildInputs will add their lib/pkgconfig and bin paths automatically in setup.sh.
@@ -106,8 +101,13 @@ - Now you can create the png! Ignore any error from fontconfig, especially if you are in a chroot. - + We add pkg-config to the derivation to make this tool + available for the configure script. As gd is a package + with split outputs, + we need to add both the library- and development outputs. + + + Now you can create the png!
@@ -218,7 +218,7 @@ - You can find the whole repository at the pill 12 gist. + You can find the whole repository at the pill 12 gist.
diff --git a/pills/12/graphviz-derivation.txt b/pills/12/graphviz-derivation.txt index 2509a28..8bd25f6 100644 --- a/pills/12/graphviz-derivation.txt +++ b/pills/12/graphviz-derivation.txt @@ -3,5 +3,5 @@ let mkDerivation = import ./autotools.nix pkgs; in mkDerivation { name = "graphviz"; - src = ./graphviz-2.38.0.tar.gz; + src = ./graphviz-2.49.3.tar.gz; } diff --git a/pills/12/graphviz-gd-derivation.txt b/pills/12/graphviz-gd-derivation.txt index 0907a59..f3f2f4d 100644 --- a/pills/12/graphviz-gd-derivation.txt +++ b/pills/12/graphviz-gd-derivation.txt @@ -3,6 +3,10 @@ let mkDerivation = import ./autotools.nix pkgs; in mkDerivation { name = "graphviz"; - src = ./graphviz-2.38.0.tar.gz; - buildInputs = with pkgs; [ gd fontconfig libjpeg bzip2 ]; + src = ./graphviz-2.49.3.tar.gz; + buildInputs = with pkgs; [ + pkg-config + (pkgs.lib.getLib gd) + (pkgs.lib.getDev gd) + ]; } diff --git a/pills/12/graphviz-mkderivation.txt b/pills/12/graphviz-mkderivation.txt index ab2962d..e60c7c0 100644 --- a/pills/12/graphviz-mkderivation.txt +++ b/pills/12/graphviz-mkderivation.txt @@ -1,7 +1,14 @@ -{ mkDerivation, gdSupport ? true, gd, fontconfig, libjpeg, bzip2 }: +{ mkDerivation, lib, gdSupport ? true, gd, pkg-config }: mkDerivation { name = "graphviz"; - src = ./graphviz-2.38.0.tar.gz; - buildInputs = if gdSupport then [ gd fontconfig libjpeg bzip2 ] else []; + src = ./graphviz-2.49.3.tar.gz; + buildInputs = + if gdSupport + then [ + pkg-config + (lib.getLib gd) + (lib.getDev gd) + ] + else []; } diff --git a/pills/12/repository-mkderivation.txt b/pills/12/repository-mkderivation.txt index 340697d..3bfe328 100644 --- a/pills/12/repository-mkderivation.txt +++ b/pills/12/repository-mkderivation.txt @@ -2,10 +2,10 @@ let pkgs = import {}; mkDerivation = import ./autotools.nix pkgs; in with pkgs; { - hello = import ./hello.nix { inherit mkDerivation; }; - graphviz = import ./graphviz.nix { inherit mkDerivation gd fontconfig libjpeg bzip2; }; + hello = import ./hello.nix { inherit mkDerivation; }; + graphviz = import ./graphviz.nix { inherit mkDerivation lib gd pkg-config; }; graphvizCore = import ./graphviz.nix { - inherit mkDerivation gd fontconfig libjpeg bzip2; + inherit mkDerivation lib gd pkg-config; gdSupport = false; }; } diff --git a/pills/12/setup-sh.txt b/pills/12/setup-sh.txt index 4c92bdc..bf9b24c 100644 --- a/pills/12/setup-sh.txt +++ b/pills/12/setup-sh.txt @@ -2,10 +2,7 @@ for p in $baseInputs $buildInputs; do if [ -d $p/bin ]; then export PATH="$p/bin${PATH:+:}$PATH" fi - if [ -d $p/include ]; then - export NIX_CFLAGS_COMPILE="-I $p/include${NIX_CFLAGS_COMPILE:+ }$NIX_CFLAGS_COMPILE" - fi - if [ -d $p/lib ]; then - export NIX_LDFLAGS="-rpath $p/lib -L $p/lib${NIX_LDFLAGS:+ }$NIX_LDFLAGS" + if [ -d $p/lib/pkgconfig ]; then + export PKG_CONFIG_PATH="$p/lib/pkgconfig${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH" fi done