Merge branch 'p/orig-modular-stdenv' of github.com:vcunat/nixpkgs into staging

This commit is contained in:
Eelco Dolstra 2014-09-08 22:32:11 +02:00
commit 88822dc23c
49 changed files with 509 additions and 411 deletions

View File

@ -2,4 +2,4 @@ addRLibPath () {
addToSearchPath R_LIBS_SITE $1/library addToSearchPath R_LIBS_SITE $1/library
} }
envHooks=(${envHooks[@]} addRLibPath) envHooks+=(addRLibPath)

View File

@ -1,3 +1,5 @@
export NIX_GCC=@out@
addCVars () { addCVars () {
if test -d $1/include; then if test -d $1/include; then
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include" export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
@ -12,7 +14,7 @@ addCVars () {
fi fi
} }
envHooks=(${envHooks[@]} addCVars) envHooks+=(addCVars)
# Note: these come *after* $out in the PATH (see setup.sh). # Note: these come *after* $out in the PATH (see setup.sh).

View File

@ -13,9 +13,7 @@
, ... } @ args: , ... } @ args:
fetchurl ({ fetchurl ({
# Remove the extension, because otherwise unpackPhase will get name = args.name or (baseNameOf url);
# confused. FIXME: fix unpackPhase.
name = args.name or lib.removeSuffix ".zip" (lib.removeSuffix ".tar.gz" (baseNameOf url));
recursiveHash = true; recursiveHash = true;

View File

@ -11,7 +11,7 @@ crossAddCVars () {
fi fi
} }
crossEnvHooks=(${crossEnvHooks[@]} crossAddCVars) crossEnvHooks+=(crossAddCVars)
crossStripDirs() { crossStripDirs() {
local dirs="$1" local dirs="$1"

View File

@ -1,3 +1,5 @@
export NIX_GCC=@out@
addCVars () { addCVars () {
if test -d $1/include; then if test -d $1/include; then
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include" export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
@ -12,7 +14,7 @@ addCVars () {
fi fi
} }
envHooks=(${envHooks[@]} addCVars) envHooks+=(addCVars)
# Note: these come *after* $out in the PATH (see setup.sh). # Note: these come *after* $out in the PATH (see setup.sh).

View File

@ -0,0 +1,27 @@
fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi')
compressManPages() {
local dir="$1"
echo "gzipping man pages in $dir"
GLOBIGNORE=.:..:*.gz:*.bz2
for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
if [ -f "$f" -a ! -L "$f" ]; then
if gzip -c -n "$f" > "$f".gz; then
rm "$f"
else
rm "$f".gz
fi
fi
done
for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
fi
done
unset GLOBIGNORE
}

View File

@ -0,0 +1,50 @@
# This setup hook moves $out/{man,doc,info} to $out/share; moves
# $out/share/man to $man/share/man; and moves $out/share/doc to
# $man/share/doc.
preFixupHooks+=(_moveDocs)
_moveToShare() {
forceShare=${forceShare:=man doc info}
if [ -z "$forceShare" -o -z "$out" ]; then return; fi
for d in $forceShare; do
if [ -d "$out/$d" ]; then
if [ -d "$out/share/$d" ]; then
echo "both $d/ and share/$d/ exist!"
else
echo "moving $out/$d to $out/share/$d"
mkdir -p $out/share
mv $out/$d $out/share/
fi
fi
done
}
_moveToOutput() {
local d="$1"
local dst="$2"
if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi
local output
for output in $outputs; do
if [ "${!output}" = "$dst" ]; then continue; fi
if [ -d "${!output}/$d" ]; then
echo "moving ${!output}/$d to $dst/$d"
mkdir -p $dst/share
mv ${!output}/$d $dst/$d
break
fi
done
}
_moveDocs() {
_moveToShare
_moveToOutput share/man "$man"
_moveToOutput share/info "$info"
_moveToOutput share/doc "$doc"
# Remove empty share directory.
if [ -d "$out/share" ]; then
rmdir $out/share 2> /dev/null || true
fi
}

View File

@ -0,0 +1,62 @@
# This setup hook causes the fixup phase to rewrite all script
# interpreter file names (`#! /path') to paths found in $PATH. E.g.,
# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
# /usr/bin/env gets special treatment so that ".../bin/env python" is
# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
# already in the store are left untouched.
fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi')
patchShebangs() {
local dir="$1"
header "patching script interpreter paths in $dir"
local f
local oldPath
local newPath
local arg0
local args
local oldInterpreterLine
local newInterpreterLine
find "$dir" -type f -perm +0100 | while read f; do
if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
# missing shebang => not a script
continue
fi
oldInterpreterLine=$(head -1 "$f" | tail -c +3)
read -r oldPath arg0 args <<< "$oldInterpreterLine"
if $(echo "$oldPath" | grep -q "/bin/env$"); then
# Check for unsupported 'env' functionality:
# - options: something starting with a '-'
# - environment variables: foo=bar
if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
exit 1
fi
newPath="$(command -v "$arg0" || true)"
else
if [ "$oldPath" = "" ]; then
# If no interpreter is specified linux will use /bin/sh. Set
# oldpath="/bin/sh" so that we get /nix/store/.../sh.
oldPath="/bin/sh"
fi
newPath="$(command -v "$(basename "$oldPath")" || true)"
args="$arg0 $args"
fi
newInterpreterLine="$newPath $args"
if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
fi
fi
done
stopNest
}

View File

@ -10,4 +10,4 @@ addPkgToClassPath () {
done done
} }
envHooks=(''${envHooks[@]} addPkgToClassPath) envHooks+=(addPkgToClassPath)

View File

@ -0,0 +1,36 @@
# This setup hook strips libraries and executables in the fixup phase.
fixupOutputHooks+=(_doStrip)
_doStrip() {
if [ -z "$dontStrip" ]; then
stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
if [ -n "$stripDebugList" ]; then
stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
fi
stripAllList=${stripAllList:-}
if [ -n "$stripAllList" ]; then
stripDirs "$stripAllList" "${stripAllFlags:--s}"
fi
fi
}
stripDirs() {
local dirs="$1"
local stripFlags="$2"
local dirsNew=
for d in ${dirs}; do
if [ -d "$prefix/$d" ]; then
dirsNew="${dirsNew} $prefix/$d "
fi
done
dirs=${dirsNew}
if [ -n "${dirs}" ]; then
header "stripping (with flags $stripFlags) in$dirs"
find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
stopNest
fi
}

View File

@ -5,4 +5,4 @@ addDbusIncludePath () {
fi fi
} }
envHooks=(${envHooks[@]} addDbusIncludePath) envHooks+=(addDbusIncludePath)

View File

@ -10,4 +10,4 @@ addGuileLibPath () {
fi fi
} }
envHooks=(${envHooks[@]} addGuileLibPath) envHooks+=(addGuileLibPath)

View File

@ -5,4 +5,4 @@ addGuileLibPath () {
fi fi
} }
envHooks=(${envHooks[@]} addGuileLibPath) envHooks+=(addGuileLibPath)

View File

@ -2,4 +2,4 @@ addPerlLibPath () {
addToSearchPath PERL5LIB $1/lib/perl5/site_perl addToSearchPath PERL5LIB $1/lib/perl5/site_perl
} }
envHooks=(${envHooks[@]} addPerlLibPath) envHooks+=(addPerlLibPath)

View File

@ -2,4 +2,4 @@ addPerlLibPath () {
addToSearchPath PERL5LIB $1/lib/perl5/site_perl addToSearchPath PERL5LIB $1/lib/perl5/site_perl
} }
envHooks=(${envHooks[@]} addPerlLibPath) envHooks+=(addPerlLibPath)

