2012-03-14 19:59:09 +01:00
|
|
|
# idea: provide a build environments for your developement of preference
|
2008-10-10 00:57:20 +02:00
|
|
|
/*
|
2012-03-14 19:59:09 +01:00
|
|
|
#### examples of use: ####
|
2017-05-27 12:33:22 +02:00
|
|
|
# Add this to your ~/.config/nixpkgs/config.nix:
|
2012-03-14 19:59:09 +01:00
|
|
|
{
|
2012-03-15 00:38:28 +01:00
|
|
|
packageOverrides = pkgs : with pkgs; {
|
2012-03-14 19:59:09 +01:00
|
|
|
sdlEnv = pkgs.myEnvFun {
|
|
|
|
name = "sdl";
|
2017-09-05 23:26:13 +02:00
|
|
|
nativeBuildInputs = [ pkgconfig ];
|
|
|
|
buildInputs = [ stdenv SDL SDL_image SDL_ttf SDL_gfx cmake SDL_net];
|
2012-03-14 19:59:09 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-20 15:51:18 +01:00
|
|
|
# Then you can install it by:
|
2013-02-23 12:32:15 +01:00
|
|
|
# $ nix-env -i env-sdl
|
2012-03-20 15:51:18 +01:00
|
|
|
# And you can load it simply calling:
|
2012-03-26 12:20:32 +02:00
|
|
|
# $ load-env-sdl
|
2012-03-15 00:07:59 +01:00
|
|
|
# and this will update your env vars to have 'make' and 'gcc' finding the SDL
|
|
|
|
# headers and libs.
|
2008-10-10 00:57:20 +02:00
|
|
|
|
2012-03-14 19:59:09 +01: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
|
2017-05-27 12:33:22 +02:00
|
|
|
# full ~/.config/nixpkgs/config.nix
|
2008-10-10 00:57:20 +02:00
|
|
|
{
|
|
|
|
packageOverrides = pkgs : with pkgs; with sourceAndTags;
|
2012-03-14 19:59:09 +01:00
|
|
|
let complicatedMyEnv = { name, buildInputs ? [], cTags ? [], extraCmds ? ""}:
|
2008-10-10 00:57:20 +02:00
|
|
|
pkgs.myEnvFun {
|
|
|
|
inherit name;
|
|
|
|
buildInputs = buildInputs
|
2012-03-14 19:59:09 +01:00
|
|
|
++ map (x : sourceWithTagsDerivation
|
|
|
|
( (addCTaggingInfo x ).passthru.sourceWithTags ) ) cTags;
|
2008-10-10 00:57:20 +02:00
|
|
|
extraCmds = ''
|
|
|
|
${extraCmds}
|
|
|
|
HOME=${builtins.getEnv "HOME"}
|
|
|
|
. ~/.bashrc
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in rec {
|
2012-03-14 19:46:18 +01:00
|
|
|
# this is the example we will be using
|
2012-03-14 19:59:09 +01:00
|
|
|
nixEnv = complicatedMyEnv {
|
|
|
|
name = "nix";
|
2016-11-01 04:10:13 +01:00
|
|
|
buildInputs = [ libtool stdenv perl curl bzip2 openssl db5 autoconf automake zlib ];
|
2012-03-14 19:46:18 +01:00
|
|
|
};
|
2008-10-10 00:57:20 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-03-20 15:51:18 +01: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-10 00:57:20 +02:00
|
|
|
|
2012-03-26 12:20:32 +02:00
|
|
|
# You can load the environment simply typing a "load-env-${name}" command.
|
|
|
|
# $ load-env-nix
|
2012-03-20 15:51:18 +01:00
|
|
|
# The result using that command should be:
|
|
|
|
# env-nix loaded
|
2012-03-20 19:49:44 +01:00
|
|
|
and show you a shell with a prefixed prompt.
|
2008-10-10 00:57:20 +02:00
|
|
|
*/
|
|
|
|
|
2012-05-25 19:53:37 +02:00
|
|
|
{ mkDerivation, substituteAll, pkgs }:
|
|
|
|
{ stdenv ? pkgs.stdenv, name, buildInputs ? []
|
2014-12-17 19:11:30 +01:00
|
|
|
, propagatedBuildInputs ? [], gcc ? stdenv.cc, cTags ? [], extraCmds ? ""
|
2013-10-04 10:02:30 +02:00
|
|
|
, cleanupCmds ? "", shell ? "${pkgs.bashInteractive}/bin/bash --norc"}:
|
2012-05-25 19:53:37 +02:00
|
|
|
|
2008-10-10 00:57:20 +02:00
|
|
|
mkDerivation {
|
2017-09-05 17:34:53 +02:00
|
|
|
inherit buildInputs propagatedBuildInputs;
|
2012-05-25 19:53:37 +02:00
|
|
|
|
2008-10-10 00:57:20 +02:00
|
|
|
name = "env-${name}";
|
2012-02-29 13:55:51 +01:00
|
|
|
phases = [ "buildPhase" "fixupPhase" ];
|
2008-10-10 00:57:20 +02:00
|
|
|
setupNew = substituteAll {
|
2009-04-28 18:52:36 +02:00
|
|
|
src = ../../stdenv/generic/setup.sh;
|
2012-05-25 19:53:37 +02:00
|
|
|
inherit gcc;
|
2008-10-10 00:57:20 +02:00
|
|
|
};
|
2011-03-27 16:08:13 +02:00
|
|
|
|
2014-11-25 14:05:21 +01:00
|
|
|
buildPhase = let
|
|
|
|
initialPath = import ../../stdenv/common-path.nix { inherit pkgs; };
|
|
|
|
in ''
|
2008-10-10 00:57:20 +02:00
|
|
|
set -x
|
2012-02-29 13:55:51 +01:00
|
|
|
mkdir -p "$out/dev-envs" "$out/nix-support" "$out/bin"
|
2008-10-10 00:57:20 +02: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 14:05:21 +01:00
|
|
|
-e '1i initialPath="${toString initialPath}"' \
|
|
|
|
"$setupNew" > "$s"
|
2008-10-10 00:57:20 +02:00
|
|
|
cat >> "$out/dev-envs/''${name/env-/}" << EOF
|
2016-03-09 12:40:17 +01:00
|
|
|
defaultNativeBuildInputs="$defaultNativeBuildInputs"
|
2017-09-05 17:34:53 +02:00
|
|
|
buildInputs="$buildInputs"
|
|
|
|
propagatedBuildInputs="$propagatedBuildInputs"
|
2008-10-10 00:57:20 +02: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 10:54:56 +01:00
|
|
|
# This prevents having -rpath /lib in NIX_LDFLAGS
|
|
|
|
export NIX_NO_SELF_RPATH=1
|
2009-02-11 17:12:12 +01:00
|
|
|
if [[ -z "\$ZSH_VERSION" ]]; then
|
|
|
|
source "$s"
|
|
|
|
else
|
|
|
|
setopt interactivecomments
|
2009-02-11 17:12:14 +01:00
|
|
|
# fix bash indirection
|
2009-02-11 17:12:12 +01: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 02:01:22 +01:00
|
|
|
${pkgs.coreutils}/bin/rm -fr "\$tmp"
|
2008-10-10 00:57:20 +02:00
|
|
|
${extraCmds}
|
2013-04-13 19:10:50 +02:00
|
|
|
|
|
|
|
nix_cleanup() {
|
2013-05-14 18:59:50 +02:00
|
|
|
:
|
2013-04-13 19:10:50 +02:00
|
|
|
${cleanupCmds}
|
|
|
|
}
|
|
|
|
|
2008-10-10 00:57:20 +02:00
|
|
|
export PATH
|
2015-03-20 14:50:34 +01:00
|
|
|
echo $name loaded >&2
|
2013-04-13 19:10:50 +02:00
|
|
|
|
|
|
|
trap nix_cleanup EXIT
|
2008-10-10 00:57:20 +02:00
|
|
|
EOF
|
2012-02-29 13:55:51 +01:00
|
|
|
|
2012-03-20 19:49:44 +01:00
|
|
|
mkdir -p $out/bin
|
2013-10-04 10:02:30 +02: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 12:20:32 +02:00
|
|
|
chmod +x $out/bin/load-env-${name}
|
2008-10-10 00:57:20 +02:00
|
|
|
'';
|
|
|
|
}
|