From 01a1658c6b8cdf75ad87ea24d1f82bc6c17670d4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 30 Mar 2004 12:46:52 +0000 Subject: [PATCH] * Finally we have a working stdenvLinux again. On the downside, the build process of stdenvLinux builds gcc 9 times (3 x 3 bootstrap stages). That's a bit excessive. svn path=/nixpkgs/trunk/; revision=880 --- pkgs/build-support/gcc-wrapper/builder.sh | 4 +- pkgs/build-support/gcc-wrapper/default.nix | 3 +- pkgs/build-support/gcc-wrapper/gcc-wrapper.sh | 2 +- pkgs/build-support/gcc-wrapper/ld-wrapper.sh | 5 +- pkgs/stdenv/generic/builder.sh | 1 + pkgs/stdenv/generic/default.nix | 8 +-- pkgs/stdenv/generic/setup.sh | 1 + pkgs/stdenv/initial/default.nix | 8 ++- pkgs/stdenv/native/default.nix | 2 +- pkgs/stdenv/native/prehook.sh | 2 - pkgs/stdenv/nix-linux/boot.nix | 19 ------ pkgs/stdenv/nix-linux/default.nix | 7 +- pkgs/stdenv/nix-linux/prehook-boot.sh | 3 - pkgs/stdenv/nix-linux/prehook.sh | 2 - pkgs/stdenv/nix/default.nix | 5 +- pkgs/stdenv/nix/prehook.sh | 3 +- pkgs/system/stdenvs.nix | 67 ++++++++++++------- pkgs/test/simple/builder.sh | 2 +- pkgs/test/simple/default.nix | 7 +- 19 files changed, 76 insertions(+), 75 deletions(-) delete mode 100644 pkgs/stdenv/nix-linux/boot.nix delete mode 100644 pkgs/stdenv/nix-linux/prehook-boot.sh diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index f6f388911531..a6a4c3f7253c 100644 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -39,7 +39,7 @@ mkGccWrapper () { sed \ -e "s^@gcc@^$src^g" \ -e "s^@out@^$out^g" \ - -e "s^@bash@^$SHELL^g" \ + -e "s^@shell@^$shell^g" \ < $gccWrapper > $dst chmod +x $dst } @@ -58,7 +58,7 @@ sed \ -e "s^@out@^$out^g" \ -e "s^@ldflags@^$ldflags^g" \ -e "s^@ld@^$ldPath/ld^g" \ - -e "s^@bash@^$SHELL^g" \ + -e "s^@shell@^$shell^g" \ < $ldWrapper > $out/bin/ld chmod +x $out/bin/ld diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index 486876049715..4dfacf9b3b53 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -6,7 +6,7 @@ # variables so that the compiler and the linker just "work". { name, stdenv, nativeTools, nativeGlibc, nativePrefix ? "" -, gcc ? null, glibc ? null, binutils ? null +, gcc ? null, glibc ? null, binutils ? null, shell ? "" }: assert nativeTools -> nativePrefix != ""; @@ -23,4 +23,5 @@ stdenv.mkDerivation { langC = if nativeTools then true else gcc.langC; langCC = if nativeTools then true else gcc.langCC; langF77 = if nativeTools then false else gcc.langF77; + shell = if shell == "" then stdenv.shell else shell; } diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh index 21e519242091..149d6e2fcbcc 100644 --- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh @@ -1,4 +1,4 @@ -#! @bash@ -e +#! @shell@ -e if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then . "$NIX_GCC_WRAPPER_START_HOOK" diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh index 1443af331550..3196a9322464 100644 --- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh @@ -1,4 +1,4 @@ -#! @bash@ -e +#! @shell@ -e if test -n "$NIX_LD_WRAPPER_START_HOOK"; then . "$NIX_LD_WRAPPER_START_HOOK" @@ -9,7 +9,8 @@ fi # Optionally filter out paths not refering to the store. params=("$@") -if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then +if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \ + -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then rest=() n=0 while test $n -lt ${#params[*]}; do diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index b3d464322499..bbcd19448cb7 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -13,6 +13,7 @@ sed \ -e "s^@postHook@^$postHook^g" \ -e "s^@initialPath@^$initialPath^g" \ -e "s^@gcc@^$gcc^g" \ + -e "s^@shell@^$shell^g" \ -e "s^@param1@^$p1^g" \ -e "s^@param2@^$p2^g" \ -e "s^@param3@^$p3^g" \ diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index d7b953ffb056..3aa2d3bfac07 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -1,4 +1,4 @@ -{ stdenv, name, preHook ? null, postHook ? null, initialPath, gcc, bash +{ stdenv, name, preHook ? null, postHook ? null, initialPath, gcc, shell , param1 ? "", param2 ? "", param3 ? "", param4 ? "", param5 ? "" }: @@ -13,17 +13,17 @@ let { setup = ./setup.sh; - inherit preHook postHook initialPath gcc; + inherit preHook postHook initialPath gcc shell; # TODO: make this more elegant. inherit param1 param2 param3 param4 param5; } # Add a utility function to produce derivations that use this - # stdenv and its the bash shell. + # stdenv and its shell. // { mkDerivation = attrs: derivation (attrs // { - builder = bash; + builder = shell; args = ["-e" (if attrs ? builder then attrs.builder else ./default-builder.sh)]; stdenv = body; system = body.system; diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 074e738dca37..4f1485f224bf 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -15,6 +15,7 @@ fi # Execute the pre-hook. +export SHELL=@shell@ param1=@param1@ param2=@param2@ param3=@param3@ diff --git a/pkgs/stdenv/initial/default.nix b/pkgs/stdenv/initial/default.nix index 6a62751b0370..4c67fee7cd5a 100644 --- a/pkgs/stdenv/initial/default.nix +++ b/pkgs/stdenv/initial/default.nix @@ -7,21 +7,25 @@ let { + shell = "/bin/sh"; + body = derivation { inherit system name; - builder = "/bin/sh"; + builder = shell; args = ["-e" ./builder.sh]; } // { mkDerivation = attrs: derivation (attrs // { - builder = "/bin/sh"; + builder = shell; args = ["-e" attrs.builder]; stdenv = body; system = body.system; }); + + inherit shell; }; } diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index 143230fbd893..2dae9c9fbf43 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -15,5 +15,5 @@ genericStdenv { inherit stdenv; }; - bash = "/bin/sh"; + shell = "/bin/sh"; } diff --git a/pkgs/stdenv/native/prehook.sh b/pkgs/stdenv/native/prehook.sh index 21248e16cdb2..1714586999e1 100644 --- a/pkgs/stdenv/native/prehook.sh +++ b/pkgs/stdenv/native/prehook.sh @@ -1,3 +1 @@ -export SHELL=/bin/sh - export NIX_ENFORCE_PURITY= diff --git a/pkgs/stdenv/nix-linux/boot.nix b/pkgs/stdenv/nix-linux/boot.nix deleted file mode 100644 index b556ba9ba361..000000000000 --- a/pkgs/stdenv/nix-linux/boot.nix +++ /dev/null @@ -1,19 +0,0 @@ -{stdenv, glibc, genericStdenv, gccWrapper}: - -genericStdenv { - name = "stdenv-nix-linux-boot"; - preHook = ./prehook-boot.sh; - initialPath = "/usr/local /usr /"; - - inherit stdenv; - - gcc = gccWrapper { - name = "gcc-native"; - nativeTools = true; - nativeGlibc = false; - nativePrefix = "/usr"; - inherit stdenv glibc; - }; - - bash = "/bin/sh"; -} diff --git a/pkgs/stdenv/nix-linux/default.nix b/pkgs/stdenv/nix-linux/default.nix index 9b4231962c30..c06f2cf815a1 100644 --- a/pkgs/stdenv/nix-linux/default.nix +++ b/pkgs/stdenv/nix-linux/default.nix @@ -12,10 +12,9 @@ genericStdenv { nativeTools = false; nativeGlibc = false; inherit (pkgs) gcc binutils; - inherit glibc; + inherit stdenv glibc; + shell = pkgs.bash ~ /bin/sh; }; - bash = pkgs.bash ~ /bin/sh; - - param1 = pkgs.bash; + shell = pkgs.bash ~ /bin/sh; } diff --git a/pkgs/stdenv/nix-linux/prehook-boot.sh b/pkgs/stdenv/nix-linux/prehook-boot.sh deleted file mode 100644 index 21248e16cdb2..000000000000 --- a/pkgs/stdenv/nix-linux/prehook-boot.sh +++ /dev/null @@ -1,3 +0,0 @@ -export SHELL=/bin/sh - -export NIX_ENFORCE_PURITY= diff --git a/pkgs/stdenv/nix-linux/prehook.sh b/pkgs/stdenv/nix-linux/prehook.sh index 0e0bada4fcb2..08bb6c0332c9 100644 --- a/pkgs/stdenv/nix-linux/prehook.sh +++ b/pkgs/stdenv/nix-linux/prehook.sh @@ -1,3 +1 @@ -export SHELL=$param1 - export NIX_ENFORCE_PURITY=1 diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index 5634553dd500..f3fb4a4f9517 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -13,9 +13,8 @@ genericStdenv { nativeGlibc = true; inherit (pkgs) gcc binutils; inherit stdenv; + shell = pkgs.bash ~ /bin/sh; }; - bash = pkgs.bash ~ /bin/sh; - - param1 = pkgs.bash; + shell = pkgs.bash ~ /bin/sh; } diff --git a/pkgs/stdenv/nix/prehook.sh b/pkgs/stdenv/nix/prehook.sh index af5121f49c38..734d0f1ae83a 100644 --- a/pkgs/stdenv/nix/prehook.sh +++ b/pkgs/stdenv/nix/prehook.sh @@ -1 +1,2 @@ -export SHELL=$param1 +export NIX_ENFORCE_PURITY=1 +export NIX_IGNORE_LD_THROUGH_GCC=1 diff --git a/pkgs/system/stdenvs.nix b/pkgs/system/stdenvs.nix index 0621608f2be3..7e41c0b6e86b 100644 --- a/pkgs/system/stdenvs.nix +++ b/pkgs/system/stdenvs.nix @@ -38,19 +38,14 @@ # The Nix build environment. stdenvNix = (import ../stdenv/nix) { stdenv = stdenvNative; - pkgs = stdenvNixBootPkgs; + pkgs = stdenvNativePkgs; inherit genericStdenv gccWrapper; }; - stdenvNixBootPkgs = allPackages { - stdenv = stdenvNative; - bootCurl = null; - noSysDirs = true; - }; - stdenvNixPkgs = allPackages { stdenv = stdenvNix; - bootCurl = stdenvNixBootPkgs.curl; + bootCurl = stdenvNativePkgs.curl; + noSysDirs = false; }; @@ -59,40 +54,53 @@ # 1) Build glibc in the Nix build environment. The result is # pure. - stdenvLinuxGlibc = stdenvNativePkgs.glibc; # !!! should be NixPkgs, but doesn't work + stdenvLinuxGlibc = stdenvNixPkgs.glibc; - # 2) Construct a stdenv consisting of the native build environment, - # plus the pure glibc. - stdenvLinuxBoot1 = (import ../stdenv/nix-linux/boot.nix) { + # 2) Construct a stdenv consisting of the Nix build environment, but + # with a gcc-wrapper that causes linking against the glibc from + # step 1. However, since the gcc wrapper here *does* look in + # native system directories (e.g., `/usr/lib'), it doesn't + # prevent impurity in the things it builds (e.g., through + # `-lncurses'). + stdenvLinuxBoot1 = (import ../stdenv/nix-linux) { stdenv = stdenvNative; + pkgs = stdenvNativePkgs; glibc = stdenvLinuxGlibc; inherit genericStdenv gccWrapper; }; - # 3) Now we can build packages that will have the Nix glibc. + # 3) Now we can build packages that will link against the Nix + # glibc. We are on thin ice here: the compiler used to build + # these packages doesn't prevent impurity, so e.g. bash ends up + # linking against `/lib/libncurses.so', but the glibc from step 1 + # *doesn't* search in `/lib' etc. So these programs won't work. stdenvLinuxBoot1Pkgs = allPackages { stdenv = stdenvLinuxBoot1; - bootCurl = null; + bootCurl = stdenvNativePkgs.curl; + noSysDirs = true; }; - # 4) However, since these packages are built by an native C compiler - # and linker, they may well pick up impure references (e.g., bash - # might end up linking against /lib/libncurses). So repeat, but - # now use the Nix-built tools from step 2/3. + # 4) Therefore we build a new standard environment which is the same + # as the one in step 2, but with a gcc and binutils from step 3 + # merged in. Since these are pure (they don't search native + # system directories), things built by this stdenv should be pure. stdenvLinuxBoot2 = (import ../stdenv/nix-linux) { stdenv = stdenvLinuxBoot1; - pkgs = stdenvLinuxBoot1Pkgs; + pkgs = stdenvNativePkgs // { + inherit (stdenvLinuxBoot1Pkgs) gcc binutils; + }; glibc = stdenvLinuxGlibc; inherit genericStdenv gccWrapper; }; - # 5) These packages should be pure. + # 5) So these packages should be pure. stdenvLinuxBoot2Pkgs = allPackages { stdenv = stdenvLinuxBoot2; - bootCurl = stdenvLinuxBoot1Pkgs.curl; + bootCurl = stdenvNativePkgs.curl; }; - # 6) So finally we can construct the Nix build environment. + # 6) Finally we can construct the Nix build environment from the + # packages from step 5. stdenvLinux = (import ../stdenv/nix-linux) { stdenv = stdenvLinuxBoot2; pkgs = stdenvLinuxBoot2Pkgs; @@ -109,7 +117,20 @@ } // {inherit (stdenvLinuxBoot2Pkgs) gzip bzip2 bash binutils coreutils diffutils findutils gawk gcc - gnumake gnused gnutar gnugrep wget; + gnumake gnused gnutar gnugrep curl; } // {glibc = stdenvLinuxGlibc;}; + + # In summary, we build gcc (and binutils) three times: + # - in stdenvLinuxBoot1 (from stdenvNativePkgs); impure + # - in stdenvLinuxBoot2 (from stdenvLinuxBoot1Pkgs); pure + # - in stdenvLinux (from stdenvLinuxBoot2Pkgs); pure + # The last one may be redundant, but its good for validation (since + # the second one may use impure inputs). To reduce build time, we + # could reduce the number of bootstrap stages inside each gcc build. + # Right now there are 3 stages, so gcc is built 9 times! + + # On the other hand, a validating build of glibc is a good idea (it + # probably won't work right now due to --rpath madness). + } diff --git a/pkgs/test/simple/builder.sh b/pkgs/test/simple/builder.sh index 7455f3e22748..dcfa49bd9c31 100644 --- a/pkgs/test/simple/builder.sh +++ b/pkgs/test/simple/builder.sh @@ -39,4 +39,4 @@ g++ hello2.cc -o $out/bin/hello2 -DVALUE="1 + 2 * 3" $out/bin/hello2 -ld -v \ No newline at end of file +ld -v diff --git a/pkgs/test/simple/default.nix b/pkgs/test/simple/default.nix index 0201097dc7d3..b7d9446bac7f 100644 --- a/pkgs/test/simple/default.nix +++ b/pkgs/test/simple/default.nix @@ -2,15 +2,14 @@ let { system = "i686-linux"; stdenvs = (import ../../system/stdenvs.nix) { - system = "i686-linux"; + inherit system; allPackages = import ../../system/all-packages-generic.nix; }; - stdenv = stdenvs.stdenvLinux; + stdenv = stdenvs.stdenvNix; - test = derivation { + test = stdenv.mkDerivation { name = "simple-test"; - inherit system stdenv; builder = ./builder.sh; };