View File

@ -2,4 +2,4 @@ addPerlLibPath () {
addToSearchPath PERL5LIB $1/lib/perl5/site_perl addToSearchPath PERL5LIB $1/lib/perl5/site_perl
} }
envHooks=(${envHooks[@]} addPerlLibPath) envHooks+=(addPerlLibPath)

View File

@ -2,4 +2,4 @@ addPerlLibPath () {
addToSearchPath PERL5LIB $1/@libPrefix@ addToSearchPath PERL5LIB $1/@libPrefix@
} }
envHooks=(${envHooks[@]} addPerlLibPath) envHooks+=(addPerlLibPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -12,4 +12,4 @@ toPythonPath() {
echo $result echo $result
} }
envHooks=(${envHooks[@]} addPythonPath) envHooks+=(addPythonPath)

View File

@ -5,5 +5,5 @@ addGstreamer1LibPath () {
fi fi
} }
envHooks=(${envHooks[@]} addGstreamer1LibPath) envHooks+=(addGstreamer1LibPath)

View File

@ -5,4 +5,4 @@ addGstreamerLibPath () {
fi fi
} }
envHooks=(${envHooks[@]} addGstreamerLibPath) envHooks+=(addGstreamerLibPath)

View File

@ -23,5 +23,5 @@ if test -z "$libxmlHookDone"; then
# xmllint and xsltproc from looking in /etc/xml/catalog. # xmllint and xsltproc from looking in /etc/xml/catalog.
export XML_CATALOG_FILES export XML_CATALOG_FILES
if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi
envHooks=(${envHooks[@]} addXMLCatalogs) envHooks+=(addXMLCatalogs)
fi fi

View File

@ -10,4 +10,4 @@ addSlibPath () {
fi fi
} }
envHooks=(${envHooks[@]} addSlibPath) envHooks+=(addSlibPath)

View File

@ -33,7 +33,7 @@ collectNixLispLDLP () {
export NIX_LISP_COMMAND NIX_LISP CL_SOURCE_REGISTRY NIX_LISP_ASDF export NIX_LISP_COMMAND NIX_LISP CL_SOURCE_REGISTRY NIX_LISP_ASDF
envHooks=(envHooks[@] addASDFPaths setLisp collectNixLispLDLP) envHooks+=(addASDFPaths setLisp collectNixLispLDLP)
mkdir -p "$HOME"/.cache/common-lisp || HOME="$TMP/.temp-$USER-home" mkdir -p "$HOME"/.cache/common-lisp || HOME="$TMP/.temp-$USER-home"
mkdir -p "$HOME"/.cache/common-lisp mkdir -p "$HOME"/.cache/common-lisp

View File

@ -2,4 +2,4 @@ addOcamlMakefile () {
export OCAMLMAKEFILE="@out@/include/OCamlMakefile" export OCAMLMAKEFILE="@out@/include/OCamlMakefile"
} }
envHooks=(${envHooks[@]} addOcamlMakefile) envHooks+=(addOcamlMakefile)

View File

