2009-07-07 21:53:16 +01:00
|
|
|
{ pkgs, stdenv } :
|
|
|
|
|
2010-05-23 16:54:10 +01:00
|
|
|
let inherit (pkgs) stdenv runCommand perl lib;
|
2009-07-07 21:53:16 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2013-05-05 16:05:59 +01:00
|
|
|
# description see mergeAttrsByVersion in lib/misc.nix
|
|
|
|
versionedDerivation = name: version: attrsByVersion: base:
|
|
|
|
pkgs.stdenv.mkDerivation (stdenv.lib.mergeAttrsByVersion name version attrsByVersion base);
|
|
|
|
|
2011-08-16 14:03:46 +01:00
|
|
|
/*
|
|
|
|
Usage example creating a derivation installing ruby, sup and a lib:
|
2009-07-07 21:53:16 +01:00
|
|
|
|
2011-08-16 14:03:46 +01:00
|
|
|
packageOverrides = {
|
|
|
|
rubyCollection = collection {
|
|
|
|
name = "ruby";
|
2014-11-09 22:16:58 +00:00
|
|
|
list = let l = rubyPackages; in
|
2011-08-16 14:03:46 +01:00
|
|
|
[ pkgs.ruby l.chronic l.sup ];
|
|
|
|
};
|
|
|
|
}
|
2009-07-07 21:53:16 +01:00
|
|
|
*/
|
|
|
|
collection = {list, name} : runCommand "collection-${name}" {} ''
|
|
|
|
mkdir -p $out/nix-support
|
2017-07-10 16:59:14 +01:00
|
|
|
printLines ${builtins.toString list} > $out/nix-support/propagated-user-env-packages
|
2009-07-07 21:53:16 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
/* creates a derivation symlinking references C/C++ libs into one include and lib directory called $out/cdt-envs/${name}
|
|
|
|
then you can
|
|
|
|
ln -s ~/.nix-profile/cdt-envs/name ./nix-deps
|
|
|
|
and add .nix-deps/{libs,includes} to IDE's such as Eclipse/ Netbeans etc.
|
|
|
|
To update replace library versions just replace the symlink
|
|
|
|
*/
|
|
|
|
cdtEnv = { name, buildInputs }:
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "cdt-env-${name}";
|
|
|
|
inherit buildInputs;
|
|
|
|
phases = "installPhase";
|
|
|
|
installPhase = ''
|
|
|
|
set -x
|
|
|
|
# requires bash4
|
|
|
|
PATH=$PATH:${pkgs.pkgconfig}/bin
|
|
|
|
|
|
|
|
perlScript=$(dirname $(dirname ${builtins.getEnv "NIXPKGS_ALL"}))/build-support/buildenv/builder.pl
|
|
|
|
# now collect includes and lib paths
|
|
|
|
|
|
|
|
# probably the nix hooks work best, so reuse them by reading NIX_CFLAGS_COMPILE and NIX_LDFLAGS
|
|
|
|
|
|
|
|
PKG_CONFIG_KNOWN_PACKAGES=$(pkg-config --list-all | sed 's/ .*//')
|
|
|
|
|
|
|
|
declare -A INCLUDE_PATHS
|
|
|
|
declare -A LIB_PATHS
|
|
|
|
declare -A LIBS
|
|
|
|
declare -A CFLAGS_OTHER
|
|
|
|
|
|
|
|
PKG_CONFIG_LIBS="$(pkg-config --libs $PKG_CONFIG_KNOWN_PACKAGES)"
|
|
|
|
PKG_CONFIG_CFLAGS="$(pkg-config --cflags $PKG_CONFIG_KNOWN_PACKAGES)"
|
|
|
|
|
|
|
|
for i in $NIX_CFLAGS_COMPILE $PKG_CONFIG_CFLAGS; do
|
|
|
|
echo i is $i
|
|
|
|
case $i in
|
|
|
|
-I*) INCLUDE_PATHS["''${i/-I/}"]= ;;
|
|
|
|
*) CFLAGS_OTHER["''${i}"]= ;;
|
|
|
|
esac
|
|
|
|
echo list is now ''${!INCLUDE_PATHS[@]}
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $NIX_LDFLAGS $PKG_CONFIG_LIBS; do
|
|
|
|
case $i in
|
|
|
|
-L*)
|
|
|
|
LIB_PATHS["''${i/-L/}"]= ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $NIX_LDFLAGS $PKG_CONFIG_LIBS; do
|
|
|
|
echo chekcing $i
|
|
|
|
case $i in
|
|
|
|
-l*) LIBS["''${i}"]= ;;
|
|
|
|
esac;
|
|
|
|
done
|
|
|
|
|
|
|
|
# build output env
|
|
|
|
|
|
|
|
target="$out/cdt-envs/${name}"
|
|
|
|
|
|
|
|
link(){
|
|
|
|
echo "link !!!!"
|
|
|
|
echo $1
|
|
|
|
echo $2
|
|
|
|
(
|
|
|
|
export out="$1"
|
|
|
|
export paths="$2"
|
|
|
|
|
|
|
|
export ignoreCollisions=1
|
|
|
|
export manifest=
|
|
|
|
export pathsToLink=/
|
|
|
|
${perl}/bin/perl $perlScript
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $target/{include,lib}
|
2009-07-07 21:53:16 +01:00
|
|
|
link $target/lib "$(echo "''${!LIB_PATHS[@]}")"
|
|
|
|
link $target/include "$(echo "''${!INCLUDE_PATHS[@]}")"
|
|
|
|
echo "''${!LIBS[@]}" > $target/libs
|
|
|
|
echo "''${!CFLAGS_OTHER[@]}" > $target/cflags-other
|
2009-07-27 17:05:36 +01:00
|
|
|
echo "''${PKG_CONFIG_PATH}" > $target/PKG_CONFIG_PATH
|
|
|
|
echo "''${PATH}" > $target/PATH
|
2009-07-07 21:53:16 +01:00
|
|
|
'';
|
|
|
|
};
|
2010-05-23 16:54:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
# build a debug version of a package
|
|
|
|
debugVersion = pkg: lib.overrideDerivation pkg (attrs: {
|
|
|
|
|
2012-04-10 08:13:52 +01:00
|
|
|
prePhases = ["debugPhase"] ++ lib.optionals (attrs ? prePhases) attrs.prePhases;
|
|
|
|
postPhases = ["objectsPhase"] ++ lib.optionals (attrs ? postPhases) attrs.postPhases;
|
2010-05-23 16:54:10 +01:00
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
CFLAGS="-ggdb -O0";
|
|
|
|
CXXFLAGS="-ggdb -O0";
|
|
|
|
|
2012-04-10 08:13:52 +01:00
|
|
|
debugPhase = ''
|
2010-05-23 16:54:10 +01:00
|
|
|
s=$out/src
|
|
|
|
mkdir -p $s; cd $s;
|
|
|
|
export TMP=$s
|
|
|
|
export TEMP=$s
|
|
|
|
|
|
|
|
for var in CFLAGS CXXFLAGS NIX_CFLAGS_COMPILE; do
|
|
|
|
declare -x "$var=''${!var} -ggdb -O0"
|
|
|
|
done
|
2011-05-04 19:55:22 +01:00
|
|
|
echo "file should tell that executable has not been stripped"
|
2010-05-23 16:54:10 +01:00
|
|
|
'';
|
|
|
|
|
2012-04-10 08:13:52 +01:00
|
|
|
objectsPhase = ''
|
|
|
|
cd $out/src
|
|
|
|
find . -name "*.o" -exec rm {} \;
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
# build an optimized ersion of a package but with symbols and source
|
|
|
|
symbolsVersion = pkg: lib.overrideDerivation pkg (attrs: {
|
|
|
|
|
|
|
|
prePhases = ["debugPhase"] ++ lib.optionals (attrs ? prePhases) attrs.prePhases;
|
|
|
|
postPhases = ["objectsPhase"] ++ lib.optionals (attrs ? postPhases) attrs.postPhases;
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
CFLAGS="-g -O2";
|
|
|
|
CXXFLAGS="-g -O2";
|
|
|
|
|
|
|
|
debugPhase = ''
|
|
|
|
s=$out/src
|
|
|
|
mkdir -p $s; cd $s;
|
|
|
|
export TMP=$s
|
|
|
|
export TEMP=$s
|
|
|
|
|
|
|
|
for var in CFLAGS CXXFLAGS NIX_CFLAGS_COMPILE; do
|
|
|
|
declare -x "$var=''${!var} -g -O2"
|
|
|
|
done
|
|
|
|
echo "file should tell that executable has not been stripped"
|
|
|
|
'';
|
|
|
|
|
|
|
|
objectsPhase = ''
|
|
|
|
cd $out/src
|
|
|
|
find . -name "*.o" -exec rm {} \;
|
|
|
|
'';
|
2010-05-23 16:54:10 +01:00
|
|
|
});
|
2009-07-07 21:53:16 +01:00
|
|
|
}
|