From e84255296f4ba8f22dd9216dd7024f87e15e60bd Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 4 Dec 2018 21:06:46 -0600 Subject: [PATCH 1/5] stdenv: implement crossOverlays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit crossOverlays only apply to the packages being built, not the build packages. It is useful when you don’t care what is used to build your packages, just what is being built. The idea relies heavily on the cross compiling infrastructure. Using this implies that we need to create a cross stdenv. (cherry picked from commit a3a6ad7a01e943a4097c87cb144d331910693d82) --- pkgs/stdenv/cross/default.nix | 13 +++++++++---- pkgs/stdenv/custom/default.nix | 2 +- pkgs/stdenv/darwin/default.nix | 4 ++-- pkgs/stdenv/default.nix | 4 ++-- pkgs/stdenv/freebsd/default.nix | 2 +- pkgs/stdenv/linux/default.nix | 4 ++-- pkgs/stdenv/native/default.nix | 2 +- pkgs/stdenv/nix/default.nix | 4 ++-- pkgs/top-level/default.nix | 13 ++++++++----- 9 files changed, 28 insertions(+), 20 deletions(-) diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index daa9f66615c9..a6063049a3ad 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -1,11 +1,14 @@ { lib -, localSystem, crossSystem, config, overlays +, localSystem, crossSystem, config, overlays, crossOverlays ? [] }: let bootStages = import ../. { inherit lib localSystem overlays; - crossSystem = null; + + crossSystem = localSystem; + crossOverlays = []; + # Ignore custom stdenvs when cross compiling for compatability config = builtins.removeAttrs config [ "replaceStdenv" ]; }; @@ -33,7 +36,8 @@ in lib.init bootStages ++ [ # Run Packages (buildPackages: { - inherit config overlays; + inherit config; + overlays = overlays ++ crossOverlays; selfBuild = false; stdenv = buildPackages.stdenv.override (old: rec { buildPlatform = localSystem; @@ -48,7 +52,7 @@ in lib.init bootStages ++ [ cc = if crossSystem.useiOSPrebuilt or false then buildPackages.darwin.iosSdkPkgs.clang - else if crossSystem.useAndroidPrebuilt + else if crossSystem.useAndroidPrebuilt or false then buildPackages.androidenv."androidndkPkgs_${crossSystem.ndkVer}".gcc else buildPackages.gcc; @@ -56,6 +60,7 @@ in lib.init bootStages ++ [ ++ lib.optionals (hostPlatform.isLinux && !buildPlatform.isLinux) [ buildPackages.patchelf buildPackages.paxctl ] + ++ lib.optional hostPlatform.isDarwin buildPackages.clang ++ lib.optional (let f = p: !p.isx86 || p.libc == "musl"; in f hostPlatform && !(f buildPlatform)) buildPackages.updateAutotoolsGnuConfigScriptsHook diff --git a/pkgs/stdenv/custom/default.nix b/pkgs/stdenv/custom/default.nix index b6ea8685f8e6..e86face95195 100644 --- a/pkgs/stdenv/custom/default.nix +++ b/pkgs/stdenv/custom/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays }: -assert crossSystem == null; +assert crossSystem == localSystem; let bootStages = import ../. { diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index cda643c42fe3..4c693f3e5d66 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -1,5 +1,5 @@ { lib -, localSystem, crossSystem, config, overlays +, localSystem, crossSystem, config, overlays, crossOverlays ? [] # Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools , bootstrapFiles ? let @@ -16,7 +16,7 @@ } }: -assert crossSystem == null; +assert crossSystem == localSystem; let inherit (localSystem) system platform; diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 210e0439c0b8..c0bbe24e5219 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -7,7 +7,7 @@ { # Args just for stdenvs' usage lib # Args to pass on to the pkgset builder, too -, localSystem, crossSystem, config, overlays +, localSystem, crossSystem, config, overlays, crossOverlays ? [] } @ args: let @@ -36,7 +36,7 @@ let # Select the appropriate stages for the platform `system'. in - if crossSystem != null then stagesCross + if crossSystem != localSystem || crossOverlays != [] then stagesCross else if config ? replaceStdenv then stagesCustom else { # switch "i686-linux" = stagesLinux; diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index b3a6cedad841..dbb4a0564558 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays }: -assert crossSystem == null; +assert crossSystem == localSystem; let inherit (localSystem) system; in diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 884730cfe904..3700211fa293 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -4,7 +4,7 @@ # compiler and linker that do not search in default locations, # ensuring purity of components produced by it. { lib -, localSystem, crossSystem, config, overlays +, localSystem, crossSystem, config, overlays, crossOverlays ? [] , bootstrapFiles ? let table = { @@ -32,7 +32,7 @@ in files }: -assert crossSystem == null; +assert crossSystem == localSystem; let inherit (localSystem) system platform; diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index 37795b11f6dd..810cf16301f4 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -2,7 +2,7 @@ , localSystem, crossSystem, config, overlays }: -assert crossSystem == null; +assert crossSystem == localSystem; let inherit (localSystem) system; diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index ffff8bdf51d4..a8311f49609a 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -1,10 +1,10 @@ { lib -, crossSystem, config, overlays +, crossSystem, localSystem, config, overlays , bootStages , ... }: -assert crossSystem == null; +assert crossSystem == localSystem; bootStages ++ [ (prevStage: { diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index da7fc1bed34c..dcd443a1c29e 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -22,9 +22,8 @@ # `*Platform`s. localSystem -, # The system packages will ultimately be run on. Null if the two should be the - # same. - crossSystem ? null +, # The system packages will ultimately be run on. + crossSystem ? localSystem , # Allow a configuration attribute set to be passed in as an argument. config ? {} @@ -32,6 +31,9 @@ , # List of overlays layers used to extend Nixpkgs. overlays ? [] +, # List of overlays to apply to target packages only. + crossOverlays ? [] + , # A function booting the final package set for a specific standard # environment. See below for the arguments given to that function, the type of # list it returns. @@ -61,7 +63,8 @@ in let builtins.intersectAttrs { platform = null; } config // args.localSystem); - crossSystem = lib.mapNullable lib.systems.elaborate crossSystem0; + crossSystem = if crossSystem0 == null then localSystem + else lib.systems.elaborate crossSystem0; # A few packages make a new package set to draw their dependencies from. # (Currently to get a cross tool chain, or forced-i686 package.) Rather than @@ -91,7 +94,7 @@ in let boot = import ../stdenv/booter.nix { inherit lib allPackages; }; stages = stdenvStages { - inherit lib localSystem crossSystem config overlays; + inherit lib localSystem crossSystem config overlays crossOverlays; }; pkgs = boot stages; From 7fcbc52d7d717778e019bb35673eb2aaae7d2842 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 4 Dec 2018 21:12:17 -0600 Subject: [PATCH 2/5] stdenv/adapters.nix: fixup makeStaticBinaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - makeStaticBinaries don’t work on Darwin (no stable ABI!) - Need to make sure NIX_CFLAGS_LINK appends - isStatic is not used anymore (cherry picked from commit 8726f6a558ac7587db93ca2e67ec3ae1a0c0d5cc) --- pkgs/stdenv/adapters.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 7d5277292738..7ba65fd76e94 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -32,13 +32,15 @@ rec { # Return a modified stdenv that tries to build statically linked # binaries. makeStaticBinaries = stdenv: stdenv // - { mkDerivation = args: stdenv.mkDerivation (args // { - NIX_CFLAGS_LINK = "-static"; + { mkDerivation = args: + if stdenv.hostPlatform.isDarwin + then throw "Cannot build fully static binaries on Darwin/macOS" + else stdenv.mkDerivation (args // { + NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + "-static"; configureFlags = (args.configureFlags or []) ++ [ "--disable-shared" # brrr... ]; }); - isStatic = true; }; From f11d5341aad86561b541839115e31e98326f3342 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 4 Dec 2018 21:13:24 -0600 Subject: [PATCH 3/5] darwin/libiconv: fix static/shared logic The conditional was incorrect - postInstall script should only hsppen when enableShared = true. (cherry picked from commit 5e06294276754ef063c618a1ecb12b629cde8ac3) --- .../darwin/apple-source-releases/libiconv/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix index ea5a59536062..0532c88b66b9 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix @@ -15,7 +15,7 @@ appleDerivation { (lib.enableFeature enableShared "shared") ]; - postInstall = lib.optionalString (!enableStatic) '' + postInstall = lib.optionalString enableShared '' mv $out/lib/libiconv.dylib $out/lib/libiconv-nocharset.dylib ${stdenv.cc.bintools.targetPrefix}install_name_tool -id $out/lib/libiconv-nocharset.dylib $out/lib/libiconv-nocharset.dylib From a8e0694993a561483e6b28d745367d04a0772600 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 4 Dec 2018 21:14:41 -0600 Subject: [PATCH 4/5] zlib: clean up static/shared distincion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is kind of a mess, but basically: - static=true, shared=true means to build statically but move it to the static output - static=true, shared=false means to build statically and leave it in the main output - static=false, shared=true means to not build static at all Confusingly, the old default was static=true, shared=true even though static=false? Still can’t figure out what was meant by that. (cherry picked from commit e999def1597de9d03a35cfa6b62277adb0e9a7ad) --- pkgs/development/libraries/zlib/default.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index d348f877f722..735a92bd370a 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -1,6 +1,7 @@ { stdenv , fetchurl -, static ? false +, static ? true +, shared ? true }: stdenv.mkDerivation (rec { @@ -24,13 +25,15 @@ stdenv.mkDerivation (rec { --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' ''; - outputs = [ "out" "dev" "static" ]; + outputs = [ "out" "dev" ] + ++ stdenv.lib.optional (shared && static) "static"; setOutputFlags = false; outputDoc = "dev"; # single tiny man3 page - configureFlags = stdenv.lib.optional (!static) "--shared"; + configureFlags = stdenv.lib.optional shared "--shared" + ++ stdenv.lib.optional (static && !shared) "--static"; - postInstall = '' + postInstall = stdenv.lib.optionalString (shared && static) '' moveToOutput lib/libz.a "$static" '' # jww (2015-01-06): Sometimes this library install as a .so, even on @@ -64,7 +67,7 @@ stdenv.mkDerivation (rec { "PREFIX=${stdenv.cc.targetPrefix}" ] ++ stdenv.lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ "-f" "win32/Makefile.gcc" - ] ++ stdenv.lib.optionals (!static) [ + ] ++ stdenv.lib.optionals shared [ "SHARED_MODE=1" ]; From 3170d617ef7618a27cacf2eabac3ce3ea9d5a7c4 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Tue, 4 Dec 2018 21:16:43 -0600 Subject: [PATCH 5/5] ncurses: make shared linking optinoal when enableShared = false, we set --without-shared flag. (cherry picked from commit 53a67891ab1fefd3aceed07f173cdd33f549fc70) --- pkgs/development/libraries/ncurses/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix index 6293efcca8b2..56727f5a5d83 100644 --- a/pkgs/development/libraries/ncurses/default.nix +++ b/pkgs/development/libraries/ncurses/default.nix @@ -4,6 +4,7 @@ , mouseSupport ? false , unicode ? true , enableStatic ? stdenv.hostPlatform.useAndroidPrebuilt +, enableShared ? !enableStatic , withCxx ? !stdenv.hostPlatform.useAndroidPrebuilt , gpm @@ -28,7 +29,7 @@ stdenv.mkDerivation rec { setOutputFlags = false; # some aren't supported configureFlags = [ - "--with-shared" + (lib.withFeature enableShared "shared") "--without-debug" "--enable-pc-files" "--enable-symlinks"