summaryrefslogtreecommitdiffstats
path: root/pkgs/misc/my-env/default.nix
blob: 2bf2d86c2c81ebae743111510e1092226aa57816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# idea: provide nix environment for your developement actions
# experimental

/*
  # example:
  # add postgresql to environment and create ctags (tagfiles can be extracted from TAG_FILES)
  # add this to your ~/.nixpkgs/config.nix

  {
    packageOverrides = pkgs : with pkgs; with sourceAndTags;
    let simple = { name, buildInputs ? [], cTags ? [], extraCmds ? ""}:
            pkgs.myEnvFun {
              inherit name;
            buildInputs = buildInputs 
                  ++ map (x : sourceWithTagsDerivation ( (addCTaggingInfo x ).passthru.sourceWithTags ) ) cTags;
            extraCmds = ''
              ${extraCmds}
              HOME=${builtins.getEnv "HOME"}
              . ~/.bashrc
            '';
          };
    in rec {
      nixEnv = simple {
       name = "nix";
       buildInputs = [ libtool stdenv perl curl bzip2 openssl aterm242fixes db45 autoconf automake zlib ];
       cTags = [ aterm242fixes];
      };
      [...]
    };
  }


  Put this into your .bashrc
    loadEnv(){ . "${HOME}/.nix-profile/dev-envs/${1}" }

  then nix-env -iA ...nixEnv
  and
  $ loadEnv postgresql

*/

{ mkDerivation, substituteAll, pkgs } : { stdenv ? pkgs.stdenv, name, buildInputs ? [], cTags ? [], extraCmds ? ""} :
mkDerivation {
  buildInputs = [ ] ++ buildInputs ;
  name = "env-${name}";
  phases = "buildPhase";
  setupNew = substituteAll {
    src = ../../stdenv/generic/setup-new.sh;
    preHook="";
    postHook="";
    initialPath= (import ../../stdenv/common-path.nix) { inherit pkgs; };
    gcc = stdenv.gcc;
  };
  buildPhase = ''
    set -x
    mkdir -p "$out/dev-envs" "$out/nix-support"
    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
      buildInputs="$buildInputs"
      # 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
      source "$s"
      rm -fr "\$tmp"
      ${extraCmds}
      export PATH
      echo $name loaded
    EOF
  '';
}