2012-03-14 18:59:09 +00:00
|
|
|
# idea: provide a build environments for your developement of preference
|
2008-10-09 22:57:20 +00:00
|
|
|
/*
|
2012-03-14 18:59:09 +00:00
|
|
|
#### examples of use: ####
|
|
|
|
# Add this to your ~/.nixpkgs/config.nix:
|
|
|
|
{
|
|
|
|
packageOverrides = pkgs : with pkgs;
|
|
|
|
sdlEnv = pkgs.myEnvFun {
|
|
|
|
name = "sdl";
|
|
|
|
buildInputs = [ stdenv SDL SDL_image SDL_ttf SDL_gfx cmake SDL_net pkgconfig];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# Then you can install it by: nix-env -i sdl-env
|
|
|
|
# And you can load it simply calling: load-sdl-env
|
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 22:57:20 +00: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 22:57:20 +00:00
|
|
|
{
|
|
|
|
packageOverrides = pkgs : with pkgs; with sourceAndTags;
|
2012-03-14 18:59:09 +00:00
|
|
|
let complicatedMyEnv = { name, buildInputs ? [], cTags ? [], extraCmds ? ""}:
|
2008-10-09 22:57:20 +00: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 22:57:20 +00: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 22:57:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-14 18:59:09 +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 22:57:20 +00:00
|
|
|
|
2012-03-14 23:07:59 +00:00
|
|
|
You can load the environment simply typing a "load-${name}-env" command.
|
2012-03-14 18:59:09 +00:00
|
|
|
$ load-nix-env
|
2012-03-14 23:07:59 +00:00
|
|
|
The result using that command should be:
|
2012-03-14 18:59:09 +00:00
|
|
|
env-nix loaded
|
2008-10-09 22:57:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
{ mkDerivation, substituteAll, pkgs } : { stdenv ? pkgs.stdenv, name, buildInputs ? [], cTags ? [], extraCmds ? ""} :
|
|
|
|
mkDerivation {
|
2010-01-22 15:00:15 +00:00
|
|
|
# The setup.sh script from stdenv will expect the native build inputs in
|
|
|
|
# the buildNativeInputs environment variable.
|
|
|
|
buildNativeInputs = [ ] ++ buildInputs ;
|
2008-10-09 22:57:20 +00:00
|
|
|
name = "env-${name}";
|
2012-02-29 12:55:51 +00:00
|
|
|
phases = [ "buildPhase" "fixupPhase" ];
|
2008-10-09 22:57:20 +00:00
|
|
|
setupNew = substituteAll {
|
2009-04-28 16:52:36 +00:00
|
|
|
src = ../../stdenv/generic/setup.sh;
|
2008-10-09 22:57:20 +00:00
|
|
|
initialPath= (import ../../stdenv/common-path.nix) { inherit pkgs; };
|
|
|
|
gcc = stdenv.gcc;
|
|
|
|
};
|
2011-03-27 14:08:13 +00:00
|
|
|
|
2008-10-09 22:57:20 +00:00
|
|
|
buildPhase = ''
|
|
|
|
set -x
|
2012-02-29 12:55:51 +00:00
|
|
|
mkdir -p "$out/dev-envs" "$out/nix-support" "$out/bin"
|
2008-10-09 22:57:20 +00:00
|
|
|
s="$out/nix-support/setup-new-modified"
|
|
|
|
cp "$setupNew" "$s"
|
|
|
|
# shut some warning up.., do not use set -e
|
|
|
|
sed -e 's@set -e@@' \
|
|
|
|
-e 's@assertEnvExists\s\+NIX_STORE@:@' \
|
|
|
|
-e 's@trap.*@@' \
|
|
|
|
-i "$s"
|
|
|
|
cat >> "$out/dev-envs/''${name/env-/}" << EOF
|
2010-01-22 15:00:15 +00:00
|
|
|
buildNativeInputs="$buildNativeInputs"
|
2008-10-09 22:57:20 +00: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
|
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
|
2008-10-09 22:57:20 +00:00
|
|
|
rm -fr "\$tmp"
|
|
|
|
${extraCmds}
|
|
|
|
export PATH
|
|
|
|
echo $name loaded
|
|
|
|
EOF
|
2012-02-29 12:55:51 +00:00
|
|
|
|
|
|
|
cat >> "$out/bin/load-''${name/env-/}-env" << EOF
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
source "$out/dev-envs/''${name/env-/}"
|
|
|
|
EOF
|
|
|
|
chmod +x "$out/bin/load-''${name/env-/}-env"
|
2008-10-09 22:57:20 +00:00
|
|
|
'';
|
|
|
|
}
|