[Nix-dev] [PATCH 1/4] perl-5.8 and perl-5.10: fixed build on MacOS X

Peter Simons simons at cryp.to
Thu Oct 8 14:25:48 CEST 2009


On MacOS X, we used to use the native perl interpreter from /usr/bin.
Unfortunately, that interpreter fails to build a number of packages
(Subversion, Git, etc. ...), because it assumes knowledge about the underlying
C compiler that is not valid for the compiler used by Nix. For example,
/usr/bin/perl assumes that the compiler can build binaries for both the ppc and
the x86 architecture. /usr/bin/FCC can do that, but the gcc from Nix can't.

The solution is to compile Perl 5.10 via Nix so that it can properly configure
itself. However, note that the resulting binary is impure: it will find headers
in /usr/include and libraries in /usr/lib -- something a pure perl binary
wouldn't do. In this respect our Nix-compiled perl binary is not better than
the native one from /usr/bin -- it's just more accurately configured.
---
 .../development/interpreters/perl-5.10/default.nix |   12 ++++---
 pkgs/development/interpreters/perl-5.8/builder.sh  |   22 -------------
 pkgs/development/interpreters/perl-5.8/default.nix |   32 ++++++++++++++++++-
 pkgs/top-level/all-packages.nix                    |   11 +++----
 4 files changed, 42 insertions(+), 35 deletions(-)
 delete mode 100644 pkgs/development/interpreters/perl-5.8/builder.sh

diff --git a/pkgs/development/interpreters/perl-5.10/default.nix b/pkgs/development/interpreters/perl-5.10/default.nix
index a8b8dd5..442f428 100644
--- a/pkgs/development/interpreters/perl-5.10/default.nix
+++ b/pkgs/development/interpreters/perl-5.10/default.nix
@@ -1,4 +1,6 @@
-{stdenv, fetchurl}:
+{ stdenv, fetchurl
+, impureLibcPath ? null
+}:
 
 stdenv.mkDerivation {
   name = "perl-5.10.0";
@@ -34,9 +36,9 @@ stdenv.mkDerivation {
   preConfigure =
     ''
       configureFlags="$configureFlags -Dprefix=$out -Dman1dir=$out/share/man/man1 -Dman3dir=$out/share/man/man3"
-      
-      if test "$NIX_ENFORCE_PURITY" = "1"; then
-        GLIBC=$(cat $NIX_GCC/nix-support/orig-libc)
+
+      if test "${if impureLibcPath == null then "$NIX_ENFORCE_PURITY" else "1"}" = "1"; then
+        GLIBC=${if impureLibcPath == null then "$(cat $NIX_GCC/nix-support/orig-libc)" else impureLibcPath}
         configureFlags="$configureFlags -Dlocincpth=$GLIBC/include -Dloclibpth=$GLIBC/lib"
       fi
     '';
@@ -44,7 +46,7 @@ stdenv.mkDerivation {
   preBuild =
     ''
       # Make Cwd work on NixOS (where we don't have a /bin/pwd).
-      substituteInPlace lib/Cwd.pm --replace "'/bin/pwd'" "'$(type -tP pwd)'"
+      ${if stdenv.system == "i686-darwin" then "" else "substituteInPlace lib/Cwd.pm --replace \"'/bin/pwd'\" \"'$(type -tP pwd)'\""}
     '';
 
   setupHook = ./setup-hook.sh;
diff --git a/pkgs/development/interpreters/perl-5.8/builder.sh b/pkgs/development/interpreters/perl-5.8/builder.sh
deleted file mode 100644
index 79458b3..0000000
--- a/pkgs/development/interpreters/perl-5.8/builder.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-source $stdenv/setup
-
-if test "$NIX_ENFORCE_PURITY" = "1"; then
-    GLIBC=$(cat $NIX_GCC/nix-support/orig-libc)
-    extraflags="-Dlocincpth=$GLIBC/include -Dloclibpth=$GLIBC/lib"
-fi
-
-configureScript=./Configure
-configureFlags="-de -Dcc=gcc -Dprefix=$out -Uinstallusrbinperl $extraflags"
-dontAddPrefix=1
-
-preBuild() {
-    # Make Cwd work on NixOS (where we don't have a /bin/pwd).
-    substituteInPlace lib/Cwd.pm --replace "'/bin/pwd'" "'$(type -tP pwd)'"
-}
-
-postInstall() {
-    ensureDir "$out/nix-support"
-    cp $setupHook $out/nix-support/setup-hook
-}
-
-genericBuild
diff --git a/pkgs/development/interpreters/perl-5.8/default.nix b/pkgs/development/interpreters/perl-5.8/default.nix
index 074d41e..48e3241 100644
--- a/pkgs/development/interpreters/perl-5.8/default.nix
+++ b/pkgs/development/interpreters/perl-5.8/default.nix
@@ -1,9 +1,37 @@
-{stdenv, fetchurl}:
+{ stdenv, fetchurl
+, impureLibcPath ? null
+}:
 
 stdenv.mkDerivation {
   name = "perl-5.8.8";
 
-  builder = ./builder.sh;
+  builder =
+   ''
+source $stdenv/setup
+
+if test "$NIX_ENFORCE_PURITY" = "1"; then
+    GLIBC=${if impureLibcPath == null then "$(cat $NIX_GCC/nix-support/orig-libc)" else impureLibcPath}
+    extraflags="-Dlocincpth=$GLIBC/include -Dloclibpth=$GLIBC/lib"
+fi
+
+configureScript=./Configure
+configureFlags="-de -Dcc=gcc -Dprefix=$out -Uinstallusrbinperl $extraflags"
+dontAddPrefix=1
+
+preBuild() {
+    # Make Cwd work on NixOS (where we don't have a /bin/pwd).
+    substituteInPlace lib/Cwd.pm --replace "'/bin/pwd'" "'$(type -tP pwd)'"
+}
+
+postInstall() {
+    ensureDir "$out/nix-support"
+    cp $setupHook $out/nix-support/setup-hook
+}
+
+genericBuild
+
+   '';
+
   src = fetchurl {
     url = mirror://cpan/src/perl-5.8.8.tar.bz2;
     sha256 = "1j8vzc6lva49mwdxkzhvm78dkxyprqs4n4057amqvsh4kh6i92l1";
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 4c6a43d..842ca0b 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2301,16 +2301,15 @@ let
     inherit (bleedingEdgeRepos) sourceByName;
   };
 
-  perl = if !stdenv.isLinux then sysPerl else perlReal;
-
-  perl58 = if !stdenv.isLinux then sysPerl else
-    import ../development/interpreters/perl-5.8 {
+  perl58 = import ../development/interpreters/perl-5.8 {
       inherit fetchurl stdenv;
+      impureLibcPath = if stdenv.isLinux then null else "/usr";
     };
 
-  perlReal = import ../development/interpreters/perl-5.10 {
-    fetchurl = fetchurlBoot;
+  perl = import ../development/interpreters/perl-5.10 {
     inherit stdenv;
+    fetchurl = fetchurlBoot;
+    impureLibcPath = if stdenv.isLinux then null else "/usr";
   };
 
   # FIXME: unixODBC needs patching on Darwin (see darwinports)
-- 
1.6.4.4




More information about the nix-dev mailing list