diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index 352a5895135f..5da6af4bdb60 100755 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -56,6 +56,7 @@ ln -s g77 $out/bin/f77 sed \ + -e "s^@out@^$out^g" \ -e "s^@ldflags@^$ldflags^g" \ -e "s^@ld@^$ldPath/ld^g" \ < $ldWrapper > $out/bin/ld @@ -63,7 +64,7 @@ chmod +x $out/bin/ld mkdir $out/nix-support -test -z "$gcc" && echo $gcc > $out/nix-support/orig-gcc +test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc cat > $out/nix-support/add-flags < $out/nix-support/setup-hook + +cp -p $utils $out/nix-support/utils \ No newline at end of file diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index a9c3f3382b85..304f919138f3 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -19,6 +19,7 @@ derivation { setupHook = ./setup-hook.sh; gccWrapper = ./gcc-wrapper.sh; ldWrapper = ./ld-wrapper.sh; + utils = ./utils.sh; inherit name stdenv nativeTools nativeGlibc nativePrefix gcc glibc binutils; langC = if nativeTools then true else gcc.langC; langCC = if nativeTools then true else gcc.langCC; diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh index 29d3ffb8e492..d144e142d214 100644 --- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh @@ -8,13 +8,15 @@ if test -z "$NIX_GLIBC_FLAGS_SET"; then . @out@/nix-support/add-flags fi +. @out@/nix-support/utils + # Figure out if linker flags should be passed. GCC prints annoying # warnings when they are not needed. dontLink=0 if test "$*" = "-v" -o -z "$*"; then dontLink=1 -else +else for i in "$@"; do if test "$i" = "-c"; then dontLink=1 @@ -34,19 +36,8 @@ fi # Optionally filter out paths not refering to the store. -skip () { - if test "$NIX_DEBUG" = "1"; then - echo "skipping impure path $1" >&2 - fi -} - -badPath() { - p=$1 - test "${p:0:${#NIX_STORE}}" = "$NIX_STORE" -o "${p:0:4}" = "/tmp" -} - params=("$@") -if test "$NIX_ENFORCE_PURITY" = "1x" -a -n "$NIX_STORE"; then +if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then rest=() n=0 while test $n -lt ${#params[*]}; do diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh index bf59b2a8afbb..45bb210aa6d9 100644 --- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh @@ -4,30 +4,29 @@ if test -n "$NIX_LD_WRAPPER_START_HOOK"; then . "$NIX_LD_WRAPPER_START_HOOK" fi -# Optionally filter out paths not refering to the store. -skip () { - if test "$NIX_DEBUG" = "1"; then - echo "skipping impure path $1" >&2 - fi -} +. @out@/nix-support/utils + +# Optionally filter out paths not refering to the store. params=("$@") -if test "$NIX_ENFORCE_PURITY" = "1x" -a -n "$NIX_STORE"; then +if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then rest=() n=0 while test $n -lt ${#params[*]}; do p=${params[n]} p2=${params[$((n+1))]} - if test "${p:0:3}" = "-L/" -a "${p:2:${#NIX_STORE}}" != "$NIX_STORE"; then + if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then skip $p - elif test "$p" = "-L" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then + elif test "$p" = "-L" && badPath "$p2"; then n=$((n + 1)); skip $p2 - elif test "$p" = "-dynamic-linker" -a "${p2:0:${#NIX_STORE}}" != "$NIX_STORE"; then + elif test "$p" = "-rpath" && badPath "$p2"; then n=$((n + 1)); skip $p2 -# elif test "${p:0:1}" = "/" -a "${p:0:${#NIX_STORE}}" != "$NIX_STORE"; then -# # We cannot skip this; barf. -# echo "impure path \`$p' used in link" -# exit 1 + elif test "$p" = "-dynamic-linker" && badPath "$p2"; then + n=$((n + 1)); skip $p2 + elif test "${p:0:1}" = "/" && badPath "$p"; then + # We cannot skip this; barf. + echo "impure path \`$p' used in link" >&2 + exit 1 else rest=("${rest[@]}" "$p") fi @@ -43,6 +42,7 @@ if test -z "$NIX_LDFLAGS_SET"; then extra=(${extra[@]} $NIX_LDFLAGS) fi +# Optionally print debug info. if test "$NIX_DEBUG" = "1"; then echo "original flags to @ld@:" >&2 for i in "${params[@]}"; do diff --git a/pkgs/build-support/gcc-wrapper/utils.sh b/pkgs/build-support/gcc-wrapper/utils.sh new file mode 100644 index 000000000000..5163c239527c --- /dev/null +++ b/pkgs/build-support/gcc-wrapper/utils.sh @@ -0,0 +1,13 @@ +skip () { + if test "$NIX_DEBUG" = "1"; then + echo "skipping impure path $1" >&2 + fi +} + +badPath() { + local p=$1 + test \ + "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \ + "${p:0:4}" != "/tmp" -a \ + "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP" +} diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 21611278c21b..2dedf46ac2b3 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -69,8 +69,6 @@ addToEnv() export _PATH=$_PATH:$1/bin fi - echo "${envHooks[@]}" - for i in "${envHooks[@]}"; do $i $pkg done @@ -92,8 +90,20 @@ export NIX_STRIP_DEBUG=1 export NIX_CFLAGS_STRIP="-g0 -Wl,-s" -# Where is the store? This is required for purity checking. -export NIX_STORE=$(dirname $out)/ # !!! hack +# Do we know where the store is? This is required for purity checking. +if test -z "$NIX_STORE"; then + echo "Error: you have an old version of Nix that does not set the" \ + "NIX_STORE variable. Please upgrade." >&2 + exit 1 +fi + + +# We also need to know the root of the build directory for purity checking. +if test -z "$NIX_BUILD_TOP"; then + echo "Error: you have an old version of Nix that does not set the" \ + "NIX_BUILD_TOP variable. Please upgrade." >&2 + exit 1 +fi # Set the TZ (timezone) environment variable, otherwise commands like diff --git a/pkgs/stdenv/nix-linux/boot.nix b/pkgs/stdenv/nix-linux/boot.nix index b104add43184..2e1f272fc603 100644 --- a/pkgs/stdenv/nix-linux/boot.nix +++ b/pkgs/stdenv/nix-linux/boot.nix @@ -1,19 +1,17 @@ -{stdenv, pkgs, glibc}: +{stdenv, glibc}: (import ../generic) { name = "stdenv-nix-linux-boot"; preHook = ./prehook-boot.sh; - initialPath = (import ../nix/path.nix) {pkgs = pkgs;}; + initialPath = "/usr/local /usr /"; inherit stdenv; gcc = (import ../../build-support/gcc-wrapper) { - name = pkgs.gcc.name; - nativeTools = false; + name = "gcc-native"; + nativeTools = true; nativeGlibc = false; - inherit (pkgs) gcc binutils; + nativePrefix = "/usr"; inherit stdenv glibc; }; - - param1 = pkgs.bash; } diff --git a/pkgs/stdenv/nix-linux/default.nix b/pkgs/stdenv/nix-linux/default.nix index ecbbc488cb4d..7219ae05726b 100644 --- a/pkgs/stdenv/nix-linux/default.nix +++ b/pkgs/stdenv/nix-linux/default.nix @@ -1,13 +1,13 @@ -{stdenv, glibc, pkgs}: +{stdenv, glibc, pkgs, genericStdenv, gccWrapper}: -(import ../generic) { +genericStdenv { name = "stdenv-nix-linux"; preHook = ./prehook.sh; initialPath = (import ../nix/path.nix) {pkgs = pkgs;}; inherit stdenv; - gcc = (import ../../build-support/gcc-wrapper) { + gcc = gccWrapper { name = pkgs.gcc.name; nativeTools = false; nativeGlibc = false; diff --git a/pkgs/stdenv/nix-linux/prehook-boot.sh b/pkgs/stdenv/nix-linux/prehook-boot.sh index 33f8bc0bb6e3..21248e16cdb2 100644 --- a/pkgs/stdenv/nix-linux/prehook-boot.sh +++ b/pkgs/stdenv/nix-linux/prehook-boot.sh @@ -1,3 +1,3 @@ -export SHELL=$param1 +export SHELL=/bin/sh export NIX_ENFORCE_PURITY= diff --git a/pkgs/system/stdenvs.nix b/pkgs/system/stdenvs.nix index e3381090f037..ecf8fa0f5280 100644 --- a/pkgs/system/stdenvs.nix +++ b/pkgs/system/stdenvs.nix @@ -7,6 +7,9 @@ {system, allPackages}: rec { + gccWrapper = import ../build-support/gcc-wrapper; + genericStdenv = import ../stdenv/generic; + # Trivial environment used for building other environments. stdenvInitial = (import ../stdenv/initial) { @@ -45,7 +48,6 @@ # plus the pure glibc. stdenvLinuxBoot1 = (import ../stdenv/nix-linux/boot.nix) { stdenv = stdenvNative; - pkgs = allPackages {stdenv = stdenvNative; noSysDirs = false;}; glibc = stdenvLinuxGlibc; }; @@ -60,6 +62,7 @@ stdenv = stdenvLinuxBoot1; pkgs = stdenvLinuxBoot1Pkgs; glibc = stdenvLinuxGlibc; + inherit genericStdenv gccWrapper; }; # 5) These packages should be pure. @@ -70,6 +73,7 @@ stdenv = stdenvLinuxBoot2; pkgs = stdenvLinuxBoot2Pkgs; glibc = stdenvLinuxGlibc; + inherit genericStdenv gccWrapper; }; # 7) And we can build all packages against that, but we don't diff --git a/pkgs/test/simple/builder.sh b/pkgs/test/simple/builder.sh index cfc895ac1392..f97356a55630 100755 --- a/pkgs/test/simple/builder.sh +++ b/pkgs/test/simple/builder.sh @@ -6,10 +6,7 @@ export NIX_DEBUG=1 . $stdenv/setup -#echo starting shell -#/bin/sh < /dev/tty > /dev/tty 2>&1 - -#exit 1 +export NIX_ENFORCE_PURITY=1 mkdir $out mkdir $out/bin @@ -25,7 +22,7 @@ int main(int argc, char * * argv) EOF #gcc -I/nix/store/foo -I /nix/store/foo -I/usr/lib -I /usr/lib hello.c -o $out/bin/hello -gcc -L /nix/store/abcd/lib -isystem /usr/lib hello.c -o $out/bin/hello +gcc -I`pwd` -L /nix/store/abcd/lib -isystem /usr/lib hello.c -o $out/bin/hello $out/bin/hello diff --git a/pkgs/test/simple/default.nix b/pkgs/test/simple/default.nix index 39b0416fc9a1..0201097dc7d3 100644 --- a/pkgs/test/simple/default.nix +++ b/pkgs/test/simple/default.nix @@ -6,7 +6,7 @@ let { allPackages = import ../../system/all-packages-generic.nix; }; - stdenv = stdenvs.stdenvLinuxBoot2; + stdenv = stdenvs.stdenvLinux; test = derivation { name = "simple-test";