[Nix-dev] local, custom environments for development projects

Lluís Batlle i Rossell viric at viric.name
Sun Jan 22 12:53:11 CET 2012


On Sun, Jan 22, 2012 at 12:46:23PM +0100, Mathijs Kwik wrote:
> Hi all,
> 
> I'm doing some development work on different projects that all have
> their own dependencies.
> Currently (leftover from before nix), they are just directories in my homedir.
> There are some haskell projects, some ruby, few node.js.
> All these projects have their own dependencies, usually managed
> through a language's package manager (cabal, gem, npm), but
> occasionally needing native deps too (linking to c-based library,
> depend on binaries available in PATH, like imagemagick).
> As a result, my user environment (~/.nix-profile) contains a lot of
> stuff I don't really need, like stdenv, or tools only used by 1
> project.
> 
> I would like to have a way to setup special custom environments per project.
> I know for haskell there's hack-nix and there might be tricks for
> other languages/package managers as well, but I'm looking for a
> generic solution.
> 
> I thought of using a separate user per project and just su into that
> when starting development, but that's a bit too much.
> I would like to just "be" me when developing, being able to call my
> opened web browser, use ssh keys, use my shell aliasses and so on.
> Chrooting into an environment will probably have similar issues.
> 

I use 'myEnv', like this in packageOverrides:
      offrssEnv = pkgs.myEnvFun {
          name = "offrss";
          stdenv = ccacheStdenv;
          buildInputs = [ libmrss curl podofo ];
      };

      fossilEnvClang = pkgs.myEnvFun {
          name = "fossil-clang";
          buildInputs = [ clangStdenv zlib readline openssl ];
      };

...

I install them: "nix-env -i offrss-env"
And then I load them using this script I attach, with "loadenv offrss" for
example.

Regards,
Lluís.
-------------- next part --------------
#!/bin/sh

OLDPATH="$PATH"
OLDTZ="$TZ"
# set > var1
DIRNAME="`dirname $1`"
if [ "$DIRNAME" == "." ]; then
  source $HOME/.nix-profile/dev-envs/$1
else
  source $1
fi
# set > var2
PATH="$PATH:$OLDPATH"
export PS1="\n`basename $1`:[\u@\h:\w]\$ "
export buildInputs
export NIX_STRIP_DEBUG=0
export TZ="$OLDTZ"

exec /var/run/current-system/sw/bin/bash --norc


More information about the nix-dev mailing list