2012-03-14 18:59:09 +00:00
|
|
|
# idea: provide a build environments for your developement of preference
|
2008-10-09 23:57:20 +01:00
|
|
|
/*
|
2012-03-14 18:59:09 +00:00
|
|
|
#### examples of use: ####
|
|
|
|
# Add this to your ~/.nixpkgs/config.nix:
|
|
|
|
{
|
2012-03-14 23:38:28 +00:00
|
|
|
packageOverrides = pkgs : with pkgs; {
|
2012-03-14 18:59:09 +00:00
|
|
|
sdlEnv = pkgs.myEnvFun {
|
|
|
|
name = "sdl";
|
|
|
|
buildInputs = [ stdenv SDL SDL_image SDL_ttf SDL_gfx cmake SDL_net pkgconfig];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-20 14:51:18 +00:00
|
|
|
# Then you can install it by:
|
2013-02-23 11:32:15 +00:00
|
|
|
# $ nix-env -i env-sdl
|
2012-03-20 14:51:18 +00:00
|
|
|
# And you can load it simply calling:
|
2012-03-26 11:20:32 +01:00
|
|
|
# $ load-env-sdl
|
2012-03-14 23:07:59 +00:00
|
|
|
# and this will update your env vars to have 'make' and 'gcc' finding the SDL
|
|
|
|
# headers and libs.
|
2008-10-09 23:57:20 +01:00
|
|
|
|
2012-03-14 18:59:09 +00:00
|
|
|
|
|
|
|
##### Another example, more complicated but achieving more: #######
|
|
|
|
# Make an environment to build nix from source and create ctags (tagfiles can
|
|
|
|
# be extracted from TAG_FILES) from every source package. Here would be a
|
|
|
|
# full ~/.nixpkgs/config.nix
|
2008-10-09 23:57:20 +01:00
|
|
|
{
|
|
|
|
packageOverrides = pkgs : with pkgs; with sourceAndTags;
|
2012-03-14 18:59:09 +00:00
|
|
|
let complicatedMyEnv = { name, buildInputs ? [], cTags ? [], extraCmds ? ""}:
|
2008-10-09 23:57:20 +01:00
|
|
|
pkgs.myEnvFun {
|
|
|
|
inherit name;
|
|
|
|
buildInputs = buildInputs
|
2012-03-14 18:59:09 +00:00
|
|
|
++ map (x : sourceWithTagsDerivation
|
|
|
|
( (addCTaggingInfo x ).passthru.sourceWithTags ) ) cTags;
|
2008-10-09 23:57:20 +01:00
|
|
|
extraCmds = ''
|
|
|
|
${extraCmds}
|
|
|
|
HOME=${builtins.getEnv "HOME"}
|
|
|
|
. ~/.bashrc
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in rec {
|
2012-03-14 18:46:18 +00:00
|
|
|
# this is the example we will be using
|
2012-03-14 18:59:09 +00:00
|
|
|
nixEnv = complicatedMyEnv {
|
|
|
|
name = "nix";
|
|
|
|
buildInputs = [ libtool stdenv perl curl bzip2 openssl db45 autoconf automake zlib ];
|
2012-03-14 18:46:18 +00:00
|
|
|
};
|
2008-10-09 23:57:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-20 14:51:18 +00:00
|
|
|
# Now we should build our newly defined custom environment using this command on a shell, so type:
|
|
|
|
# $ nix-env -i env-nix
|
2008-10-09 23:57:20 +01:00
|
|
|
|
2012-03-26 11:20:32 +01:00
|
|
|
# You can load the environment simply typing a "load-env-${name}" command.
|
|
|
|
# $ load-env-nix
|
2012-03-20 14:51:18 +00:00
|
|
|
# The result using that command should be:
|
|
|
|
# env-nix loaded
|
2012-03-20 18:49:44 +00:00
|
|
|
and show you a shell with a prefixed prompt.
|
2008-10-09 23:57:20 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-25 18:53:37 +01:00
|
|
|
{ mkDerivation, substituteAll, pkgs }:
|
|
|
|
{ stdenv ? pkgs.stdenv, name, buildInputs ? []
|
|
|
|
, propagatedBuildInputs ? [], gcc ? stdenv.gcc, cTags ? [], extraCmds ? ""
|
2013-10-04 09:02:30 +01:00
|
|
|
, cleanupCmds ? "", shell ? "${pkgs.bashInteractive}/bin/bash --norc"}:
|
2012-05-25 18:53:37 +01:00
|
|
|
|
2008-10-09 23:57:20 +01:00
|
|
|
mkDerivation {
|
2010-01-22 15:00:15 +00:00
|
|
|
# The setup.sh script from stdenv will expect the native build inputs in
|
2012-12-28 18:20:09 +00:00
|
|
|
# the nativeBuildInputs environment variable.
|
|
|
|
nativeBuildInputs = [ ] ++ buildInputs;
|
2012-05-25 18:53:37 +01:00
|
|
|
# Trick to bypass the stdenv usual change of propagatedBuildInputs => propagatedNativeBuildInputs
|
|
|
|
propagatedBuildInputs2 = propagatedBuildInputs;
|
|
|
|
|
2008-10-09 23:57:20 +01:00
|
|
|
name = "env-${name}";
|
2012-02-29 12:55:51 +00:00
|
|
|
phases = [ "buildPhase" "fixupPhase" ];
|
2008-10-09 23:57:20 +01:00
|
|
|
setupNew = substituteAll {
|
2009-04-28 17:52:36 +01:00
|
|
|
src = ../../stdenv/generic/setup.sh;
|
2012-05-25 18:53:37 +01:00
|
|
|
inherit gcc;
|
2008-10-09 23:57:20 +01:00
|
|
|
};
|
2011-03-27 15:08:13 +01:00
|
|
|
|
2014-11-25 13:05:21 +00:00
|
|
|
buildPhase = let
|
|
|
|
initialPath = import ../../stdenv/common-path.nix { inherit pkgs; };
|
|
|
|
in ''
|
2008-10-09 23:57:20 +01:00
|
|
|
set -x
|
2012-02-29 12:55:51 +00:00
|
|
|
mkdir -p "$out/dev-envs" "$out/nix-support" "$out/bin"
|
2008-10-09 23:57:20 +01:00
|
|
|
s="$out/nix-support/setup-new-modified"
|
|
|
|
# shut some warning up.., do not use set -e
|
|
|
|
sed -e 's@set -e@@' \
|
|
|
|
-e 's@assertEnvExists\s\+NIX_STORE@:@' \
|
|
|
|
-e 's@trap.*@@' \
|
2014-11-25 13:05:21 +00:00
|
|
|
-e '1i initialPath="${toString initialPath}"' \
|
|
|
|
"$setupNew" > "$s"
|
2008-10-09 23:57:20 +01:00
|
|
|
cat >> "$out/dev-envs/''${name/env-/}" << EOF
|
2012-12-28 18:20:09 +00:00
|
|
|
nativeBuildInputs="$nativeBuildInputs"
|
2012-05-25 18:53:37 +01:00
|
|
|
propagatedBuildInputs="$propagatedBuildInputs2"
|
2008-10-09 23:57:20 +01:00
|
|
|
# the setup-new script wants to write some data to a temp file.. so just let it do that and tidy up afterwards
|
|
|
|
tmp="\$("${pkgs.coreutils}/bin/mktemp" -d)"
|
|
|
|
NIX_BUILD_TOP="\$tmp"
|
|
|
|
phases=
|
|
|
|
# only do all the setup stuff in nix-support/*
|
|
|
|
set +e
|
2012-11-22 09:54:56 +00:00
|
|
|
# This prevents having -rpath /lib in NIX_LDFLAGS
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2009-02-11 16:12:12 +00:00
|
|
|
if [[ -z "\$ZSH_VERSION" ]]; then
|
|
|
|
source "$s"
|
|
|
|
else
|
|
|
|
setopt interactivecomments
|
2009-02-11 16:12:14 +00:00
|
|
|
# fix bash indirection
|
2009-02-11 16:12:12 +00:00
|
|
|
# let's hope the bash arrays aren't used
|
|
|
|
# substitute is using bash array, so skip it
|
|
|
|
echo '
|
|
|
|
setopt NO_BAD_PATTERN
|
|
|
|
setopt NO_BANG_HIST
|
|
|
|
setopt NO_BG_NICE
|
|
|
|
setopt NO_EQUALS
|
|
|
|
setopt NO_FUNCTION_ARGZERO
|
|
|
|
setopt GLOB_SUBST
|
|
|
|
setopt NO_HUP
|
|
|
|
setopt INTERACTIVE_COMMENTS
|
|
|
|
setopt KSH_ARRAYS
|
|
|
|
setopt NO_MULTIOS
|
|
|
|
setopt NO_NOMATCH
|
|
|
|
setopt RM_STAR_SILENT
|
|
|
|
setopt POSIX_BUILTINS
|
|
|
|
setopt SH_FILE_EXPANSION
|
|
|
|
setopt SH_GLOB
|
|
|
|
setopt SH_OPTION_LETTERS
|
|
|
|
setopt SH_WORD_SPLIT
|
|
|
|
' >> "\$tmp/script"
|
|
|
|
sed -e 's/\''${!\([^}]*\)}/\''${(P)\1}/g' \
|
|
|
|
-e 's/[[]\*\]//' \
|
|
|
|
-e 's/substitute() {/ substitute() { return; /' \
|
|
|
|
-e 's@PATH=\$@PATH=${pkgs.coreutils}/bin@' \
|
|
|
|
"$s" >> "\$tmp/script"
|
|
|
|
echo "\$tmp/script";
|
|
|
|
source "\$tmp/script";
|
|
|
|
fi
|
2014-11-25 01:01:22 +00:00
|
|
|
${pkgs.coreutils}/bin/rm -fr "\$tmp"
|
2008-10-09 23:57:20 +01:00
|
|
|
${extraCmds}
|
2013-04-13 18:10:50 +01:00
|
|
|
|
|
|
|
nix_cleanup() {
|
2013-05-14 17:59:50 +01:00
|
|
|
:
|
2013-04-13 18:10:50 +01:00
|
|
|
${cleanupCmds}
|
|
|
|
}
|
|
|
|
|
2008-10-09 23:57:20 +01:00
|
|
|
export PATH
|
|
|
|
echo $name loaded
|
2013-04-13 18:10:50 +01:00
|
|
|
|
|
|
|
trap nix_cleanup EXIT
|
2008-10-09 23:57:20 +01:00
|
|
|
EOF
|
2012-02-29 12:55:51 +00:00
|
|
|
|
2012-03-20 18:49:44 +00:00
|
|
|
mkdir -p $out/bin
|
2013-10-04 09:02:30 +01:00
|
|
|
sed -e 's,@shell@,${shell},' -e s,@myenvpath@,$out/dev-envs/${name}, \
|
|
|
|
-e 's,@name@,${name},' ${./loadenv.sh} > $out/bin/load-env-${name}
|
2012-03-26 11:20:32 +01:00
|
|
|
chmod +x $out/bin/load-env-${name}
|
2008-10-09 23:57:20 +01:00
|
|
|
'';
|
|
|
|
}
|