Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb18a3b
top-level: Splice in more package sets for new types of deps
Ericson2314 Jun 2, 2017
7f3ca3e
stdenv: Fix handling of dependencies and hooks
Ericson2314 Sep 11, 2017
a036473
{bintools,cc}-wrapper: Fix setup hook to respect the role of the cc-c…
Ericson2314 Aug 3, 2017
3a50395
{bintools,cc}-wrapper: extraPackages should be `depsTargetTargetPropa…
Ericson2314 Jul 7, 2017
5b74540
treewide: Use `depsBuildBuild` for buildPackges.stdenv.cc
Ericson2314 Jun 26, 2017
bc23afe
gcc: Add build->build dep for C compilers
Ericson2314 Aug 17, 2017
114a9b6
gcc: Let cc-wrapper's setup hook define any tool env vars we need
Ericson2314 Aug 18, 2017
9cda2f5
gcc: Fix deps, for cross and consistency
Ericson2314 Sep 4, 2017
0f5c804
gcc, binutils: Get rid of 32-bit ARM configure flag exception
Ericson2314 Nov 28, 2017
4ad9a97
gcc: Don't let solaris hack pollute CC elsehwere
Ericson2314 Nov 28, 2017
a1cdc20
strip setup hook: Learn about only stripping host/target binaries alone
Ericson2314 Jul 7, 2017
046f091
treewide: Don't use envHook anymore
Ericson2314 Aug 10, 2017
e0f1739
treewide: Don't use `nativePkgs` or `crossPkgs` anymore
Ericson2314 Aug 12, 2017
f083248
linux bootstrap tools cross: Nuke more refs
Ericson2314 Dec 14, 2017
469fd89
stdenv-setup: Ease the transition with native builds
Ericson2314 Aug 28, 2017
e9a369b
kdoctools: Perl is a propagated *run*-time dep
Ericson2314 Dec 24, 2017
7ffc4e1
doc: Add "Specifying Dependencies" section to the stdenv chapter
Ericson2314 Jun 2, 2017
b55999b
doc: Document `dontStripHost` and `dontStripTarget`
Ericson2314 Jun 2, 2017
edfe42f
doc: More information in the setup hook section of the stdenv chapter
Ericson2314 Jun 2, 2017
8a434b6
doc: Add cross cookbook
Ericson2314 Dec 31, 2017
a98e686
doc: Breaking change release not for dependency propagation logic
Ericson2314 Dec 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion doc/cross-compilation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
How does this work in practice? Nixpkgs is now structured so that build-time dependencies are taken from <varname>buildPackages</varname>, whereas run-time dependencies are taken from the top level attribute set.
For example, <varname>buildPackages.gcc</varname> should be used at build time, while <varname>gcc</varname> should be used at run time.
Now, for most of Nixpkgs's history, there was no <varname>buildPackages</varname>, and most packages have not been refactored to use it explicitly.
Instead, one can use the four attributes used for specifying dependencies as documented in <xref linkend="ssec-stdenv-attributes"/>.
Instead, one can use the six (<emphasis>gasp</emphasis>) attributes used for specifying dependencies as documented in <xref linkend="ssec-stdenv-dependencies"/>.
We "splice" together the run-time and build-time package sets with <varname>callPackage</varname>, and then <varname>mkDerivation</varname> for each of four attributes pulls the right derivation out.
This splicing can be skipped when not cross compiling as the package sets are the same, but is a bit slow for cross compiling.
Because of this, a best-of-both-worlds solution is in the works with no splicing or explicit access of <varname>buildPackages</varname> needed.
Expand All @@ -200,6 +200,45 @@
</para></note>
</section>

<section>
<title>Cross packagaing cookbook</title>
<para>
Some frequently problems when packaging for cross compilation are good to just spell and answer.
Ideally the information above is exhaustive, so this section cannot provide any new information,
but its ludicrous and cruel to expect everyone to spend effort working through the interaction of many features just to figure out the same answer to the same common problem.
Feel free to add to this list!
</para>
<qandaset>
<qandaentry>
<question><para>
What if my package's build system needs to build a C program to be run under the build environment?
</para></question>
<answer><para>
<programlisting>depsBuildBuild = [ buildPackages.stdenv.cc ];</programlisting>
Add it to your <function>mkDerivation</function> invocation.
</para></answer>
</qandaentry>
<qandaentry>
<question><para>
My package fails to find <command>ar</command>.
</para></question>
<answer><para>
Many packages assume that an unprefixed <command>ar</command> is available, but Nix doesn't provide one.
It only provides a prefixed one, just as it only does for all the other binutils programs.
It may be necessary to patch the package to fix the build system to use a prefixed `ar`.
</para></answer>
</qandaentry>
<qandaentry>
<question><para>
My package's testsuite needs to run host platform code.
</para></question>
<answer><para>
<programlisting>doCheck = stdenv.hostPlatform != stdenv.buildPlatfrom;</programlisting>
Add it to your <function>mkDerivation</function> invocation.
</para></answer>
</qandaentry>
</qandaset>
</section>
</section>

<!--============================================================-->
Expand Down
357 changes: 318 additions & 39 deletions doc/stdenv.xml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions nixos/doc/manual/release-notes/rl-1803.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ following incompatible changes:</para>
Other more obscure ones are just moved.
</para>
</listitem>
<listitem>
<para>
The propagation logic has been changed.
The new logic, along with new types of dependencies that go with, is thoroughly documented in the "Specifying dependencies" section of the "Standard Environment" chapter of the nixpkgs manual.
<!-- That's <xref linkend="ssec-stdenv-attributes"> were we to merge the manuals. -->
The old logic isn't but is easy to describe: dependencies were propagated as the same type of dependency no matter what.
In practice, that means that many <function>propagatedNativeBuildInputs</function> should instead be <function>propagatedBuildInputs</function>.
Thankfully, that was and is the least used type of dependency.
Also, it means that some <function>propagatedBuildInputs</function> should instead be <function>depsTargetTargetPropagated</function>.
Other types dependencies should be unaffected.
</para>
</listitem>
</itemizedlist>

</section>
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/kde/libkcddb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mkDerivation {
license = with licenses; [ gpl2 lgpl21 bsd3 ];
maintainers = with maintainers; [ peterhoeg ];
};
nativeBuildInputs = [ extra-cmake-modules ];
buildInputs = [ qtbase kdoctools ];
nativeBuildInputs = [ extra-cmake-modules kdoctools ];
buildInputs = [ qtbase ];
propagatedBuildInputs = [
kcodecs ki18n kio kwidgetsaddons
libmusicbrainz5
Expand Down
6 changes: 3 additions & 3 deletions pkgs/applications/networking/browsers/lynx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ stdenv.mkDerivation rec {

configureFlags = [ "--enable-widec" ] ++ stdenv.lib.optional sslSupport "--with-ssl";

nativeBuildInputs = stdenv.lib.optional sslSupport pkgconfig
++ stdenv.lib.optional (hostPlatform != buildPlatform) buildPackages.stdenv.cc
++ [ nukeReferences ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ nukeReferences ]
++ stdenv.lib.optional sslSupport pkgconfig;

buildInputs = [ ncurses gzip ] ++ stdenv.lib.optional sslSupport openssl.dev;

Expand Down
7 changes: 5 additions & 2 deletions pkgs/applications/office/skrooge/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ mkDerivation rec {
sha256 = "1dbvdrkdpgv39v8h7k3mri0nzlslfyd5kk410czj0jdn4qq400md";
};

nativeBuildInputs = [ cmake extra-cmake-modules shared_mime_info ];
nativeBuildInputs = [
cmake extra-cmake-modules kdoctools shared_mime_info
];

buildInputs = [ qtwebkit qtscript grantlee kxmlgui kwallet kparts kdoctools
buildInputs = [
qtwebkit qtscript grantlee kxmlgui kwallet kparts
kjobwidgets kdesignerplugin kiconthemes knewstuff sqlcipher qca-qt5
kactivities karchive kguiaddons knotifyconfig krunner kwindowsystem libofx
];
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/science/logic/coq/8.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stdenv.mkDerivation {
fi
}

envHooks=(''${envHooks[@]} addCoqPath)
addEnvHooks "$targetOffset" addCoqPath
'';

passthru = {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/science/logic/coq/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ self = stdenv.mkDerivation {
fi
}

envHooks=(''${envHooks[@]} addCoqPath)
addEnvHooks "$targetOffset" addCoqPath
'';

preConfigure = ''
Expand Down
6 changes: 4 additions & 2 deletions pkgs/applications/science/math/R/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
addRLibPath () {
addToSearchPath R_LIBS_SITE $1/library
if [[ -d "$1/library" ]]; then
addToSearchPath R_LIBS_SITE "$1/library"
fi
}

envHooks+=(addRLibPath)
addEnvHooks "$targetOffset" addRLibPath
3 changes: 2 additions & 1 deletion pkgs/applications/video/mplayer/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ stdenv.mkDerivation rec {
rm -rf ffmpeg
'';

nativeBuildInputs = [ buildPackages.stdenv.cc pkgconfig yasm ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ pkgconfig yasm ];
buildInputs = with stdenv.lib;
[ freetype ffmpeg ]
++ optional aalibSupport aalib
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ stdenv.mkDerivation {
else throw "unknown emulation for platform: " + targetPlatform.config;
in targetPlatform.platform.bfdEmulation or (fmt + "-" + arch);

propagatedBuildInputs = extraPackages;
depsTargetTargetPropagated = extraPackages;

setupHook = ./setup-hook.sh;

Expand Down
45 changes: 33 additions & 12 deletions pkgs/build-support/bintools-wrapper/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
#
# See comments in cc-wrapper's setup hook. This works exactly the same way.

set -u

# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
# native compile.
#
# TODO(@Ericson2314): No native exception
[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0

bintoolsWrapper_addLDVars () {
case $depOffset in
case $depHostOffset in
-1) local role='BUILD_' ;;
0) local role='' ;;
1) local role='TARGET_' ;;
*) echo "bintools-wrapper: Error: Cannot be used with $depOffset-offset deps, " >2;
*) echo "bintools-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2;
return 1 ;;
esac

Expand All @@ -20,17 +28,29 @@ bintoolsWrapper_addLDVars () {
fi
}

if [ -n "${crossConfig:-}" ]; then
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1
role_pre='BUILD_'
role_post='_FOR_BUILD'
else
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1
role_pre=""
role_post=''
fi
case $targetOffset in
-1)
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1
role_pre='BUILD_'
role_post='_FOR_BUILD'
;;
0)
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1
role_pre=''
role_post=''
;;
1)
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET=1
role_pre='TARGET_'
role_post='_FOR_TARGET'
;;
*)
echo "cc-wrapper: used as improper sort of dependency" >2;
return 1
;;
esac

envHooks+=(bintoolsWrapper_addLDVars)
addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars

# shellcheck disable=SC2157
if [ -n "@bintools_bin@" ]; then
Expand Down Expand Up @@ -65,3 +85,4 @@ done

# No local scope in sourced file
unset -v role_pre role_post cmd upper_case
set +u
3 changes: 2 additions & 1 deletion pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ stdenv.mkDerivation {
ln -s $ccPath/${targetPrefix}ghdl $out/bin/${targetPrefix}ghdl
'';

propagatedBuildInputs = [ bintools ] ++ extraPackages;
propagatedBuildInputs = [ bintools ];
depsTargetTargetPropagated = extraPackages;

setupHook = ./setup-hook.sh;

Expand Down
55 changes: 37 additions & 18 deletions pkgs/build-support/cc-wrapper/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,26 @@
# For more details, read the individual files where the mechanisms used to
# accomplish this will be individually documented.

set -u

# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
# native compile.
#
# TODO(@Ericson2314): No native exception
[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0

# It's fine that any other cc-wrapper will redefine this. Bash functions close
# over no state, and there's no @-substitutions within, so any redefined
# function is guaranteed to be exactly the same.
ccWrapper_addCVars () {
# The `depOffset` describes how the platforms of the dependencies are slid
# relative to the depending package. It is brought into scope of the
# environment hook defined as the role of the dependency being applied.
case $depOffset in
# The `depHostOffset` describes how the host platform of the dependencies
# are slid relative to the depending package. It is brought into scope of
# the environment hook defined as the role of the dependency being applied.
case $depHostOffset in
-1) local role='BUILD_' ;;
0) local role='' ;;
1) local role='TARGET_' ;;
*) echo "cc-wrapper: Error: Cannot be used with $depOffset-offset deps, " >2;
*) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2;
return 1 ;;
esac

Expand All @@ -87,20 +94,31 @@ ccWrapper_addCVars () {
#
# We also need to worry about what role is being added on *this* invocation of
# setup-hook, which `role` tracks.
if [ -n "${crossConfig:-}" ]; then
export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1
role_pre='BUILD_'
role_post='_FOR_BUILD'
else
export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1
role_pre=''
role_post=''
fi
case $targetOffset in
-1)
export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1
role_pre='BUILD_'
role_post='_FOR_BUILD'
;;
0)
export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1
role_pre=''
role_post=''
;;
1)
export NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET=1
role_pre='TARGET_'
role_post='_FOR_TARGET'
;;
*)
echo "cc-wrapper: used as improper sort of dependency" >2;
return 1
;;
esac

# Eventually the exact sort of env-hook we create will depend on the role. This
# is because based on what relative platform we are targeting, we use different
# dependencies.
envHooks+=(ccWrapper_addCVars)
# We use the `targetOffset` to choose the right env hook to accumulate the right
# sort of deps (those with that offset).
addEnvHooks "$targetOffset" ccWrapper_addCVars

# Note 1: these come *after* $out in the PATH (see setup.sh).
# Note 2: phase separation makes this look useless to shellcheck.
Expand Down Expand Up @@ -131,3 +149,4 @@ export CXX${role_post}=@named_cxx@

# No local scope in sourced file
unset -v role_pre role_post
set +u
6 changes: 5 additions & 1 deletion pkgs/build-support/emacs/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ addEmacsVars () {
fi
}

envHooks+=(addEmacsVars)
# If this is for a wrapper derivation, emacs and the dependencies are all
# run-time dependencies. If this is for precompiling packages into bytecode,
# emacs is a compile-time dependency of the package.
addEnvHooks "$targetOffset" addEmacsVars
addEnvHooks "$targetOffset" addEmacsVars
4 changes: 2 additions & 2 deletions pkgs/build-support/gcc-wrapper-old/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addCVars () {
gccWrapperOld_addCVars () {
if test -d $1/include; then
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
fi
Expand All @@ -12,7 +12,7 @@ addCVars () {
fi
}

envHooks=(${envHooks[@]} addCVars)
envBuildBuildHooks+=(gccWrapperOld_addCVars)

# Note: these come *after* $out in the PATH (see setup.sh).

Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/find-xml-catalogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ if [ -z "$libxmlHookDone" ]; then
# xmllint and xsltproc from looking in /etc/xml/catalog.
export XML_CATALOG_FILES
if [ -z "$XML_CATALOG_FILES" ]; then XML_CATALOG_FILES=" "; fi
envHooks+=(addXMLCatalogs)
addEnvHooks "$hostOffset" addXMLCatalogs
fi
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/set-java-classpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ addPkgToClassPath () {
done
}

envHooks+=(addPkgToClassPath)
addEnvHooks "$targetOffset" addPkgToClassPath
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/setup-debug-info-dirs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ setupDebugInfoDirs () {
addToSearchPath NIX_DEBUG_INFO_DIRS $1/lib/debug
}

envHooks+=(setupDebugInfoDirs)
addEnvHooks "$targetOffset" setupDebugInfoDirs
Loading