Merge branch 'master' into gcc-7

This commit is contained in:
Vladimír Čunát
2017-09-25 12:37:31 +02:00
5008 changed files with 102396 additions and 69296 deletions
+8 -24
View File
@@ -59,29 +59,23 @@ rec {
makeStdenvCross = { stdenv
, cc
, buildPlatform, hostPlatform, targetPlatform
, # Prior overrides are surely not valid as packages built
# with this run on a different platform, so disable by
# default.
overrides ? _: _: {}
} @ overrideArgs: let
stdenv = overrideArgs.stdenv.override {
inherit
buildPlatform hostPlatform targetPlatform
cc;
cc overrides;
allowedRequisites = null;
# Overrides are surely not valid as packages built with this run on a
# different platform.
overrides = _: _: {};
extraBuildInputs = [ ]; # Old ones run on wrong platform
};
in stdenv // {
mkDerivation =
{ name ? "", buildInputs ? [], nativeBuildInputs ? []
{ buildInputs ? [], nativeBuildInputs ? []
, propagatedBuildInputs ? [], propagatedNativeBuildInputs ? []
, # Disabling the tests by default when cross compiling, as usually the
# tests rely on being able to run produced binaries.
doCheck ? false
, configureFlags ? []
, # Target is not included by default because most programs don't care.
# Including it then would cause needless massive rebuilds.
configurePlatforms ? args.crossAttrs.configurePlatforms or [ "build" "host" ]
, selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false
, ...
} @ args:
@@ -106,25 +100,15 @@ rec {
nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
in
stdenv.mkDerivation (args // {
name = name + "-" + hostPlatform.config;
nativeBuildInputs = nativeBuildInputs
++ nativeInputsFromBuildInputs
++ stdenv.lib.optional selfNativeBuildInput nativeDrv
# without proper `file` command, libtool sometimes fails
# to recognize 64-bit DLLs
++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file
++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
++ stdenv.lib.optional hostPlatform.isAarch64 pkgs.updateAutotoolsGnuConfigScriptsHook
;
inherit doCheck;
# This parameter is sometimes a string and sometimes a list, yuck
configureFlags = let inherit (stdenv.lib) optional elem; in
(if stdenv.lib.isString configureFlags then [configureFlags] else configureFlags)
++ optional (elem "build" configurePlatforms) "--build=${buildPlatform.config}"
++ optional (elem "host" configurePlatforms) "--host=${hostPlatform.config}"
++ optional (elem "target" configurePlatforms) "--target=${targetPlatform.config}";
# Cross-linking dynamic libraries, every buildInput should
# be propagated because ld needs the -rpath-link to find
# any library needed to link the program dynamically at
+1 -1
View File
@@ -35,7 +35,7 @@ in bootStages ++ [
targetPlatform = crossSystem;
cc = if crossSystem.useiOSCross or false
then buildPackages.darwin.ios-cross
else buildPackages.gccCrossStageFinal;
else buildPackages.gcc;
};
})
@@ -0,0 +1,15 @@
With format string strictness, High Sierra also enforces that %n isn't used
in dynamic format strings, but we should just disable its use on darwin in
general.
--- a/lib/vasnprintf.c 2017-06-22 15:19:15.000000000 -0700
+++ b/lib/vasnprintf.c 2017-06-22 15:20:20.000000000 -0700
@@ -4869,7 +4869,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *
#endif
*fbp = dp->conversion;
#if USE_SNPRINTF
-# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+# if !defined(__APPLE__) && !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
fbp[1] = '%';
fbp[2] = 'n';
fbp[3] = '\0';
+114 -87
View File
@@ -4,15 +4,15 @@
# Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools
, bootstrapFiles ? let
fetch = { file, sha256, executable ? true }: import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/c4effbe806be9a0a3727fdbbc9a5e28149347532/${file}";
url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/10cbca5b30c6cb421ce15139f32ae3a4977292cf/${file}";
inherit (localSystem) system;
inherit sha256 executable;
}; in {
sh = fetch { file = "sh"; sha256 = "1b9r3dksj907bpxp589yhc4217cas73vni8sng4r57f04ydjcinr"; };
bzip2 = fetch { file = "bzip2"; sha256 = "1wm28jgap4cbr8hf4ambg6h9flr2b4mcbh7fw20i0l51v6n8igky"; };
mkdir = fetch { file = "mkdir"; sha256 = "0jc32mzx2whhx2xh70grvvgz4jj26118p9yxmhjqcysagc0k7y66"; };
cpio = fetch { file = "cpio"; sha256 = "0x5dcczkzn0g8yb4pah449jmgy3nmpzrqy4s480grcx05b6v6hkp"; };
tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "0ifdc8bwxdhmpbhx2vd3lwjg71gqm6pi5mfm0fkcsbqavl8hd8hz"; executable = false; };
sh = fetch { file = "sh"; sha256 = "0s8a9vpzj6vadq4jmf4r8cargwnsf327hdjydxgqsfxb8y1q39w3"; };
bzip2 = fetch { file = "bzip2"; sha256 = "1jqljpjr8mkiv7g5rl5impqx3all8vn1mxxdwa004pr3h48c1zgg"; };
mkdir = fetch { file = "mkdir"; sha256 = "17zsjiwnq07i5r85q1hg7f6cnkcgllwy2amz9klaqwjy4vzz4vwh"; };
cpio = fetch { file = "cpio"; sha256 = "04hrair58dgja6syh442pswiga5an9nl58ls57yknkn2pq51nx9m"; };
tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "103833hrci0vwi1gi978hkp69rncicvpdszn87ffpf1cq0jzpa14"; executable = false; };
}
}:
@@ -50,6 +50,8 @@ in rec {
args = [ ./unpack-bootstrap-tools.sh ];
inherit (bootstrapFiles) mkdir bzip2 cpio tarball;
reexportedLibrariesFile =
../../os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries;
__sandboxProfile = binShClosure + libSystemProfile;
};
@@ -57,11 +59,12 @@ in rec {
stageFun = step: last: {shell ? "${bootstrapTools}/bin/bash",
overrides ? (self: super: {}),
extraPreHook ? "",
extraNativeBuildInputs,
extraBuildInputs,
allowedRequisites ? null}:
let
thisStdenv = import ../generic {
inherit config shell extraBuildInputs;
inherit config shell extraNativeBuildInputs extraBuildInputs;
allowedRequisites = if allowedRequisites == null then null else allowedRequisites ++ [
thisStdenv.cc.expand-response-params
];
@@ -75,19 +78,18 @@ in rec {
cc = if isNull last then "/dev/null" else import ../../build-support/cc-wrapper {
inherit shell;
inherit (last) stdenv;
inherit (last.pkgs.darwin) dyld;
nativeTools = true;
nativePrefix = bootstrapTools;
nativeTools = false;
nativeLibc = false;
buildPackages = lib.optionalAttrs (last ? stdenv) {
inherit (last) stdenv;
};
hostPlatform = localSystem;
targetPlatform = localSystem;
libc = last.pkgs.darwin.Libsystem;
isClang = true;
cc = { name = "clang-9.9.9"; outPath = bootstrapTools; };
cc = { name = "clang-9.9.9"; outPath = bootstrapTools; };
binutils = { name = "binutils-9.9.9"; outPath = bootstrapTools; };
coreutils = { name = "coreutils-9.9.9"; outPath = bootstrapTools; };
gnugrep = { name = "gnugrep-9.9.9"; outPath = bootstrapTools; };
};
preHook = stage0.stdenv.lib.optionalString (shell == "${bootstrapTools}/bin/bash") ''
@@ -109,7 +111,13 @@ in rec {
stdenvSandboxProfile = binShClosure + libSystemProfile;
extraSandboxProfile = binShClosure + libSystemProfile;
extraAttrs = { inherit platform; parent = last; };
extraAttrs = {
inherit platform;
parent = last;
# This is used all over the place so I figured I'd just leave it here for now
secure-format-patch = ./darwin-secure-format.patch;
};
overrides = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; };
};
@@ -154,71 +162,75 @@ in rec {
};
extraNativeBuildInputs = [];
extraBuildInputs = [];
};
persistent0 = _: _: _: {};
stage1 = prevStage: with prevStage; stageFun 1 prevStage {
stage1 = prevStage: let
persistent = _: _: {};
in with prevStage; stageFun 1 prevStage {
extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
extraNativeBuildInputs = [];
extraBuildInputs = [ pkgs.libcxx ];
allowedRequisites =
[ bootstrapTools ] ++ (with pkgs; [ libcxx libcxxabi ]) ++ [ pkgs.darwin.Libsystem ];
overrides = persistent0 prevStage;
overrides = persistent;
};
persistent1 = prevStage: self: super: with prevStage; {
inherit
zlib patchutils m4 scons flex perl bison unifdef unzip openssl python
libxml2 gettext sharutils gmp libarchive ncurses pkg-config libedit groff
openssh sqlite sed serf openldap db cyrus-sasl expat apr-util subversion xz
findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils;
stage2 = prevStage: let
persistent = self: super: with prevStage; {
inherit
zlib patchutils m4 scons flex perl bison unifdef unzip openssl python
libxml2 gettext sharutils gmp libarchive ncurses pkg-config libedit groff
openssh sqlite sed serf openldap db cyrus-sasl expat apr-util subversion xz
findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils;
darwin = super.darwin // {
inherit (darwin)
dyld Libsystem xnu configd ICU libdispatch libclosure launchd;
darwin = super.darwin // {
inherit (darwin)
dyld Libsystem xnu configd ICU libdispatch libclosure launchd;
};
};
};
stage2 = prevStage: with prevStage; stageFun 2 prevStage {
in with prevStage; stageFun 2 prevStage {
extraPreHook = ''
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';
extraBuildInputs = with pkgs; [ xz darwin.CF libcxx ];
extraNativeBuildInputs = [ pkgs.xz ];
extraBuildInputs = with pkgs; [ darwin.CF libcxx ];
allowedRequisites =
[ bootstrapTools ] ++
(with pkgs; [ xz.bin xz.out libcxx libcxxabi ]) ++
(with pkgs.darwin; [ dyld Libsystem CF ICU locale ]);
overrides = persistent1 prevStage;
overrides = persistent;
};
persistent2 = prevStage: self: super: with prevStage; {
inherit
patchutils m4 scons flex perl bison unifdef unzip openssl python
gettext sharutils libarchive pkg-config groff bash subversion
openssh sqlite sed serf openldap db cyrus-sasl expat apr-util
findfreetype libssh curl cmake autoconf automake libtool cpio
libcxx libcxxabi;
stage3 = prevStage: let
persistent = self: super: with prevStage; {
inherit
patchutils m4 scons flex perl bison unifdef unzip openssl python
gettext sharutils libarchive pkg-config groff bash subversion
openssh sqlite sed serf openldap db cyrus-sasl expat apr-util
findfreetype libssh curl cmake autoconf automake libtool cpio
libcxx libcxxabi;
darwin = super.darwin // {
inherit (darwin)
dyld Libsystem xnu configd libdispatch libclosure launchd libiconv locale;
darwin = super.darwin // {
inherit (darwin)
dyld Libsystem xnu configd libdispatch libclosure launchd libiconv locale;
};
};
};
stage3 = prevStage: with prevStage; stageFun 3 prevStage {
in with prevStage; stageFun 3 prevStage {
shell = "${pkgs.bash}/bin/bash";
# We have a valid shell here (this one has no bootstrap-tools runtime deps) so stageFun
# enables patchShebangs above. Unfortunately, patchShebangs ignores our $SHELL setting
# and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
# patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
extraBuildInputs = with pkgs; [ xz darwin.CF libcxx pkgs.bash ];
extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
extraBuildInputs = with pkgs; [ darwin.CF libcxx ];
extraPreHook = ''
export PATH=${pkgs.bash}/bin:$PATH
@@ -230,54 +242,67 @@ in rec {
(with pkgs; [ xz.bin xz.out bash libcxx libcxxabi ]) ++
(with pkgs.darwin; [ dyld ICU Libsystem locale ]);
overrides = persistent2 prevStage;
overrides = persistent;
};
persistent3 = prevStage: self: super: with prevStage; {
inherit
gnumake gzip gnused bzip2 gawk ed xz patch bash
libcxxabi libcxx ncurses libffi zlib gmp pcre gnugrep
coreutils findutils diffutils patchutils;
stage4 = prevStage: let
persistent = self: super: with prevStage; {
inherit
gnumake gzip gnused bzip2 gawk ed xz patch bash
libcxxabi libcxx ncurses libffi zlib gmp pcre gnugrep
coreutils findutils diffutils patchutils;
llvmPackages = let llvmOverride = llvmPackages.llvm.override { inherit libcxxabi; };
in super.llvmPackages // {
llvm = llvmOverride;
clang-unwrapped = llvmPackages.clang-unwrapped.override { llvm = llvmOverride; };
};
llvmPackages = let llvmOverride = llvmPackages.llvm.override { inherit libcxxabi; };
in super.llvmPackages // {
llvm = llvmOverride;
clang-unwrapped = llvmPackages.clang-unwrapped.override { llvm = llvmOverride; };
};
darwin = super.darwin // {
inherit (darwin) dyld Libsystem libiconv locale;
darwin = super.darwin // {
inherit (darwin) dyld Libsystem libiconv locale;
};
};
};
stage4 = prevStage: with prevStage; stageFun 4 prevStage {
in with prevStage; stageFun 4 prevStage {
shell = "${pkgs.bash}/bin/bash";
extraBuildInputs = with pkgs; [ xz darwin.CF libcxx pkgs.bash ];
extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
extraBuildInputs = with pkgs; [ darwin.CF libcxx ];
extraPreHook = ''
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';
overrides = persistent3 prevStage;
overrides = self: super: (persistent self super) // {
# Hack to make sure we don't link ncurses in bootstrap tools. The proper
# solution is to avoid passing -L/nix-store/...-bootstrap-tools/lib,
# quite a sledgehammer just to get the C runtime.
gettext = super.gettext.overrideAttrs (old: {
configureFlags = old.configureFlags ++ [
"--disable-curses"
];
});
};
};
persistent4 = prevStage: self: super: with prevStage; {
inherit
gnumake gzip gnused bzip2 gawk ed xz patch bash
libcxxabi libcxx ncurses libffi zlib llvm gmp pcre gnugrep
coreutils findutils diffutils patchutils;
stdenvDarwin = prevStage: let
pkgs = prevStage;
persistent = self: super: with prevStage; {
inherit
gnumake gzip gnused bzip2 gawk ed xz patch bash
libcxxabi libcxx ncurses libffi zlib llvm gmp pcre gnugrep
coreutils findutils diffutils patchutils;
llvmPackages = super.llvmPackages // {
inherit (llvmPackages) llvm clang-unwrapped;
llvmPackages = super.llvmPackages // {
inherit (llvmPackages) llvm clang-unwrapped;
};
darwin = super.darwin // {
inherit (darwin) dyld ICU Libsystem libiconv;
} // lib.optionalAttrs (super.targetPlatform == localSystem) {
inherit (darwin) cctools;
};
} // lib.optionalAttrs (super.targetPlatform == localSystem) {
# Need to get rid of these when cross-compiling.
inherit binutils binutils-raw;
};
darwin = super.darwin // {
inherit (darwin) dyld ICU Libsystem cctools libiconv;
};
} // lib.optionalAttrs (super.targetPlatform == localSystem) {
# Need to get rid of these when cross-compiling.
inherit binutils binutils-raw;
};
stdenvDarwin = prevStage: let pkgs = prevStage; in import ../generic rec {
in import ../generic rec {
inherit config;
inherit (pkgs.stdenv) fetchurlBoot;
@@ -288,6 +313,7 @@ in rec {
targetPlatform = localSystem;
preHook = commonPreHook + ''
export NIX_COREFOUNDATION_RPATH=${pkgs.darwin.CF}/Library/Frameworks
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';
@@ -297,7 +323,7 @@ in rec {
initialPath = import ../common-path.nix { inherit pkgs; };
shell = "${pkgs.bash}/bin/bash";
cc = import ../../build-support/cc-wrapper {
cc = lib.callPackageWith {} ../../build-support/cc-wrapper {
inherit (pkgs) stdenv;
inherit shell;
nativeTools = false;
@@ -305,20 +331,21 @@ in rec {
buildPackages = {
inherit (prevStage) stdenv;
};
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit (pkgs) coreutils binutils gnugrep;
inherit (pkgs.darwin) dyld;
cc = pkgs.llvmPackages.clang-unwrapped;
libc = pkgs.darwin.Libsystem;
};
extraNativeBuildInputs = [];
extraBuildInputs = with pkgs; [ darwin.CF libcxx ];
extraAttrs = {
inherit platform bootstrapTools;
libc = pkgs.darwin.Libsystem;
shellPackage = pkgs.bash;
# This is used all over the place so I figured I'd just leave it here for now
secure-format-patch = ./darwin-secure-format.patch;
};
allowedRequisites = (with pkgs; [
@@ -333,9 +360,9 @@ in rec {
]);
overrides = self: super:
let persistent = persistent4 prevStage self super; in persistent // {
let persistent' = persistent self super; in persistent' // {
clang = cc;
llvmPackages = persistent.llvmPackages // { clang = cc; };
llvmPackages = persistent'.llvmPackages // { clang = cc; };
inherit cc;
};
};
+1 -1
View File
@@ -26,7 +26,7 @@ install_name_tool \
$out/lib/system/libsystem_kernel.dylib
# TODO: this logic basically duplicates similar logic in the Libsystem expression. Deduplicate them!
libs=$(otool -arch x86_64 -L /usr/lib/libSystem.dylib | tail -n +3 | awk '{ print $1 }')
libs=$(cat $reexportedLibrariesFile | grep -v '^#')
for i in $libs; do
if [ "$i" != "/usr/lib/system/libsystem_kernel.dylib" ] && [ "$i" != "/usr/lib/system/libsystem_c.dylib" ]; then
+4 -10
View File
@@ -40,8 +40,6 @@ let inherit (localSystem) system; in
targetPlatform = localSystem;
inherit config;
initialPath = [ "/" "/usr" ];
hostPlatform = localSystem;
targetPlatform = localSystem;
shell = "${bootstrapTools}/bin/bash";
fetchurlBoot = null;
cc = null;
@@ -55,13 +53,11 @@ let inherit (localSystem) system; in
stdenv = import ../generic {
name = "stdenv-freebsd-boot-0";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
initialPath = [ prevStage.bootstrapTools ];
inherit (prevStage.stdenv)
hostPlatform targetPlatform shell;
buildPlatform hostPlatform targetPlatform
shell;
fetchurlBoot = prevStage.fetchurl;
cc = null;
};
@@ -71,13 +67,11 @@ let inherit (localSystem) system; in
inherit config overlays;
stdenv = import ../generic {
name = "stdenv-freebsd-boot-3";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
inherit (prevStage.stdenv)
hostPlatform targetPlatform initialPath shell fetchurlBoot;
buildPlatform hostPlatform targetPlatform
initialPath shell fetchurlBoot;
cc = import ../../build-support/cc-wrapper {
nativeTools = true;
+4 -1
View File
@@ -9,10 +9,13 @@ mkdir $out
echo "export SHELL=$shell" > $out/setup
echo "initialPath=\"$initialPath\"" >> $out/setup
echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" >> $out/setup
echo "defaultBuildInputs=\"$defaultBuildInputs\"" >> $out/setup
echo "$preHook" >> $out/setup
cat "$setup" >> $out/setup
# Allow the user to install stdenv using nix-env and get the packages
# in stdenv.
mkdir $out/nix-support
echo $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages
if [ "$propagatedUserEnvPkgs" ]; then
printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages
fi
+3 -1
View File
@@ -40,6 +40,8 @@ let
allowBroken = config.allowBroken or false || builtins.getEnv "NIXPKGS_ALLOW_BROKEN" == "1";
allowUnsupportedSystem = config.allowUnsupportedSystem or false;
isUnfree = licenses: lib.lists.any (l:
!l.free or true || l == "unfree" || l == "unfree-redistributable") licenses;
@@ -177,7 +179,7 @@ let
{ valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (${showLicense attrs.meta.license})"; }
else if !allowBroken && attrs.meta.broken or false then
{ valid = false; reason = "broken"; errormsg = "is marked as broken"; }
else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
{ valid = false; reason = "broken"; errormsg = "is not supported on ${system}"; }
else if !(hasAllowedInsecure attrs) then
{ valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
+14 -8
View File
@@ -9,6 +9,7 @@ let lib = import ../../../lib; in lib.makeOverridable (
, setupScript ? ./setup.sh
, extraNativeBuildInputs ? []
, extraBuildInputs ? []
, __stdenvImpureHostDeps ? []
, __extraImpureHostDeps ? []
@@ -41,7 +42,7 @@ let lib = import ../../../lib; in lib.makeOverridable (
}:
let
defaultNativeBuildInputs = extraBuildInputs ++
defaultNativeBuildInputs = extraNativeBuildInputs ++
[ ../../build-support/setup-hooks/move-docs.sh
../../build-support/setup-hooks/compress-man-pages.sh
../../build-support/setup-hooks/strip.sh
@@ -58,11 +59,16 @@ let
cc
];
defaultBuildInputs = extraBuildInputs;
# The stdenv that we are producing.
stdenv =
derivation (
(if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) //
{
lib.optionalAttrs (allowedRequisites != null) {
allowedRequisites = allowedRequisites
++ defaultNativeBuildInputs ++ defaultBuildInputs;
}
// {
inherit name;
# Nix itself uses the `system` field of a derivation to decide where to
@@ -75,7 +81,8 @@ let
setup = setupScript;
inherit preHook initialPath shell defaultNativeBuildInputs;
inherit preHook initialPath shell
defaultNativeBuildInputs defaultBuildInputs;
}
// lib.optionalAttrs buildPlatform.isDarwin {
__sandboxProfile = stdenvSandboxProfile;
@@ -91,14 +98,13 @@ let
inherit buildPlatform hostPlatform targetPlatform;
inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile;
inherit extraNativeBuildInputs extraBuildInputs
__extraImpureHostDeps extraSandboxProfile;
# Utility flags to test the type of platform.
inherit (hostPlatform)
isDarwin isLinux isSunOS isHurd isCygwin isFreeBSD isOpenBSD
isi686 isx86_64 is64bit isMips isBigEndian;
isArm = hostPlatform.isArm32;
isAarch64 = hostPlatform.isArm64;
isi686 isx86_64 is64bit isArm isAarch64 isMips isBigEndian;
# Whether we should run paxctl to pax-mark binaries.
needsPax = isLinux;
+58 -22
View File
@@ -12,12 +12,22 @@ rec {
# * https://nixos.org/nix/manual/#ssec-derivation
# Explanation about derivations in general
mkDerivation =
{ nativeBuildInputs ? []
{ name ? ""
, nativeBuildInputs ? []
, buildInputs ? []
, propagatedNativeBuildInputs ? []
, propagatedBuildInputs ? []
, configureFlags ? []
, # Target is not included by default because most programs don't care.
# Including it then would cause needless mass rebuilds.
#
# TODO(@Ericson2314): Make [ "build" "host" ] always the default.
configurePlatforms ? lib.optionals
(stdenv.hostPlatform != stdenv.buildPlatform)
[ "build" "host" ]
, crossConfig ? null
, meta ? {}
, passthru ? {}
@@ -31,31 +41,36 @@ rec {
, __propagatedImpureHostDeps ? []
, sandboxProfile ? ""
, propagatedSandboxProfile ? ""
, hardeningEnable ? []
, hardeningDisable ? []
, ... } @ attrs:
# TODO(@Ericson2314): Make this more modular, and not O(n^2).
let
dependencies = [
(map (drv: drv.nativeDrv or drv) nativeBuildInputs)
supportedHardeningFlags = [ "fortify" "stackprotector" "pie" "pic" "strictoverflow" "format" "relro" "bindnow" ];
# hardeningDisable additionally supports "all".
erroneousHardeningFlags = lib.subtractLists supportedHardeningFlags (hardeningEnable ++ lib.remove "all" hardeningDisable);
in if builtins.length erroneousHardeningFlags != 0
then abort ("mkDerivation was called with unsupported hardening flags: " + lib.generators.toPretty {} {
inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags;
})
else let
dependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) nativeBuildInputs
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh)
(map (drv: drv.crossDrv or drv) buildInputs)
];
propagatedDependencies = [
propagatedDependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs)
(map (drv: drv.crossDrv or drv) propagatedBuildInputs)
];
in let
outputs' =
outputs ++
(if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []);
dependencies' = let
justMap = map lib.chooseDevOutputs dependencies;
nativeBuildInputs = lib.head justMap
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh;
in [ nativeBuildInputs ] ++ lib.tail justMap;
propagatedDependencies' = map lib.chooseDevOutputs propagatedDependencies;
derivationArg =
(removeAttrs attrs
["meta" "passthru" "crossAttrs" "pos"
@@ -63,15 +78,26 @@ rec {
"sandboxProfile" "propagatedSandboxProfile"])
// (let
computedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or []) (stdenv.extraBuildInputs ++ lib.concatLists dependencies');
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies);
computedPropagatedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or []) (lib.concatLists propagatedDependencies');
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(lib.concatLists propagatedDependencies);
computedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (stdenv.extraBuildInputs ++ lib.concatLists dependencies'));
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
++ lib.concatLists dependencies));
computedPropagatedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists propagatedDependencies'));
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(lib.concatLists propagatedDependencies));
in
{
name = name + lib.optionalString
(stdenv.hostPlatform != stdenv.buildPlatform)
("-" + stdenv.hostPlatform.config);
builder = attrs.realBuilder or stdenv.shell;
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
inherit stdenv;
@@ -79,11 +105,21 @@ rec {
userHook = config.stdenv.userHook or null;
__ignoreNulls = true;
nativeBuildInputs = lib.elemAt dependencies' 0;
buildInputs = lib.elemAt dependencies' 1;
nativeBuildInputs = lib.elemAt dependencies 0;
buildInputs = lib.elemAt dependencies 1;
propagatedNativeBuildInputs = lib.elemAt propagatedDependencies 0;
propagatedBuildInputs = lib.elemAt propagatedDependencies 1;
# This parameter is sometimes a string, sometimes null, and sometimes a list, yuck
configureFlags = let inherit (lib) optional elem; in
(/**/ if lib.isString configureFlags then [configureFlags]
else if configureFlags == null then []
else configureFlags)
++ optional (elem "build" configurePlatforms) "--build=${stdenv.buildPlatform.config}"
++ optional (elem "host" configurePlatforms) "--host=${stdenv.hostPlatform.config}"
++ optional (elem "target" configurePlatforms) "--target=${stdenv.targetPlatform.config}";
propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0;
propagatedBuildInputs = lib.elemAt propagatedDependencies' 1;
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) {
# TODO: remove lib.unique once nix has a list canonicalization primitive
__sandboxProfile =
+340 -222
View File
@@ -1,4 +1,4 @@
set -e
set -eu
set -o pipefail
: ${outputs:=out}
@@ -13,15 +13,22 @@ set -o pipefail
# code). The hooks for <hookName> are the shell function or variable
# <hookName>, and the values of the shell array <hookName>Hooks.
runHook() {
local oldOpts="$(shopt -po nounset)"
set -u # May be called from elsewhere, so do `set -u`.
local hookName="$1"
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local hooksSlice="${hookName%Hook}Hooks[@]"
local hook
for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do
# Hack around old bash being bad and thinking empty arrays are
# undefined.
for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
_eval "$hook" "$@"
set -u # To balance `_eval`
done
eval "${oldOpts}"
return 0
}
@@ -29,18 +36,25 @@ runHook() {
# 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 oldOpts="$(shopt -po nounset)"
set -u # May be called from elsewhere, so do `set -u`.
local hookName="$1"
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local hook
for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do
local hooksSlice="${hookName%Hook}Hooks[@]"
local hook ret=1
# Hack around old bash like above
for hook in "_callImplicitHook 1 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
if _eval "$hook" "$@"; then
return 0
ret=0
break
fi
set -u # To balance `_eval`
done
return 1
eval "${oldOpts}"
return "$ret"
}
@@ -50,56 +64,62 @@ runOneHook() {
# environment variables) and from shell scripts (as functions). If you
# want to allow multiple hooks, use runHook instead.
_callImplicitHook() {
set -u
local def="$1"
local hookName="$2"
case "$(type -t $hookName)" in
(function|alias|builtin) $hookName;;
(file) source $hookName;;
case "$(type -t "$hookName")" in
(function|alias|builtin)
set +u
"$hookName";;
(file)
set +u
source "$hookName";;
(keyword) :;;
(*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
(*) if [ -z "${!hookName:-}" ]; then
return "$def";
else
set +u
eval "${!hookName}"
fi;;
esac
# `_eval` expects hook to need nounset disable and leave it
# disabled anyways, so Ok to to delegate. The alternative of a
# return trap is no good because it would affect nested returns.
}
# A function wrapper around eval that ensures that return inside
# hooks exits the hook, not the caller.
# hooks exits the hook, not the caller. Also will only pass args if
# command can take them
_eval() {
local code="$1"
shift
if [ "$(type -t $code)" = function ]; then
eval "$code \"\$@\""
if [ "$(type -t "$1")" = function ]; then
set +u
"$@" # including args
else
eval "$code"
set +u
eval "$1"
fi
# `run*Hook` reenables `set -u`
}
######################################################################
# Logging.
nestingLevel=0
# Obsolete.
stopNest() { true; }
header() { echo "$1"; }
closeNest() { true; }
startNest() {
nestingLevel=$(($nestingLevel + 1))
echo -en "\033[$1p"
}
stopNest() {
nestingLevel=$(($nestingLevel - 1))
echo -en "\033[q"
}
header() {
startNest "$2"
echo "$1"
}
# Make sure that even when we exit abnormally, the original nesting
# level is properly restored.
closeNest() {
while [ $nestingLevel -gt 0 ]; do
stopNest
done
# Prints a command such that all word splits are unambiguous. We need
# to split the command in three parts because the middle format string
# will be, and must be, repeated for each argument. The first argument
# goes before the ':' and is just for convenience.
echoCmd() {
printf "%s:" "$1"
shift
printf ' %q' "$@"
echo
}
@@ -107,12 +127,10 @@ closeNest() {
# Error handling.
exitHandler() {
exitCode=$?
exitCode="$?"
set +e
closeNest
if [ -n "$showBuildStats" ]; then
if [ -n "${showBuildStats:-}" ]; then
times > "$NIX_BUILD_TOP/.times"
local -a times=($(cat "$NIX_BUILD_TOP/.times"))
# Print the following statistics:
@@ -120,20 +138,20 @@ exitHandler() {
# - system time for the shell
# - user time for all child processes
# - system time for all child processes
echo "build time elapsed: " ${times[*]}
echo "build time elapsed: " "${times[@]}"
fi
if [ $exitCode != 0 ]; then
if (( "$exitCode" != 0 )); then
runHook failureHook
# If the builder had a non-zero exit code and
# $succeedOnFailure is set, create the file
# $out/nix-support/failed to signal failure, and exit
# normally. Otherwise, return the original exit code.
if [ -n "$succeedOnFailure" ]; then
if [ -n "${succeedOnFailure:-}" ]; then
echo "build failed with exit code $exitCode (ignored)"
mkdir -p "$out/nix-support"
printf "%s" $exitCode > "$out/nix-support/failed"
printf "%s" "$exitCode" > "$out/nix-support/failed"
exit 0
fi
@@ -141,7 +159,7 @@ exitHandler() {
runHook exitHook
fi
exit $exitCode
exit "$exitCode"
}
trap "exitHandler" EXIT
@@ -152,11 +170,11 @@ trap "exitHandler" EXIT
addToSearchPathWithCustomDelimiter() {
local delimiter=$1
local varName=$2
local dir=$3
local delimiter="$1"
local varName="$2"
local dir="$3"
if [ -d "$dir" ]; then
eval export ${varName}=${!varName}${!varName:+$delimiter}${dir}
export "${varName}=${!varName:+${!varName}${delimiter}}${dir}"
fi
}
@@ -180,12 +198,12 @@ ensureDir() {
# The function is used in multiple-outputs.sh hook,
# so it is defined here but tried after the hook.
_addRpathPrefix() {
if [ "$NIX_NO_SELF_RPATH" != 1 ]; then
if [ "${NIX_NO_SELF_RPATH:-0}" != 1 ]; then
export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS"
if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then
if [ -n "${NIX_LIB64_IN_SELF_RPATH:-}" ]; then
export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS"
fi
if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then
if [ -n "${NIX_LIB32_IN_SELF_RPATH:-}" ]; then
export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS"
fi
fi
@@ -197,7 +215,7 @@ isELF() {
local fd
local magic
exec {fd}< "$fn"
read -n 4 -u $fd magic
read -r -n 4 -u "$fd" magic
exec {fd}<&-
if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
}
@@ -210,11 +228,21 @@ isScript() {
local magic
if ! [ -x /bin/sh ]; then return 0; fi
exec {fd}< "$fn"
read -n 2 -u $fd magic
read -r -n 2 -u "$fd" magic
exec {fd}<&-
if [[ "$magic" =~ \#! ]]; then return 0; else return 1; fi
}
# printf unfortunately will print a trailing newline regardless
printLines() {
[[ "$#" -gt 0 ]] || return 0
printf '%s\n' "$@"
}
printWords() {
[[ "$#" -gt 0 ]] || return 0
printf '%s ' "$@"
}
######################################################################
# Initialisation.
@@ -238,16 +266,16 @@ shopt -s nullglob
PATH=
for i in $initialPath; do
if [ "$i" = / ]; then i=; fi
addToSearchPath PATH $i/bin
addToSearchPath PATH "$i/bin"
done
if [ "$NIX_DEBUG" = 1 ]; then
if [ "${NIX_DEBUG:-}" = 1 ]; then
echo "initial path: $PATH"
fi
# 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
BASH="$SHELL"
export CONFIG_SHELL="$SHELL"
@@ -258,7 +286,7 @@ paxmark() { true; }
# Execute the pre-hook.
if [ -z "$shell" ]; then export shell=$SHELL; fi
if [ -z "${shell:-}" ]; then export shell="$SHELL"; fi
runHook preHook
@@ -271,16 +299,21 @@ runHook addInputsHook
# Recursively find all build inputs.
findInputs() {
local pkg="$1"
local var=$2
local propagatedBuildInputsFile=$3
local var="$2"
local propagatedBuildInputsFile="$3"
case ${!var} in
*\ $pkg\ *)
return 0
;;
# TODO(@Ericson2314): Restore using associative array once Darwin
# nix-shell doesn't use impure bash. This should replace the O(n)
# case with an O(1) hash map lookup, assuming bash is implemented
# well :D.
local varSlice="$var[*]"
# ${..-} to hack around old bash empty array problem
case "${!varSlice-}" in
*" $pkg "*) return 0 ;;
esac
unset -v varSlice
eval $var="'${!var} $pkg '"
eval "$var"'+=("$pkg")'
if ! [ -e "$pkg" ]; then
echo "build input $pkg does not exist" >&2
@@ -288,68 +321,89 @@ findInputs() {
fi
if [ -f "$pkg" ]; then
local oldOpts="$(shopt -po nounset)"
set +u
source "$pkg"
eval "$oldOpts"
fi
if [ -d $1/bin ]; then
addToSearchPath _PATH $1/bin
if [ -d "$pkg/bin" ]; then
addToSearchPath _PATH "$pkg/bin"
fi
if [ -f "$pkg/nix-support/setup-hook" ]; then
local oldOpts="$(shopt -po nounset)"
set +u
source "$pkg/nix-support/setup-hook"
eval "$oldOpts"
fi
if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then
for i in $(cat "$pkg/nix-support/$propagatedBuildInputsFile"); do
findInputs "$i" $var $propagatedBuildInputsFile
local pkgNext
for pkgNext in $(< "$pkg/nix-support/$propagatedBuildInputsFile"); do
findInputs "$pkgNext" "$var" "$propagatedBuildInputsFile"
done
fi
}
if [ -z "$crossConfig" ]; then
declare -a nativePkgs crossPkgs
if [ -z "${crossConfig:-}" ]; then
# Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
# are handled identically to nativeBuildInputs
nativePkgs=""
for i in $nativeBuildInputs $buildInputs \
$defaultNativeBuildInputs $defaultBuildInputs \
$propagatedNativeBuildInputs $propagatedBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
for i in ${nativeBuildInputs:-} ${buildInputs:-} \
${defaultNativeBuildInputs:-} ${defaultBuildInputs:-} \
${propagatedNativeBuildInputs:-} ${propagatedBuildInputs:-}; do
findInputs "$i" nativePkgs propagated-native-build-inputs
done
else
crossPkgs=""
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs $i crossPkgs propagated-build-inputs
for i in ${buildInputs:-} ${defaultBuildInputs:-} ${propagatedBuildInputs:-}; do
findInputs "$i" crossPkgs propagated-build-inputs
done
nativePkgs=""
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
declare -a nativePkgs
for i in ${nativeBuildInputs:-} ${defaultNativeBuildInputs:-} ${propagatedNativeBuildInputs:-}; do
findInputs "$i" nativePkgs propagated-native-build-inputs
done
fi
# Set the relevant environment variables to point to the build inputs
# found above.
#
# These `depOffset`s tell the env hook what sort of dependency
# (ignoring propagatedness) is being passed to the env hook. In a real
# language, we'd append a closure with this information to the
# relevant env hook array, but bash doesn't have closures, so it's
# easier to just pass this in.
_addToNativeEnv() {
local pkg=$1
local pkg="$1"
if [[ -n "${crossConfig:-}" ]]; then
local -i depOffset=-1
else
local -i depOffset=0
fi
# Run the package-specific hooks set by the setup-hook scripts.
runHook envHook "$pkg"
}
for i in $nativePkgs; do
_addToNativeEnv $i
# Old bash empty array hack
for i in ${nativePkgs+"${nativePkgs[@]}"}; do
_addToNativeEnv "$i"
done
_addToCrossEnv() {
local pkg=$1
local pkg="$1"
local -i depOffset=0
# Run the package-specific hooks set by the setup-hook scripts.
runHook crossEnvHook "$pkg"
}
for i in $crossPkgs; do
_addToCrossEnv $i
# Old bash empty array hack
for i in ${crossPkgs+"${crossPkgs[@]}"}; do
_addToCrossEnv "$i"
done
@@ -365,17 +419,17 @@ export TZ=UTC
# Set the prefix. This is generally $out, but it can be overriden,
# for instance if we just want to perform a test build/install to a
# temporary location and write a build report to $out.
if [ -z "$prefix" ]; then
if [ -z "${prefix:-}" ]; then
prefix="$out";
fi
if [ "$useTempPrefix" = 1 ]; then
if [ "${useTempPrefix:-}" = 1 ]; then
prefix="$NIX_BUILD_TOP/tmp_prefix";
fi
PATH=$_PATH${_PATH:+:}$PATH
if [ "$NIX_DEBUG" = 1 ]; then
PATH="${_PATH-}${_PATH:+${PATH:+:}}$PATH"
if [ "${NIX_DEBUG:-}" = 1 ]; then
echo "final path: $PATH"
fi
@@ -404,7 +458,7 @@ export NIX_BUILD_CORES
# Prevent OpenSSL-based applications from using certificates in
# /etc/ssl.
# Leave it in shells for convenience.
if [ -z "$SSL_CERT_FILE" ] && [ -z "$IN_NIX_SHELL" ]; then
if [ -z "${SSL_CERT_FILE:-}" ] && [ -z "${IN_NIX_SHELL:-}" ]; then
export SSL_CERT_FILE=/no-cert-file.crt
fi
@@ -416,48 +470,51 @@ fi
substitute() {
local input="$1"
local output="$2"
shift 2
if [ ! -f "$input" ]; then
echo "substitute(): file '$input' does not exist"
echo "substitute(): ERROR: file '$input' does not exist" >&2
return 1
fi
local -a params=("$@")
local content
# read returns non-0 on EOF, so we want read to fail
if IFS='' read -r -N 0 content < "$input"; then
echo "substitute(): ERROR: File \"$input\" has null bytes, won't process" >&2
return 1
fi
local n p pattern replacement varName content
while (( "$#" )); do
case "$1" in
--replace)
pattern="$2"
replacement="$3"
shift 3
;;
# a slightly hacky way to keep newline at the end
content="$(cat "$input"; printf "%s" X)"
content="${content%X}"
--subst-var)
local varName="$2"
shift 2
# check if the used nix attribute name is a valid bash name
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
echo "substitute(): ERROR: substitution variables must be valid Bash names, \"$varName\" isn't." >&2
return 1
fi
pattern="@$varName@"
replacement="${!varName}"
;;
for ((n = 2; n < ${#params[*]}; n += 1)); do
p="${params[$n]}"
--subst-var-by)
pattern="@$2@"
replacement="$3"
shift 3
;;
if [ "$p" = --replace ]; then
pattern="${params[$((n + 1))]}"
replacement="${params[$((n + 2))]}"
n=$((n + 2))
fi
if [ "$p" = --subst-var ]; then
varName="${params[$((n + 1))]}"
n=$((n + 1))
# check if the used nix attribute name is a valid bash name
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
echo "WARNING: substitution variables should be valid bash names,"
echo " \"$varName\" isn't and therefore was skipped; it might be caused"
echo " by multi-line phases in variables - see #14907 for details."
continue
fi
pattern="@$varName@"
replacement="${!varName}"
fi
if [ "$p" = --subst-var-by ]; then
pattern="@${params[$((n + 1))]}@"
replacement="${params[$((n + 2))]}"
n=$((n + 2))
fi
*)
echo "substitute(): ERROR: Invalid command line argument: $1" >&2
return 1
;;
esac
content="${content//"$pattern"/$replacement}"
done
@@ -474,18 +531,16 @@ substituteInPlace() {
}
# Substitute all environment variables that do not start with an upper-case
# character or underscore. Note: other names that aren't bash-valid
# will cause an error during `substitute --subst-var`.
# Substitute all environment variables that start with a lowercase character and
# are valid Bash names.
substituteAll() {
local input="$1"
local output="$2"
local -a args=()
# Select all environment variables that start with a lowercase character.
for varName in $(env | sed -e $'s/^\([a-z][^= \t]*\)=.*/\\1/; t \n d'); do
if [ "$NIX_DEBUG" = "1" ]; then
echo "@${varName}@ -> '${!varName}'"
for varName in $(awk 'BEGIN { for (v in ENVIRON) if (v ~ /^[a-z][a-zA-Z0-9_]*$/) print v }'); do
if [ "${NIX_DEBUG:-}" = "1" ]; then
printf "@%s@ -> %q\n" "${varName}" "${!varName}"
fi
args+=("--subst-var" "$varName")
done
@@ -511,7 +566,7 @@ substituteAllInPlace() {
# then go to the build directory and source in `env-vars' to reproduce
# the environment used for building.
dumpVars() {
if [ "$noDumpEnvVars" != 1 ]; then
if [ "${noDumpEnvVars:-0}" != 1 ]; then
export > "$NIX_BUILD_TOP/env-vars" || true
fi
}
@@ -520,7 +575,9 @@ dumpVars() {
# Utility function: echo the base name of the given path, with the
# prefix `HASH-' removed, if present.
stripHash() {
local strippedName="$(basename "$1")";
local strippedName
# On separate line for `set -e`
strippedName="$(basename "$1")"
if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
echo "$strippedName" | cut -c34-
else
@@ -568,15 +625,15 @@ unpackFile() {
echo "do not know how to unpack source archive $curSrc"
exit 1
fi
stopNest
}
unpackPhase() {
runHook preUnpack
if [ -z "$srcs" ]; then
if [ -z "$src" ]; then
if [ -z "${srcs:-}" ]; then
if [ -z "${src:-}" ]; then
# shellcheck disable=SC2016
echo 'variable $src or $srcs should point to the source'
exit 1
fi
@@ -596,14 +653,17 @@ unpackPhase() {
# Unpack all source archives.
for i in $srcs; do
unpackFile $i
unpackFile "$i"
done
# Find the source directory.
if [ -n "$setSourceRoot" ]; then
# set to empty if unset
: ${sourceRoot=}
if [ -n "${setSourceRoot:-}" ]; then
runOneHook setSourceRoot
elif [ -z "$sourceRoot" ]; then
sourceRoot=
for i in *; do
if [ -d "$i" ]; then
case $dirsBefore in
@@ -631,7 +691,7 @@ unpackPhase() {
# By default, add write permission to the sources. This is often
# necessary when sources have been copied from other store
# locations.
if [ "$dontMakeSourcesWritable" != 1 ]; then
if [ "${dontMakeSourcesWritable:-0}" != 1 ]; then
chmod -R u+w "$sourceRoot"
fi
@@ -642,7 +702,7 @@ unpackPhase() {
patchPhase() {
runHook prePatch
for i in $patches; do
for i in ${patches:-}; do
header "applying patch $i" 3
local uncompress=cat
case "$i" in
@@ -660,8 +720,8 @@ patchPhase() {
;;
esac
# "2>&1" is a hack to make patch fail if the decompressor fails (nonexistent patch, etc.)
# shellcheck disable=SC2086
$uncompress < "$i" 2>&1 | patch ${patchFlags:--p1}
stopNest
done
runHook postPatch
@@ -676,38 +736,50 @@ fixLibtool() {
configurePhase() {
runHook preConfigure
if [ -z "$configureScript" -a -x ./configure ]; then
# set to empty if unset
: ${configureScript=}
: ${configureFlags=}
if [[ -z "$configureScript" && -x ./configure ]]; then
configureScript=./configure
fi
if [ -z "$dontFixLibtool" ]; then
find . -iname "ltmain.sh" | while read i; do
if [ -z "${dontFixLibtool:-}" ]; then
local i
find . -iname "ltmain.sh" -print0 | while IFS='' read -r -d '' i; do
echo "fixing libtool script $i"
fixLibtool $i
fixLibtool "$i"
done
fi
if [ -z "$dontAddPrefix" -a -n "$prefix" ]; then
if [[ -z "${dontAddPrefix:-}" && -n "$prefix" ]]; then
configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
fi
# Add --disable-dependency-tracking to speed up some builds.
if [ -z "$dontAddDisableDepTrack" ]; then
if [ -z "${dontAddDisableDepTrack:-}" ]; then
if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then
configureFlags="--disable-dependency-tracking $configureFlags"
fi
fi
# By default, disable static builds.
if [ -z "$dontDisableStatic" ]; then
if [ -z "${dontDisableStatic:-}" ]; then
if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then
configureFlags="--disable-static $configureFlags"
fi
fi
if [ -n "$configureScript" ]; then
echo "configure flags: $configureFlags ${configureFlagsArray[@]}"
$configureScript $configureFlags "${configureFlagsArray[@]}"
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
$configureFlags ${configureFlagsArray+"${configureFlagsArray[@]}"}
)
echoCmd 'configure flags' "${flagsArray[@]}"
# shellcheck disable=SC2086
$configureScript "${flagsArray[@]}"
unset flagsArray
else
echo "no configure script, doing nothing"
fi
@@ -719,17 +791,26 @@ configurePhase() {
buildPhase() {
runHook preBuild
if [ -z "$makeFlags" ] && ! [ -n "$makefile" -o -e "Makefile" -o -e "makefile" -o -e "GNUmakefile" ]; then
# set to empty if unset
: ${makeFlags=}
if [[ -z "$makeFlags" && ! ( -n "${makefile:-}" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then
echo "no Makefile, doing nothing"
else
# See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409
makeFlags="SHELL=$SHELL $makeFlags"
echo "make flags: $makeFlags ${makeFlagsArray[@]} $buildFlags ${buildFlagsArray[@]}"
make ${makefile:+-f $makefile} \
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
$makeFlags "${makeFlagsArray[@]}" \
$buildFlags "${buildFlagsArray[@]}"
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
)
echoCmd 'build flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
fi
runHook postBuild
@@ -739,11 +820,18 @@ buildPhase() {
checkPhase() {
runHook preCheck
echo "check flags: $makeFlags ${makeFlagsArray[@]} $checkFlags ${checkFlagsArray[@]}"
make ${makefile:+-f $makefile} \
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
$makeFlags "${makeFlagsArray[@]}" \
${checkFlags:-VERBOSE=y} "${checkFlagsArray[@]}" ${checkTarget:-check}
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
${checkTarget:-check}
)
echoCmd 'check flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postCheck
}
@@ -756,11 +844,19 @@ installPhase() {
mkdir -p "$prefix"
fi
installTargets=${installTargets:-install}
echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}"
make ${makefile:+-f $makefile} $installTargets \
$makeFlags "${makeFlagsArray[@]}" \
$installFlags "${installFlagsArray[@]}"
installTargets="${installTargets:-install}"
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
$installTargets
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
)
echoCmd 'install flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postInstall
}
@@ -780,44 +876,48 @@ fixupPhase() {
# Apply fixup to each output.
local output
for output in $outputs; do
prefix=${!output} runHook fixupOutput
prefix="${!output}" runHook fixupOutput
done
# Propagate build inputs and setup hook into the development output.
if [ -z "$crossConfig" ]; then
if [ -z "${crossConfig:-}" ]; then
# Not cross-compiling - propagatedBuildInputs are handled identically to propagatedNativeBuildInputs
local propagated="$propagatedNativeBuildInputs"
if [ -n "$propagatedBuildInputs" ]; then
if [ -n "${propagatedBuildInputs:-}" ]; then
propagated+="${propagated:+ }$propagatedBuildInputs"
fi
if [ -n "$propagated" ]; then
if [ -n "${propagated:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagated" > "${!outputDev}/nix-support/propagated-native-build-inputs"
# shellcheck disable=SC2086
printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs"
fi
else
if [ -n "$propagatedBuildInputs" ]; then
if [ -n "${propagatedBuildInputs:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedBuildInputs" > "${!outputDev}/nix-support/propagated-build-inputs"
# shellcheck disable=SC2086
printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs"
fi
if [ -n "$propagatedNativeBuildInputs" ]; then
if [ -n "${propagatedNativeBuildInputs:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedNativeBuildInputs" > "${!outputDev}/nix-support/propagated-native-build-inputs"
# shellcheck disable=SC2086
printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs"
fi
fi
if [ -n "$setupHook" ]; then
if [ -n "${setupHook:-}" ]; then
mkdir -p "${!outputDev}/nix-support"
substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
fi
# Propagate user-env packages into the output with binaries, TODO?
if [ -n "$propagatedUserEnvPkgs" ]; then
if [ -n "${propagatedUserEnvPkgs:-}" ]; then
mkdir -p "${!outputBin}/nix-support"
echo "$propagatedUserEnvPkgs" > "${!outputBin}/nix-support/propagated-user-env-packages"
# shellcheck disable=SC2086
printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages"
fi
runHook postFixup
@@ -827,11 +927,18 @@ fixupPhase() {
installCheckPhase() {
runHook preInstallCheck
echo "installcheck flags: $makeFlags ${makeFlagsArray[@]} $installCheckFlags ${installCheckFlagsArray[@]}"
make ${makefile:+-f $makefile} \
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
$makeFlags "${makeFlagsArray[@]}" \
$installCheckFlags "${installCheckFlagsArray[@]}" ${installCheckTarget:-installcheck}
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
$installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"}
${installCheckTarget:-installcheck}
)
echoCmd 'installcheck flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
unset flagsArray
runHook postInstallCheck
}
@@ -840,15 +947,22 @@ installCheckPhase() {
distPhase() {
runHook preDist
echo "dist flags: $distFlags ${distFlagsArray[@]}"
make ${makefile:+-f $makefile} $distFlags "${distFlagsArray[@]}" ${distTarget:-dist}
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
$distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
)
if [ "$dontCopyDist" != 1 ]; then
echo 'dist flags: %q' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"
if [ "${dontCopyDist:-0}" != 1 ]; then
mkdir -p "$out/tarballs"
# Note: don't quote $tarballs, since we explicitly permit
# wildcards in there.
cp -pvd ${tarballs:-*.tar.gz} $out/tarballs
# shellcheck disable=SC2086
cp -pvd ${tarballs:-*.tar.gz} "$out/tarballs"
fi
runHook postDist
@@ -857,7 +971,7 @@ distPhase() {
showPhaseHeader() {
local phase="$1"
case $phase in
case "$phase" in
unpackPhase) header "unpacking sources";;
patchPhase) header "patching sources";;
configurePhase) header "configuring";;
@@ -872,33 +986,38 @@ showPhaseHeader() {
genericBuild() {
if [ -f "$buildCommandPath" ]; then
. "$buildCommandPath"
if [ -f "${buildCommandPath:-}" ]; then
local oldOpts="$(shopt -po nounset)"
set +u
source "$buildCommandPath"
eval "$oldOpts"
return
fi
if [ -n "$buildCommand" ]; then
if [ -n "${buildCommand:-}" ]; then
local oldOpts="$(shopt -po nounset)"
set +u
eval "$buildCommand"
eval "$oldOpts"
return
fi
if [ -z "$phases" ]; then
phases="$prePhases unpackPhase patchPhase $preConfigurePhases \
configurePhase $preBuildPhases buildPhase checkPhase \
$preInstallPhases installPhase $preFixupPhases fixupPhase installCheckPhase \
$preDistPhases distPhase $postPhases";
if [ -z "${phases:-}" ]; then
phases="${prePhases:-} unpackPhase patchPhase ${preConfigurePhases:-} \
configurePhase ${preBuildPhases:-} buildPhase checkPhase \
${preInstallPhases:-} installPhase ${preFixupPhases:-} fixupPhase installCheckPhase \
${preDistPhases:-} distPhase ${postPhases:-}";
fi
for curPhase in $phases; do
if [ "$curPhase" = buildPhase -a -n "$dontBuild" ]; then continue; fi
if [ "$curPhase" = checkPhase -a -z "$doCheck" ]; then continue; fi
if [ "$curPhase" = installPhase -a -n "$dontInstall" ]; then continue; fi
if [ "$curPhase" = fixupPhase -a -n "$dontFixup" ]; then continue; fi
if [ "$curPhase" = installCheckPhase -a -z "$doInstallCheck" ]; then continue; fi
if [ "$curPhase" = distPhase -a -z "$doDist" ]; then continue; fi
if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then continue; fi
if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then continue; fi
if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then continue; fi
if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then continue; fi
if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then continue; fi
if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi
if [ -n "$tracePhases" ]; then
echo
echo "@ phase-started $out $curPhase"
if [[ -n $NIX_LOG_FD ]]; then
echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&$NIX_LOG_FD
fi
showPhaseHeader "$curPhase"
@@ -906,18 +1025,14 @@ genericBuild() {
# Evaluate the variable named $curPhase if it exists, otherwise the
# function named $curPhase.
local oldOpts="$(shopt -po nounset)"
set +u
eval "${!curPhase:-$curPhase}"
eval "$oldOpts"
if [ "$curPhase" = unpackPhase ]; then
cd "${sourceRoot:-.}"
fi
if [ -n "$tracePhases" ]; then
echo
echo "@ phase-succeeded $out $curPhase"
fi
stopNest
done
}
@@ -933,3 +1048,6 @@ runHook userHook
dumpVars
# Disable nounset for nix-shell.
set +u
+27 -19
View File
@@ -47,7 +47,7 @@ let
# the bootstrap. In all stages, we build an stdenv and the package
# set that can be built with that stdenv.
stageFun = prevStage:
{ name, overrides ? (self: super: {}), extraBuildInputs ? [] }:
{ name, overrides ? (self: super: {}), extraNativeBuildInputs ? [] }:
let
@@ -56,7 +56,7 @@ let
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config extraBuildInputs;
inherit config extraNativeBuildInputs;
preHook =
''
# Don't patch #!/interpreter because it leads to retained
@@ -79,8 +79,6 @@ let
buildPackages = lib.optionalAttrs (prevStage ? stdenv) {
inherit (prevStage) stdenv;
};
hostPlatform = localSystem;
targetPlatform = localSystem;
cc = prevStage.gcc-unwrapped;
isGNU = true;
libc = prevStage.glibc;
@@ -219,9 +217,9 @@ in
isl = isl_0_17;
};
};
extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
extraNativeBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
# Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook;
})
@@ -244,8 +242,6 @@ in
buildPackages = {
inherit (prevStage) stdenv;
};
hostPlatform = localSystem;
targetPlatform = localSystem;
cc = prevStage.gcc-unwrapped;
libc = self.glibc;
inherit (self) stdenv binutils coreutils gnugrep;
@@ -253,9 +249,9 @@ in
shell = self.bash + "/bin/bash";
};
};
extraBuildInputs = [ prevStage.patchelf prevStage.xz ] ++
extraNativeBuildInputs = [ prevStage.patchelf prevStage.xz ] ++
# Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook;
})
# Construct the final stdenv. It uses the Glibc and GCC, and adds
@@ -283,9 +279,9 @@ in
initialPath =
((import ../common-path.nix) {pkgs = prevStage;});
extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
extraNativeBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
# Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
lib.optional localSystem.isAarch64 prevStage.updateAutotoolsGnuConfigScriptsHook;
cc = prevStage.gcc;
@@ -299,13 +295,25 @@ in
shellPackage = prevStage.bash;
};
/* outputs TODO
allowedRequisites = with prevStage;
[ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl
paxctl zlib pcre linuxHeaders ed gcc gcc.cc libsigsegv
] ++ lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;
*/
# Mainly avoid reference to bootstrap tools
allowedRequisites = with prevStage; with lib;
# Simple executable tools
concatMap (p: [ (getBin p) (getLib p) ])
[ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
gnumake gnused gnutar gnugrep gnupatch patchelf ed paxctl
]
# Library dependencies
++ map getLib (
[ attr acl zlib pcre ]
++ lib.optional (gawk.libsigsegv != null) gawk.libsigsegv
)
# More complicated cases
++ [
glibc.out glibc.dev glibc.bin/*propagated from .dev*/ linuxHeaders
gcc gcc.cc gcc.cc.lib gcc.expand-response-params
]
++ lib.optionals localSystem.isAarch64
[ prevStage.updateAutotoolsGnuConfigScriptsHook prevStage.gnu-config ];
overrides = self: super: {
inherit (prevStage)
+2 -2
View File
@@ -21,8 +21,8 @@ rec {
enableMinimal = true;
extraConfig = ''
CONFIG_ASH y
CONFIG_ASH_BUILTIN_ECHO y
CONFIG_ASH_BUILTIN_TEST y
CONFIG_ASH_ECHO y
CONFIG_ASH_TEST y
CONFIG_ASH_OPTIMIZE_FOR_SIZE y
CONFIG_MKDIR y
CONFIG_TAR y
+4 -4
View File
@@ -66,7 +66,7 @@ let
export lt_cv_deplibs_check_method=pass_all
'';
extraBuildInputsCygwin = [
extraNativeBuildInputsCygwin = [
../cygwin/all-buildinputs-as-runtimedep.sh
../cygwin/wrap-exes-to-find-dlls.sh
] ++ (if system == "i686-cygwin" then [
@@ -94,9 +94,9 @@ let
if system == "x86_64-cygwin" then prehookCygwin else
prehookBase;
extraBuildInputs =
if system == "i686-cygwin" then extraBuildInputsCygwin else
if system == "x86_64-cygwin" then extraBuildInputsCygwin else
extraNativeBuildInputs =
if system == "i686-cygwin" then extraNativeBuildInputsCygwin else
if system == "x86_64-cygwin" then extraNativeBuildInputsCygwin else
[];
initialPath = extraPath ++ path;
+2 -6
View File
@@ -13,12 +13,10 @@ bootStages ++ [
inherit config overlays;
stdenv = import ../generic rec {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
inherit (prevStage.stdenv) buildPlatform hostPlatform targetPlatform;
preHook = ''
export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}"
export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}"
@@ -27,8 +25,6 @@ bootStages ++ [
initialPath = (import ../common-path.nix) { pkgs = prevStage; };
inherit (prevStage.stdenv) hostPlatform targetPlatform;
cc = import ../../build-support/cc-wrapper {
nativeTools = false;
nativePrefix = stdenv.lib.optionalString hostPlatform.isSunOS "/usr";