From d15e52f25f367d172efe831da89cec7b55123e57 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sat, 20 Sep 2014 02:37:28 +0400 Subject: stdenv: fail if the patch does not exist --- pkgs/stdenv/generic/setup.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index ea2ea947b505..e0e9a00a02e9 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -569,6 +569,10 @@ patchPhase() { for i in $patches; do header "applying patch $i" 3 + if [ ! -r $i ]; then + echo "file $i does not exist or not readable" + exit 1 + fi local uncompress=cat case $i in *.gz) -- cgit 1.4.1 From d59327b9382a6f7339570af88716693fc621c9eb Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 9 Oct 2014 23:41:56 +0400 Subject: stdenv: added escaping for patches --- pkgs/stdenv/generic/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index e0e9a00a02e9..443e57b065d0 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -569,12 +569,12 @@ patchPhase() { for i in $patches; do header "applying patch $i" 3 - if [ ! -r $i ]; then + if [ ! -r "$i" ]; then echo "file $i does not exist or not readable" exit 1 fi local uncompress=cat - case $i in + case "$i" in *.gz) uncompress="gzip -d" ;; @@ -589,7 +589,7 @@ patchPhase() { ;; esac # "2>&1" is a hack to make patch fail if the decompressor fails (nonexistent patch, etc.) - $uncompress < $i 2>&1 | patch ${patchFlags:--p1} + $uncompress < "$i" 2>&1 | patch ${patchFlags:--p1} stopNest done -- cgit 1.4.1 From 2ec4704961bc12bab1ba1a5af05f21d2dcc91e7d Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 9 Oct 2014 23:13:08 +0400 Subject: stdenv: Fix handling spaces in 'substitute' --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 443e57b065d0..eba29beee172 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -339,7 +339,7 @@ substitute() { local n p pattern replacement varName content # a slightly hacky way to keep newline at the end - content="$(cat $input; echo -n X)" + content="$(cat "$input"; echo -n X)" content="${content%X}" for ((n = 2; n < ${#params[*]}; n += 1)); do -- cgit 1.4.1 From ca3ecb56ae5a0a5b675ebecdb819a0b97c547df0 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 9 Oct 2014 23:14:17 +0400 Subject: stdenv: change 'echo -n' to 'printf "%s"' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Bjørn: rationale is portability, "echo -n" isn't in POSIX] --- pkgs/stdenv/generic/setup.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index eba29beee172..03859f3ba8af 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -101,7 +101,7 @@ exitHandler() { if [ -n "$succeedOnFailure" ]; then echo "build failed with exit code $exitCode (ignored)" mkdir -p "$out/nix-support" - echo -n $exitCode > "$out/nix-support/failed" + printf "%s" $exitCode > "$out/nix-support/failed" exit 0 fi @@ -339,7 +339,7 @@ substitute() { local n p pattern replacement varName content # a slightly hacky way to keep newline at the end - content="$(cat "$input"; echo -n X)" + content="$(cat "$input"; printf "%s" X)" content="${content%X}" for ((n = 2; n < ${#params[*]}; n += 1)); do @@ -367,8 +367,7 @@ substitute() { content="${content//"$pattern"/$replacement}" done - # !!! This doesn't work properly if $content is "-n". - echo -n "$content" > "$output".tmp + printf "%s" "$content" > "$output".tmp if [ -x "$output" ]; then chmod +x "$output".tmp; fi mv -f "$output".tmp "$output" } -- cgit 1.4.1 From 66d89ef2a4ff8b9a525985de3ae197dface0d8a5 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 10 Oct 2014 13:50:25 +0400 Subject: stdenv: Use "pipefail" in setup.sh --- pkgs/stdenv/generic/setup.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 03859f3ba8af..24deac21c59f 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,4 +1,5 @@ set -e +set -o pipefail : ${outputs:=out} @@ -568,10 +569,6 @@ patchPhase() { for i in $patches; do header "applying patch $i" 3 - if [ ! -r "$i" ]; then - echo "file $i does not exist or not readable" - exit 1 - fi local uncompress=cat case "$i" in *.gz) -- cgit 1.4.1 From c04e49289871232ff3c2fd1239b64c2513f18fd1 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Tue, 28 Oct 2014 23:10:26 +0100 Subject: stdenv: Prevent issues like #4266 Don't preserve hardlinks, and instead use reflinks if they're available. --- pkgs/stdenv/generic/setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 24deac21c59f..fe801c6bb971 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -463,7 +463,9 @@ _defaultUnpack() { if [ -d "$fn" ]; then stripHash "$fn" - cp -prd --no-preserve=timestamps "$fn" $strippedName + # We can't preserve hardlinks because they may have been introduced by + # store optimization, which might break things in the build + cp -pr --reflink=auto --no-preserve=timestamps "$fn" $strippedName else -- cgit 1.4.1 From 8e9e4b05f76bc0f9af6e0554ca15b81ea63fa598 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 6 Nov 2014 11:26:09 +0100 Subject: Fix running preHook Accidentally (?) lost in e3875297fac671f20feb803306e7c55789ac749e. --- pkgs/stdenv/generic/setup.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index fe801c6bb971..864a519157c3 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -181,6 +181,7 @@ if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi # Execute the pre-hook. export CONFIG_SHELL="$SHELL" if [ -z "$shell" ]; then export shell=$SHELL; fi +runHook preHook # Allow the caller to augment buildInputs (it's not always possible to -- cgit 1.4.1 From 1014620bcec75f07ee8836f517cf6aa7dd66b4c3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 6 Nov 2014 12:10:28 +0100 Subject: stdenv: Statically include the default build inputs Otherwise, stdenv won't have a reference to e.g. patchelf on Linux (because it was passed in by mkDerivation). This causes the installer tests to fail, because having "stdenv" in the installation CD closure is not enough to pull in all stdenv packages. http://hydra.nixos.org/build/16546643 --- pkgs/stdenv/generic/builder.sh | 1 + pkgs/stdenv/generic/default.nix | 10 +++++----- pkgs/stdenv/generic/setup.sh | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index 4fa722a73dd2..a46c46c2db50 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -8,6 +8,7 @@ mkdir $out echo "export SHELL=$shell" > $out/setup echo "initialPath=\"$initialPath\"" >> $out/setup +echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" >> $out/setup echo "$preHook" >> $out/setup cat "$setup" >> $out/setup diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index ce78475f5fad..20ce303307db 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -41,7 +41,7 @@ let isUnfree = licenses: lib.lists.any (l: !l.free or true || l == "unfree" || l == "unfree-redistributable") licenses; - extraBuildInputs' = extraBuildInputs ++ + defaultNativeBuildInputs = extraBuildInputs ++ [ ../../build-support/setup-hooks/move-docs.sh ../../build-support/setup-hooks/compress-man-pages.sh ../../build-support/setup-hooks/strip.sh @@ -93,10 +93,10 @@ let __ignoreNulls = true; # Inputs built by the cross compiler. - buildInputs = if crossConfig != null then buildInputs ++ extraBuildInputs' else []; + buildInputs = if crossConfig != null then buildInputs else []; propagatedBuildInputs = if crossConfig != null then propagatedBuildInputs else []; # Inputs built by the usual native compiler. - nativeBuildInputs = nativeBuildInputs ++ (if crossConfig == null then buildInputs ++ extraBuildInputs' else []); + nativeBuildInputs = nativeBuildInputs ++ (if crossConfig == null then buildInputs else []); propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ (if crossConfig == null then propagatedBuildInputs else []); }))) ( @@ -130,9 +130,9 @@ let setup = setupScript; - inherit preHook initialPath shell; + inherit preHook initialPath shell defaultNativeBuildInputs; - propagatedUserEnvPkgs = [gcc] ++ + propagatedUserEnvPkgs = [ gcc ] ++ lib.filter lib.isDerivation initialPath; }) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 864a519157c3..904cc13e06c7 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -220,12 +220,12 @@ findInputs() { } crossPkgs="" -for i in $buildInputs $propagatedBuildInputs; do +for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do findInputs $i crossPkgs propagated-build-inputs done nativePkgs="" -for i in $nativeBuildInputs $propagatedNativeBuildInputs; do +for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do findInputs $i nativePkgs propagated-native-build-inputs done -- cgit 1.4.1 From 78b01de68d6ecb65ed3b3220e96d290e116436aa Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Nov 2014 13:35:09 +0100 Subject: substituteAll: Enumerate environment variables more reliably Getting the names of all environment variables is tricky. The previous implementation easily got confused by multi-line variables. The new one is more reliable but not still not perfect. This works around a segfault in Bash 4.3, where the expression "${!var}" (where var="-9") crashes under certain conditions. http://hydra.nixos.org/build/16693445 --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index fe801c6bb971..987d7766ce89 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -386,7 +386,7 @@ substituteAll() { local output="$2" # Select all environment variables that start with a lowercase character. - for envVar in $(env | sed "s/^[^a-z].*//" | sed "s/^\([^=]*\)=.*/\1/"); do + for envVar in $(env | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do if [ "$NIX_DEBUG" = "1" ]; then echo "$envVar -> ${!envVar}" fi -- cgit 1.4.1 From 1455ecee734d537766ee61515c77582a9ebd5309 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Nov 2014 14:09:53 +0100 Subject: Ensure a correct value for $BASH Previously it was set to /run/current-system/sw/sbin/nologin or similar. --- pkgs/stdenv/generic/setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 987d7766ce89..e9cb75bb6942 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -176,10 +176,11 @@ fi # Check that the pre-hook initialised SHELL. if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi +BASH="$SHELL" +export CONFIG_SHELL="$SHELL" # Execute the pre-hook. -export CONFIG_SHELL="$SHELL" if [ -z "$shell" ]; then export shell=$SHELL; fi -- cgit 1.4.1 From 71c3c1963899e0bc6e18e32a7191670993c3e583 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Jan 2015 13:01:33 +0100 Subject: stdenv: Remove redundant "building ..." message Nix already shows what paths are being built. --- pkgs/stdenv/generic/setup.sh | 4 ---- 1 file changed, 4 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 1cc60ebf02bc..8c9f127e806c 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -783,8 +783,6 @@ showPhaseHeader() { genericBuild() { - header "building $out" - if [ -n "$buildCommand" ]; then eval "$buildCommand" return @@ -828,8 +826,6 @@ genericBuild() { stopNest done - - stopNest } -- cgit 1.4.1 From 2533a1124192c9da20087514986c3d37cc106c15 Mon Sep 17 00:00:00 2001 From: Vladimír Čunát Date: Sun, 11 Jan 2015 20:07:38 +0100 Subject: stdenv substitute: avoid using a temporary file - IMO using a temporary is not needed here (anymore), - temporary at that location can cause a problem (in a specific case): for example, when using the substituteAll function from nixpkgs on a single file directly under /nix/store/ (or ./foo-file), the stdenv's substitute tries to create a temporary directly under /nix/store, which causes problems on chrooted darwin (according to @copumpkin earlier today on IRC) --- pkgs/stdenv/generic/setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 1cc60ebf02bc..d72fddf439eb 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -370,9 +370,8 @@ substitute() { content="${content//"$pattern"/$replacement}" done - printf "%s" "$content" > "$output".tmp - if [ -x "$output" ]; then chmod +x "$output".tmp; fi - mv -f "$output".tmp "$output" + chmod -f +w "$output" || true + printf "%s" "$content" > "$output" } -- cgit 1.4.1 From bda440a7b3e473de92533e3693e9c32eb011c7a9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Mar 2015 14:12:24 +0100 Subject: substitute: Fix "No such file or directory" message on Darwin On Darwin, "chmod -f" does not suppress an error message if the file doesn't exist. So just check if the file exists. --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 82ea0863a707..452a80eadc75 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -370,7 +370,7 @@ substitute() { content="${content//"$pattern"/$replacement}" done - chmod -f +w "$output" || true + if [ -e "$output" ]; then chmod +w "$output".tmp; fi printf "%s" "$content" > "$output" } -- cgit 1.4.1 From afa998eb32b4959d5deb253bb9f96c6fd3c7af20 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Thu, 26 Mar 2015 15:44:54 -0700 Subject: stdenv: Substitute correctly chmods instead of .tmp which never exists --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 452a80eadc75..75be719c2b95 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -370,7 +370,7 @@ substitute() { content="${content//"$pattern"/$replacement}" done - if [ -e "$output" ]; then chmod +w "$output".tmp; fi + if [ -e "$output" ]; then chmod +w "$output"; fi printf "%s" "$content" > "$output" } -- cgit 1.4.1