1 # idea: provide a build environments for your developement of preference
3 #### examples of use: ####
4 # Add this to your ~/.config/nixpkgs/config.nix:
6 packageOverrides = pkgs : with pkgs; {
7 sdlEnv = pkgs.myEnvFun {
9 nativeBuildInputs = [ cmake pkg-config ];
10 buildInputs = [ stdenv SDL SDL_image SDL_ttf SDL_gfx SDL_net];
15 # Then you can install it by:
16 # $ nix-env -i env-sdl
17 # And you can load it simply calling:
19 # and this will update your env vars to have 'make' and 'gcc' finding the SDL
22 ##### Another example, more complicated but achieving more: #######
23 # Make an environment to build nix from source and create ctags (tagfiles can
24 # be extracted from TAG_FILES) from every source package. Here would be a
25 # full ~/.config/nixpkgs/config.nix
27 packageOverrides = pkgs : with pkgs; with sourceAndTags;
28 let complicatedMyEnv = { name, buildInputs ? [], cTags ? [], extraCmds ? ""}:
31 buildInputs = buildInputs
32 ++ map (x : sourceWithTagsDerivation
33 ( (addCTaggingInfo x ).passthru.sourceWithTags ) ) cTags;
36 HOME=${builtins.getEnv "HOME"}
41 # this is the example we will be using
42 nixEnv = complicatedMyEnv {
44 buildInputs = [ libtool stdenv perl curl bzip2 openssl db5 autoconf automake zlib ];
49 # Now we should build our newly defined custom environment using this command on a shell, so type:
50 # $ nix-env -i env-nix
52 # You can load the environment simply typing a "load-env-${name}" command.
54 # The result using that command should be:
56 and show you a shell with a prefixed prompt.
68 propagatedBuildInputs ? [ ],
72 shell ? "${pkgs.bashInteractive}/bin/bash --norc",
76 inherit buildInputs propagatedBuildInputs;
83 setupNew = substituteAll {
84 src = ../../stdenv/generic/setup.sh;
90 initialPath = import ../../stdenv/generic/common-path.nix { inherit pkgs; };
94 mkdir -p "$out/dev-envs" "$out/nix-support" "$out/bin"
95 s="$out/nix-support/setup-new-modified"
96 # shut some warning up.., do not use set -e
97 sed -e 's@set -eu@@' \
98 -e 's@assertEnvExists\s\+NIX_STORE@:@' \
100 -e '1i initialPath="${toString initialPath}"' \
102 cat >> "$out/dev-envs/''${name/env-/}" << EOF
103 defaultNativeBuildInputs="$defaultNativeBuildInputs"
104 buildInputs="$buildInputs"
105 propagatedBuildInputs="$propagatedBuildInputs"
106 # the setup-new script wants to write some data to a temp file.. so just let it do that and tidy up afterwards
107 tmp="\$("${pkgs.coreutils}/bin/mktemp" -d)"
108 NIX_BUILD_TOP="\$tmp"
110 # only do all the setup stuff in nix-support/*
112 # This prevents having -rpath /lib in NIX_LDFLAGS
113 export NIX_NO_SELF_RPATH=1
114 if [[ -z "\$ZSH_VERSION" ]]; then
117 setopt interactivecomments
118 # fix bash indirection
119 # let's hope the bash arrays aren't used
120 # substitute is using bash array, so skip it
122 setopt NO_BAD_PATTERN
126 setopt NO_FUNCTION_ARGZERO
129 setopt INTERACTIVE_COMMENTS
133 setopt RM_STAR_SILENT
134 setopt POSIX_BUILTINS
135 setopt SH_FILE_EXPANSION
137 setopt SH_OPTION_LETTERS
140 sed -e 's/\''${!\([^}]*\)}/\''${(P)\1}/g' \
142 -e 's/substitute() {/ substitute() { return; /' \
143 -e 's@PATH=\$@PATH=${pkgs.coreutils}/bin@' \
144 "$s" >> "\$tmp/script"
146 source "\$tmp/script";
148 ${pkgs.coreutils}/bin/rm -fr "\$tmp"
157 echo $name loaded >&2
159 trap nix_cleanup EXIT
163 sed -e 's,@shell@,${shell},' -e s,@myenvpath@,$out/dev-envs/${name}, \
164 -e 's,@name@,${name},' ${./loadenv.sh} > $out/bin/load-env-${name}
165 chmod +x $out/bin/load-env-${name}