@ -2,4 +2,4 @@ addAclocals () {
addToSearchPathWithCustomDelimiter : ACLOCAL_PATH $1/share/aclocal addToSearchPathWithCustomDelimiter : ACLOCAL_PATH $1/share/aclocal
} }
envHooks=(${envHooks[@]} addAclocals) envHooks+=(addAclocals)

View File

@ -8,6 +8,8 @@ stdenv.mkDerivation rec {
sha256 = "c99f84d124347340c36707089ec8f70530abd56e7827c54d506eb4cc097a17e7"; sha256 = "c99f84d124347340c36707089ec8f70530abd56e7827c54d506eb4cc097a17e7";
}; };
setupHook = [ ./setup-hook.sh ];
meta = { meta = {
homepage = http://nixos.org/patchelf.html; homepage = http://nixos.org/patchelf.html;
license = "GPL"; license = "GPL";

View File

@ -0,0 +1,16 @@
# This setup hook calls patchelf to automatically remove unneeded
# directories from the RPATH of every library or executable in every
# output.
fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi')
patchELF() {
header "patching ELF executables and libraries in $prefix"
if [ -e "$prefix" ]; then
find "$prefix" \( \
\( -type f -a -name "*.so*" \) -o \
\( -type f -a -perm +0100 \) \
\) -print -exec patchelf --shrink-rpath '{}' \;
fi
stopNest
}

View File

@ -4,7 +4,7 @@ addPkgConfigPath () {
} }
if test -n "$crossConfig"; then if test -n "$crossConfig"; then
crossEnvHooks=(${crossEnvHooks[@]} addPkgConfigPath) crossEnvHooks+=(addPkgConfigPath)
else else
envHooks=(${envHooks[@]} addPkgConfigPath) envHooks+=(addPkgConfigPath)
fi fi

View File

@ -43,7 +43,7 @@ stdenv.mkDerivation {
fi fi
} }
envHooks=(''${envHooks[@]} addOCamlPath) envHooks+=(addOCamlPath)
''; '';
meta = { meta = {

View File

@ -2,4 +2,4 @@ addNodePath () {
addToSearchPath NODE_PATH $1/lib/node_modules addToSearchPath NODE_PATH $1/lib/node_modules
} }
envHooks=(${envHooks[@]} addNodePath) envHooks+=(addNodePath)

View File

@ -18,6 +18,8 @@ stdenv.mkDerivation rec {
"MANDIR=share/man/man1" "MANDIR=share/man/man1"
]; ];
setupHook = ./setup-hook.sh;
meta = with stdenv.lib; { meta = with stdenv.lib; {
description = "A tool for controlling PaX flags on a per binary basis"; description = "A tool for controlling PaX flags on a per binary basis";
homepage = "https://pax.grsecurity.net"; homepage = "https://pax.grsecurity.net";

View File

@ -0,0 +1,8 @@
# PaX-mark binaries.
paxmark() {
local flags="$1"
shift
paxctl -c "$@"
paxctl -zex -${flags} "$@"
}

View File

@ -5,7 +5,7 @@
# Posix utilities, the GNU C compiler, and so on. On other systems, # Posix utilities, the GNU C compiler, and so on. On other systems,
# we use the native C library. # we use the native C library.
{ system, allPackages ? import ../.., platform, config }: { system, allPackages ? import ../.., platform, config, lib }:
rec { rec {
@ -28,14 +28,14 @@ rec {
# The Nix build environment. # The Nix build environment.
stdenvNix = import ./nix { stdenvNix = import ./nix {
inherit config; inherit config lib;
stdenv = stdenvNative; stdenv = stdenvNative;
pkgs = stdenvNativePkgs; pkgs = stdenvNativePkgs;
}; };
# Linux standard environment. # Linux standard environment.
stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux; stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
# Select the appropriate stdenv for the platform `system'. # Select the appropriate stdenv for the platform `system'.

View File

@ -6,16 +6,11 @@ done
mkdir $out mkdir $out
echo "$preHook" > $out/setup echo "export SHELL=$shell" > $out/setup
echo "initialPath=\"$initialPath\"" >> $out/setup
echo "$preHook" >> $out/setup
cat "$setup" >> $out/setup cat "$setup" >> $out/setup
sed -e "s^@initialPath@^$initialPath^g" \
-e "s^@gcc@^$gcc^g" \
-e "s^@shell@^$shell^g" \
-e "s^@needsPax@^$needsPax^g" \
< $out/setup > $out/setup.tmp
mv $out/setup.tmp $out/setup
# Allow the user to install stdenv using nix-env and get the packages # Allow the user to install stdenv using nix-env and get the packages
# in stdenv. # in stdenv.
mkdir $out/nix-support mkdir $out/nix-support

View File

@ -10,8 +10,6 @@ let lib = import ../../../lib; in lib.makeOverridable (
, setupScript ? ./setup.sh , setupScript ? ./setup.sh
, extraBuildInputs ? [] , extraBuildInputs ? []
, skipPaxMarking ? false
}: }:
let let
@ -23,7 +21,7 @@ let
# {pkgs, ...}: # {pkgs, ...}:
# { # {
# allowUnfree = false; # allowUnfree = false;
# allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayero-" x.name); # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayer-" x.name);
# } # }
allowUnfreePredicate = config.allowUnfreePredicate or (x: false); allowUnfreePredicate = config.allowUnfreePredicate or (x: false);
@ -41,37 +39,13 @@ let
unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null); unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
# The stdenv that we are producing. extraBuildInputs' = extraBuildInputs ++
result = [ ../../build-support/setup-hooks/move-docs.sh
../../build-support/setup-hooks/compress-man-pages.sh
derivation { ../../build-support/setup-hooks/strip.sh
inherit system name; ../../build-support/setup-hooks/patch-shebangs.sh
gcc
builder = shell; ];
args = ["-e" ./builder.sh];
/* TODO: special-cased @var@ substitutions are ugly.
However, using substituteAll* from setup.sh seems difficult,
as setup.sh can't be directly sourced.
Suggestion: split similar utility functions into a separate script.
*/
setup = setupScript;
inherit preHook initialPath gcc shell;
# Whether we should run paxctl to pax-mark binaries
needsPax = result.isLinux && !skipPaxMarking;
propagatedUserEnvPkgs = [gcc] ++
lib.filter lib.isDerivation initialPath;
}
// rec {
meta = {
description = "The default build environment for Unix packages in Nixpkgs";
};
# Add a utility function to produce derivations that use this # Add a utility function to produce derivations that use this
# stdenv and its shell. # stdenv and its shell.
@ -84,7 +58,9 @@ let
unsafeGetAttrPos "name" attrs; unsafeGetAttrPos "name" attrs;
pos' = if pos != null then "" + pos.file + ":" + toString pos.line + "" else "«unknown-file»"; pos' = if pos != null then "" + pos.file + ":" + toString pos.line + "" else "«unknown-file»";
in in
if !allowUnfree && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) && !(allowUnfreePredicate attrs) then if !allowUnfree
&& (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l)
&& !allowUnfreePredicate attrs then
throw '' throw ''
Package ${attrs.name} in ${pos'} has an unfree license, refusing to evaluate. Package ${attrs.name} in ${pos'} has an unfree license, refusing to evaluate.
${forceEvalHelp "Unfree"}'' ${forceEvalHelp "Unfree"}''
@ -115,10 +91,10 @@ let
__ignoreNulls = true; __ignoreNulls = true;
# Inputs built by the cross compiler. # Inputs built by the cross compiler.
buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs); buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs');
propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs; propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs;
# Inputs built by the usual native compiler. # Inputs built by the usual native compiler.
nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs); nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs');
propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ propagatedNativeBuildInputs = propagatedNativeBuildInputs ++
lib.optionals (crossConfig == null) propagatedBuildInputs; lib.optionals (crossConfig == null) propagatedBuildInputs;
}))) ( }))) (
@ -139,6 +115,28 @@ let
# derivation (e.g., in assertions). # derivation (e.g., in assertions).
(attrs.passthru or {})); (attrs.passthru or {}));
# The stdenv that we are producing.
result =
derivation {
inherit system name;
builder = shell;
args = ["-e" ./builder.sh];
setup = setupScript;
inherit preHook initialPath shell;
propagatedUserEnvPkgs = [gcc] ++
lib.filter lib.isDerivation initialPath;
}
// rec {
meta.description = "The default build environment for Unix packages in Nixpkgs";
# Utility flags to test the type of platform. # Utility flags to test the type of platform.
isDarwin = system == "x86_64-darwin"; isDarwin = system == "x86_64-darwin";
isLinux = system == "i686-linux" isLinux = system == "i686-linux"
@ -185,6 +183,11 @@ let
|| system == "armv6l-linux" || system == "armv6l-linux"
|| system == "armv7l-linux"; || system == "armv7l-linux";
# Whether we should run paxctl to pax-mark binaries.
needsPax = isLinux;
inherit mkDerivation;
# For convenience, bring in the library functions in lib/ so # For convenience, bring in the library functions in lib/ so
# packages don't have to do that themselves. # packages don't have to do that themselves.
inherit lib; inherit lib;
@ -192,6 +195,8 @@ let
inherit fetchurlBoot; inherit fetchurlBoot;
inherit overrides; inherit overrides;
inherit gcc;
} }
# Propagate any extra attributes. For instance, we use this to # Propagate any extra attributes. For instance, we use this to

