Skip to content

Commit

Permalink
Merge pull request #51957 from obsidiansystems/crossOverlays-for-18.09
Browse files Browse the repository at this point in the history
pkgsStatic for 18.09
  • Loading branch information
Ericson2314 committed Dec 13, 2018
2 parents 7a37ddc + 3c1049f commit 62c6099
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pkgs/development/libraries/ncurses/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
, mouseSupport ? false
, unicode ? true
, enableStatic ? stdenv.hostPlatform.useAndroidPrebuilt
, enableShared ? !enableStatic
, withCxx ? !stdenv.hostPlatform.useAndroidPrebuilt

, gpm
Expand All @@ -29,7 +30,7 @@ stdenv.mkDerivation rec {
setOutputFlags = false; # some aren't supported

configureFlags = [
"--with-shared"
(lib.withFeature enableShared "shared")
"--without-debug"
"--enable-pc-files"
"--enable-symlinks"
Expand Down
13 changes: 8 additions & 5 deletions pkgs/development/libraries/zlib/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ stdenv
, fetchurl
, static ? false
, static ? true
, shared ? true
}:

stdenv.mkDerivation (rec {
Expand All @@ -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
Expand Down Expand Up @@ -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"
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
13 changes: 9 additions & 4 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
@@ -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" ];
};
Expand Down Expand Up @@ -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;
Expand All @@ -48,14 +52,15 @@ 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;

extraNativeBuildInputs = old.extraNativeBuildInputs
++ 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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/custom/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays
}:

assert crossSystem == null;
assert crossSystem == localSystem;

let
bootStages = import ../. {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@
}
}:

assert crossSystem == null;
assert crossSystem == localSystem;

let
inherit (localSystem) system platform;
Expand Down
10 changes: 10 additions & 0 deletions pkgs/stdenv/darwin/portable-libsystem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Make /nix/store/...-libSystem “portable” for static built binaries.
# This just rewrites everything in $1/bin to use the
# /usr/lib/libSystem.B.dylib that is provided on every macOS system.

fixupOutputHooks+=('fixLibsystemRefs $prefix')

fixLibsystemRefs() {
find "$1/bin" \
-exec install_name_tool -change @libsystem@ /usr/lib/libSystem.B.dylib {} \;
}
4 changes: 2 additions & 2 deletions pkgs/stdenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/freebsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays
}:

assert crossSystem == null;
assert crossSystem == localSystem;
let inherit (localSystem) system; in


Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -32,7 +32,7 @@
in files
}:

assert crossSystem == null;
assert crossSystem == localSystem;

let
inherit (localSystem) system platform;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/native/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, localSystem, crossSystem, config, overlays
}:

assert crossSystem == null;
assert crossSystem == localSystem;

let
inherit (localSystem) system;
Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ lib
, crossSystem, config, overlays
, crossSystem, localSystem, config, overlays
, bootStages
, ...
}:

assert crossSystem == null;
assert crossSystem == localSystem;

bootStages ++ [
(prevStage: {
Expand Down
13 changes: 8 additions & 5 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
# `*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 ? {}

, # 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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ let
};
};
};

# Fully static packages.
# Currently uses Musl on Linux (couldn’t get static glibc to work).
pkgsStatic = lib.warn "This a provisional API backported from master for convenience." (nixpkgsFun ({
crossOverlays = [ (import ./static.nix) ];
} // lib.optionalAttrs stdenv.hostPlatform.isLinux {
crossSystem = {
parsed = stdenv.hostPlatform.parsed // {
abi = {
"gnu" = lib.systems.parse.abis.musl;
"gnueabi" = lib.systems.parse.abis.musleabi;
"gnueabihf" = lib.systems.parse.abis.musleabihf;
}.${stdenv.hostPlatform.parsed.abi.name}
or lib.systems.parse.abis.musl;
};
};
}));
};

# The complete chain of package set builders, applied from top to bottom.
Expand Down
Loading

0 comments on commit 62c6099

Please sign in to comment.