View File

@ -1,18 +1,79 @@
set -e
: ${outputs:=out}
######################################################################
# Hook handling.
# Run all hooks with the specified name in the order in which they
# were added, stopping if any fails (returns a non-zero exit
# code). The hooks for <hookName> are the shell function or variable
# <hookName>, and the values of the shell array <hookName>Hooks.
runHook() {
local hookName="$1"
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
eval "local -a dummy=(\"\${$var[@]}\")"
for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do
if ! _eval "$hook" "$@"; then return 1; fi
done
return 0
}
# Run all hooks with the specified name, until one succeeds (returns a
# zero exit code). If none succeed, return a non-zero exit code.
runOneHook() {
local hookName="$1"
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
eval "local -a dummy=(\"\${$var[@]}\")"
for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do
if _eval "$hook" "$@"; then
return 0
fi
done
return 1
}
# Run the named hook, either by calling the function with that name or # Run the named hook, either by calling the function with that name or
# by evaluating the variable with that name. This allows convenient # by evaluating the variable with that name. This allows convenient
# setting of hooks both from Nix expressions (as attributes / # setting of hooks both from Nix expressions (as attributes /
# environment variables) and from shell scripts (as functions). # environment variables) and from shell scripts (as functions). If you
runHook() { # want to allow multiple hooks, use runHook instead.
local hookName="$1" _callImplicitHook() {
local def="$1"
local hookName="$2"
case "$(type -t $hookName)" in case "$(type -t $hookName)" in
(function|alias|builtin) $hookName;; (function|alias|builtin) $hookName;;
(file) source $hookName;; (file) source $hookName;;
(keyword) :;; (keyword) :;;
(*) eval "${!hookName}";; (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
esac esac
} }
# A function wrapper around eval that ensures that return inside
# hooks exits the hook, not the caller.
_eval() {
local code="$1"
shift
if [ "$(type -t $code)" = function ]; then
eval "$code \"\$@\""
else
eval "$code"
fi
}
######################################################################
# Error handling.
exitHandler() { exitHandler() {
exitCode=$? exitCode=$?
set +e set +e
@ -55,7 +116,7 @@ trap "exitHandler" EXIT
###################################################################### ######################################################################
# Helper functions that might be useful in setup hooks. # Helper functions.
addToSearchPathWithCustomDelimiter() { addToSearchPathWithCustomDelimiter() {
@ -74,13 +135,24 @@ addToSearchPath() {
} }
ensureDir() {
echo "warning: ensureDir is deprecated; use mkdir instead" >&2
local dir
for dir in "$@"; do
if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
done
}
installBin() {
mkdir -p $out/bin
cp "$@" $out/bin
}
###################################################################### ######################################################################
# Initialisation. # Initialisation.
set -e
[ -z $NIX_GCC ] && NIX_GCC=@gcc@
# Wildcard expansions that don't match should expand to an empty list. # Wildcard expansions that don't match should expand to an empty list.
# This ensures that, for instance, "for i in *; do ...; done" does the # This ensures that, for instance, "for i in *; do ...; done" does the
@ -90,7 +162,7 @@ shopt -s nullglob
# Set up the initial path. # Set up the initial path.
PATH= PATH=
for i in $NIX_GCC @initialPath@; do for i in $initialPath; do
if [ "$i" = / ]; then i=; fi if [ "$i" = / ]; then i=; fi
addToSearchPath PATH $i/bin addToSearchPath PATH $i/bin
addToSearchPath PATH $i/sbin addToSearchPath PATH $i/sbin
@ -101,37 +173,13 @@ if [ "$NIX_DEBUG" = 1 ]; then
fi fi
# Execute the pre-hook.
export SHELL=@shell@
export CONFIG_SHELL="$SHELL"
if [ -z "$shell" ]; then export shell=@shell@; fi
runHook preHook
# Check that the pre-hook initialised SHELL. # Check that the pre-hook initialised SHELL.
if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
# Hack: run gcc's setup hook.
envHooks=()
crossEnvHooks=()
if [ -f $NIX_GCC/nix-support/setup-hook ]; then
source $NIX_GCC/nix-support/setup-hook
fi
# Execute the pre-hook.
# Ensure that the given directories exists. export CONFIG_SHELL="$SHELL"
ensureDir() { if [ -z "$shell" ]; then export shell=$SHELL; fi
echo "warning: ensureDir is deprecated; use mkdir instead" >&2
local dir
for dir in "$@"; do
if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
done
}
installBin() {
mkdir -p $out/bin
cp "$@" $out/bin
}
# Allow the caller to augment buildInputs (it's not always possible to # Allow the caller to augment buildInputs (it's not always possible to
@ -154,6 +202,10 @@ findInputs() {
eval $var="'${!var} $pkg '" eval $var="'${!var} $pkg '"
if [ -f $pkg ]; then
source $pkg
fi
if [ -f $pkg/nix-support/setup-hook ]; then if [ -f $pkg/nix-support/setup-hook ]; then
source $pkg/nix-support/setup-hook source $pkg/nix-support/setup-hook
fi fi
@ -178,7 +230,7 @@ done
# Set the relevant environment variables to point to the build inputs # Set the relevant environment variables to point to the build inputs
# found above. # found above.
addToNativeEnv() { _addToNativeEnv() {
local pkg=$1 local pkg=$1
if [ -d $1/bin ]; then if [ -d $1/bin ]; then
@ -186,16 +238,14 @@ addToNativeEnv() {
fi fi
# Run the package-specific hooks set by the setup-hook scripts. # Run the package-specific hooks set by the setup-hook scripts.
for i in "${envHooks[@]}"; do runHook envHook "$pkg"
$i $pkg
done
} }
for i in $nativePkgs; do for i in $nativePkgs; do
addToNativeEnv $i _addToNativeEnv $i
done done
addToCrossEnv() { _addToCrossEnv() {
local pkg=$1 local pkg=$1
# Some programs put important build scripts (freetype-config and similar) # Some programs put important build scripts (freetype-config and similar)
@ -206,13 +256,11 @@ addToCrossEnv() {
fi fi
# Run the package-specific hooks set by the setup-hook scripts. # Run the package-specific hooks set by the setup-hook scripts.
for i in "${crossEnvHooks[@]}"; do runHook crossEnvHook "$pkg"
$i $pkg
done
} }
for i in $crossPkgs; do for i in $crossPkgs; do
addToCrossEnv $i _addToCrossEnv $i
done done
@ -273,42 +321,11 @@ fi
export NIX_BUILD_CORES export NIX_BUILD_CORES
###################################################################### # Dummy implementation of the paxmark function. On Linux, this is
# Misc. helper functions. # overwritten by paxctl's setup hook.
paxmark() { true; }
stripDirs() {
local dirs="$1"
local stripFlags="$2"
local dirsNew=
for d in ${dirs}; do
if [ -d "$prefix/$d" ]; then
dirsNew="${dirsNew} $prefix/$d "
fi
done
dirs=${dirsNew}
if [ -n "${dirs}" ]; then
header "stripping (with flags $stripFlags) in $dirs"
find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
stopNest
fi
}
# PaX-mark binaries
paxmark() {
local flags="$1"
shift
if [ -z "@needsPax@" ]; then
return
fi
paxctl -c "$@"
paxctl -zex -${flags} "$@"
}
###################################################################### ######################################################################
# Textual substitution functions. # Textual substitution functions.
@ -439,39 +456,43 @@ stripHash() {
} }
unpackFile() { unpackCmdHooks+=(_defaultUnpack)
curSrc="$1" _defaultUnpack() {
local cmd local fn="$1"
header "unpacking source archive $curSrc" 3 if [ -d "$fn" ]; then
case "$curSrc" in stripHash "$fn"
cp -prd --no-preserve=timestamps "$fn" $strippedName
else
case "$fn" in
*.tar.xz | *.tar.lzma) *.tar.xz | *.tar.lzma)
# Don't rely on tar knowing about .xz. # Don't rely on tar knowing about .xz.
xz -d < $curSrc | tar xf - xz -d < "$fn" | tar xf -
;; ;;
*.tar | *.tar.* | *.tgz | *.tbz2) *.tar | *.tar.* | *.tgz | *.tbz2)
# GNU tar can automatically select the decompression method # GNU tar can automatically select the decompression method
# (info "(tar) gzip"). # (info "(tar) gzip").
tar xf $curSrc tar xf "$fn"
;;
*.zip)
unzip -qq $curSrc
;; ;;
*) *)
if [ -d "$curSrc" ]; then return 1
stripHash $curSrc
cp -prd --no-preserve=timestamps $curSrc $strippedName
else
if [ -z "$unpackCmd" ]; then
echo "source archive $curSrc has unknown type"
exit 1
fi
runHook unpackCmd
fi
;; ;;
esac esac
fi
}
unpackFile() {
curSrc="$1"
header "unpacking source archive $curSrc" 3
if ! runOneHook unpackCmd "$curSrc"; then
echo "do not know how to unpack source archive $curSrc"
exit 1
fi
stopNest stopNest
} }
@ -505,7 +526,7 @@ unpackPhase() {
# Find the source directory. # Find the source directory.
if [ -n "$setSourceRoot" ]; then if [ -n "$setSourceRoot" ]; then
runHook setSourceRoot runOneHook setSourceRoot
elif [ -z "$sourceRoot" ]; then elif [ -z "$sourceRoot" ]; then
sourceRoot= sourceRoot=
for i in *; do for i in *; do
@ -654,80 +675,6 @@ checkPhase() {
} }
patchELF() {
# Patch all ELF executables and shared libraries.
header "patching ELF executables and libraries"
if [ -e "$prefix" ]; then
find "$prefix" \( \
\( -type f -a -name "*.so*" \) -o \
\( -type f -a -perm +0100 \) \
\) -print -exec patchelf --shrink-rpath '{}' \;
fi
stopNest
}
patchShebangs() {
# Rewrite all script interpreter file names (`#! /path') under the
# specified directory tree to paths found in $PATH. E.g.,
# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
# /usr/bin/env gets special treatment so that ".../bin/env python" is
# rewritten to /nix/store/<hash>/bin/python.
# Interpreters that are already in the store are left untouched.
header "patching script interpreter paths"
local dir="$1"
local f
local oldPath
local newPath
local arg0
local args
local oldInterpreterLine
local newInterpreterLine
find "$dir" -type f -perm +0100 | while read f; do
if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
# missing shebang => not a script
continue
fi
oldInterpreterLine=$(head -1 "$f" | tail -c +3)
read -r oldPath arg0 args <<< "$oldInterpreterLine"
if $(echo "$oldPath" | grep -q "/bin/env$"); then
# Check for unsupported 'env' functionality:
# - options: something starting with a '-'
# - environment variables: foo=bar
if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
exit 1
fi
newPath="$(command -v "$arg0" || true)"
else
if [ "$oldPath" = "" ]; then
# If no interpreter is specified linux will use /bin/sh. Set
# oldpath="/bin/sh" so that we get /nix/store/.../sh.
oldPath="/bin/sh"
fi
newPath="$(command -v "$(basename "$oldPath")" || true)"
args="$arg0 $args"
fi
newInterpreterLine="$newPath $args"
if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
# escape the escape chars so that sed doesn't interpret them
escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
fi
fi
done
stopNest
}
installPhase() { installPhase() {
runHook preInstall runHook preInstall
@ -743,74 +690,22 @@ installPhase() {
} }
# The fixup phase performs generic, package-independent, Nix-related # The fixup phase performs generic, package-independent stuff, like
# stuff, like running patchelf and setting the # stripping binaries, running patchelf and setting
# propagated-build-inputs. It should rarely be overriden. # propagated-build-inputs.
fixupPhase() { fixupPhase() {
# Make sure everything is writable so "strip" et al. work.
for output in $outputs; do
if [ -e "${!output}" ]; then chmod -R u+w "${!output}"; fi
done
runHook preFixup runHook preFixup
# Make sure everything is writable so "strip" et al. work. # Apply fixup to each output.
if [ -e "$prefix" ]; then chmod -R u+w "$prefix"; fi local output
for output in $outputs; do
# Put man/doc/info under $out/share. prefix=${!output} runHook fixupOutput
forceShare=${forceShare:=man doc info}
if [ -n "$forceShare" ]; then
for d in $forceShare; do
if [ -d "$prefix/$d" ]; then
if [ -d "$prefix/share/$d" ]; then
echo "both $d/ and share/$d/ exists!"
else
echo "fixing location of $d/ subdirectory"
mkdir -p $prefix/share
if [ -w $prefix/share ]; then
mv -v $prefix/$d $prefix/share
ln -sv share/$d $prefix
fi
fi
fi
done;
fi
if [ -z "$dontGzipMan" ]; then
echo "gzipping man pages"
GLOBIGNORE=.:..:*.gz:*.bz2
for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
if [ -f "$f" -a ! -L "$f" ]; then
if gzip -c -n "$f" > "$f".gz; then
rm "$f"
else
rm "$f".gz
fi
fi
done done
for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
fi
done
unset GLOBIGNORE
fi
# TODO: strip _only_ ELF executables, and return || fail here...
if [ -z "$dontStrip" ]; then
stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
if [ -n "$stripDebugList" ]; then
stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
fi
stripAllList=${stripAllList:-}
if [ -n "$stripAllList" ]; then
stripDirs "$stripAllList" "${stripAllFlags:--s}"
fi
fi
if [ "$havePatchELF" = 1 -a -z "$dontPatchELF" ]; then
patchELF "$prefix"
fi
if [ -z "$dontPatchShebangs" ]; then
patchShebangs "$prefix"
fi
if [ -n "$propagatedBuildInputs" ]; then if [ -n "$propagatedBuildInputs" ]; then
mkdir -p "$out/nix-support" mkdir -p "$out/nix-support"
@ -935,7 +830,6 @@ genericBuild() {
# Execute the post-hooks. # Execute the post-hooks.
for i in "${postHooks[@]}"; do $i; done
runHook postHook runHook postHook

View File

@ -7,12 +7,10 @@
# The function defaults are for easy testing. # The function defaults are for easy testing.
{ system ? builtins.currentSystem { system ? builtins.currentSystem
, allPackages ? import ../../top-level/all-packages.nix , allPackages ? import ../../top-level/all-packages.nix
, platform ? null, config ? {} }: , platform ? null, config ? {}, lib }:
rec { rec {
lib = import ../../../lib;
bootstrapFiles = bootstrapFiles =
if system == "i686-linux" then import ./bootstrap/i686.nix if system == "i686-linux" then import ./bootstrap/i686.nix
else if system == "x86_64-linux" then import ./bootstrap/x86_64.nix else if system == "x86_64-linux" then import ./bootstrap/x86_64.nix
@ -26,7 +24,6 @@ rec {
commonPreHook = commonPreHook =
'' ''
export NIX_ENFORCE_PURITY=1 export NIX_ENFORCE_PURITY=1
havePatchELF=1
${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""} ${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""} ${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
''; '';
@ -209,7 +206,7 @@ rec {
extraAttrs = { extraAttrs = {
glibc = stage2.pkgs.glibc; # Required by gcc47 build glibc = stage2.pkgs.glibc; # Required by gcc47 build
}; };
extraPath = [ stage2.pkgs.paxctl ]; extraPath = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
}; };
@ -223,13 +220,9 @@ rec {
coreutils = bootstrapTools; coreutils = bootstrapTools;
name = ""; name = "";
}; };
extraPath = [ stage3.pkgs.xz ]; extraPath = [ stage2.pkgs.patchelf stage3.pkgs.xz ];
overrides = pkgs: { overrides = pkgs: {
# Zlib has to be inherited and not rebuilt in this stage, inherit (stage3.pkgs) gettext gnum4 gmp perl glibc;
# because gcc (since JAR support) already depends on zlib, and
# then if we already have a zlib we want to use that for the
# other purposes (binutils and top-level pkgs) too.
inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib;
}; };
}; };
@ -253,8 +246,9 @@ rec {
''; '';
initialPath = initialPath =
((import ../common-path.nix) {pkgs = stage4.pkgs;}) ((import ../common-path.nix) {pkgs = stage4.pkgs;});
++ [stage4.pkgs.patchelf stage4.pkgs.paxctl ];
extraBuildInputs = [ stage4.pkgs.patchelf stage4.pkgs.paxctl ];
shell = stage4.pkgs.bash + "/bin/bash"; shell = stage4.pkgs.bash + "/bin/bash";
@ -278,7 +272,7 @@ rec {
inherit (stage4.pkgs) inherit (stage4.pkgs)
gzip bzip2 xz bash binutils coreutils diffutils findutils gawk gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
glibc gnumake gnused gnutar gnugrep gnupatch patchelf glibc gnumake gnused gnutar gnugrep gnupatch patchelf
attr acl paxctl zlib; attr acl paxctl;
}; };
}; };

View File

@ -1,4 +1,4 @@
{ stdenv, pkgs, config }: { stdenv, pkgs, config, lib }:
import ../generic rec { import ../generic rec {
inherit config; inherit config;
@ -7,7 +7,7 @@ import ../generic rec {
'' ''
export NIX_ENFORCE_PURITY=1 export NIX_ENFORCE_PURITY=1
export NIX_IGNORE_LD_THROUGH_GCC=1 export NIX_IGNORE_LD_THROUGH_GCC=1
'' + (if stdenv.isDarwin then '' '' + lib.optionalString stdenv.isDarwin ''
export NIX_ENFORCE_PURITY= export NIX_ENFORCE_PURITY=
export NIX_DONT_SET_RPATH=1 export NIX_DONT_SET_RPATH=1
export NIX_NO_SELF_RPATH=1 export NIX_NO_SELF_RPATH=1
@ -18,7 +18,7 @@ import ../generic rec {
export SDKROOT=$(/usr/bin/xcrun --show-sdk-path 2> /dev/null || true) export SDKROOT=$(/usr/bin/xcrun --show-sdk-path 2> /dev/null || true)
export NIX_CFLAGS_COMPILE+=" --sysroot=/var/empty -idirafter $SDKROOT/usr/include -F$SDKROOT/System/Library/Frameworks -Wno-multichar -Wno-deprecated-declarations" export NIX_CFLAGS_COMPILE+=" --sysroot=/var/empty -idirafter $SDKROOT/usr/include -F$SDKROOT/System/Library/Frameworks -Wno-multichar -Wno-deprecated-declarations"
export NIX_LDFLAGS_AFTER+=" -L$SDKROOT/usr/lib" export NIX_LDFLAGS_AFTER+=" -L$SDKROOT/usr/lib"
'' else ""); '';
initialPath = (import ../common-path.nix) {pkgs = pkgs;}; initialPath = (import ../common-path.nix) {pkgs = pkgs;};

View File

@ -1,7 +1,7 @@
{ stdenv, fetchurl, bzip2 { stdenv, fetchurl, bzip2
, enableNLS ? false, libnatspec }: , enableNLS ? false, libnatspec }:
stdenv.mkDerivation ({ stdenv.mkDerivation {
name = "unzip-6.0"; name = "unzip-6.0";
src = fetchurl { src = fetchurl {
@ -9,6 +9,13 @@ stdenv.mkDerivation ({
sha256 = "0dxx11knh3nk95p2gg2ak777dd11pr7jx5das2g49l262scrcv83"; sha256 = "0dxx11knh3nk95p2gg2ak777dd11pr7jx5das2g49l262scrcv83";
}; };
patches = stdenv.lib.optional enableNLS
(fetchurl {
url = "http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-arch/unzip/files/unzip-6.0-natspec.patch?revision=1.1";
name = "unzip-6.0-natspec.patch";
sha256 = "67ab260ae6adf8e7c5eda2d1d7846929b43562943ec4aff629bd7018954058b1";
});
nativeBuildInputs = [ bzip2 ]; nativeBuildInputs = [ bzip2 ];
buildInputs = [ bzip2 ] ++ stdenv.lib.optional enableNLS libnatspec; buildInputs = [ bzip2 ] ++ stdenv.lib.optional enableNLS libnatspec;
@ -24,19 +31,12 @@ stdenv.mkDerivation ({
installFlags = "prefix=$(out)"; installFlags = "prefix=$(out)";
setupHook = ./setup-hook.sh;
meta = { meta = {
homepage = http://www.info-zip.org; homepage = http://www.info-zip.org;
description = "An extraction utility for archives compressed in .zip format"; description = "An extraction utility for archives compressed in .zip format";
license = "free"; # http://www.info-zip.org/license.html license = "free"; # http://www.info-zip.org/license.html
platforms = stdenv.lib.platforms.all; platforms = stdenv.lib.platforms.all;
}; };
} // (if enableNLS then { }
patches =
[ ( fetchurl {
url =
"http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-arch/unzip/files/unzip-6.0-natspec.patch?revision=1.1";
name = "unzip-6.0-natspec.patch";
sha256 = "67ab260ae6adf8e7c5eda2d1d7846929b43562943ec4aff629bd7018954058b1";
})
];
} else {}))

View File

@ -0,0 +1,5 @@
unpackCmdHooks+=(_tryUnzip)
_tryUnzip() {
if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi
unzip -qq "$curSrc"
}

View File

@ -18,5 +18,5 @@ if test -z "$sgmlHookDone"; then
export ftp_proxy=http://nodtd.invalid/ export ftp_proxy=http://nodtd.invalid/
export SGML_CATALOG_FILES export SGML_CATALOG_FILES
envHooks=(${envHooks[@]} addSGMLCatalogs) envHooks+=(addSGMLCatalogs)
fi fi

View File

@ -4,4 +4,4 @@ addTeXMFPath () {
fi fi
} }
envHooks=(${envHooks[@]} addTeXMFPath) envHooks+=(addTeXMFPath)

View File

@ -4,4 +4,4 @@ addTeXMFPath () {
fi fi
} }
envHooks=(${envHooks[@]} addTeXMFPath) envHooks+=(addTeXMFPath)

View File

@ -205,7 +205,7 @@ let
allStdenvs = import ../stdenv { allStdenvs = import ../stdenv {
inherit system platform config; inherit system platform config lib;
allPackages = args: import ./all-packages.nix ({ inherit config system; } // args); allPackages = args: import ./all-packages.nix ({ inherit config system; } // args);
}; };