summary refs log tree commit diff
path: root/pkgs/development/compilers/ghcs/default.nix
blob: fbc2bdd1f9d676698f51636c6e2714905a309c00 (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{ ghcPkgUtil, gnum4, perl, ghcboot, stdenv, fetchurl, recurseIntoAttrs, gmp, readline, lib, annotatedDerivations, hasktags, ctags } : 
with annotatedDerivations;
rec {
  
  /* What's in here?
     Goal:  really pure GHC. This means put every library into its each package.conf
     and add all together using GHC_PACKAGE_PATH

     First I've tried separating the build of ghc from it's lib. It hase been to painful. I've failed.
     Now there is nix_ghc_pkg_tool.hs which just takes the installed package.conf
     and creates a new package db file for each contained package.

     The final attribute set looks similar to this:
     ghc, core_libs and extra_libraries will then be used to build all the ohter packages availible on hackege..
     (There is much left to be done)

     ghcAndLibraries =  {
      ghc68 = {
        ghc = {
          src = "The compiler source"
          extra_src =  "source of extra libraries"
          version = "GHC version as string"
        }

        core_libs = [ libs distributed the ghc core (see libraries/core-packages ];
        extra_libraries = [ libraries contained extra_src ];
     };

     ghc66 = {
       roughly the same
     };
    }

  */

  #this only works for ghc-6.8 right now
  ghcAndLibraries = { version, src /* , core_libraries, extra_libraries  */
                    , extra_src }:
                   recurseIntoAttrs ( rec {
    inherit src extra_src version;

    ghc = stdenv.mkDerivation {
      name = "ghc-"+version;
      inherit src ghcboot gmp version;

      buildInputs = [readline perl gnum4 gmp];

      preConfigure = "
        chmod u+x rts/gmp/configure
        # still requires a hack for ncurses
        sed -i \"s|^\(library-dirs.*$\)|\1 \\\"$ncurses/lib\\\"|\" libraries/readline/package.conf.in
      ";

      # TODO add unique (filter duplicates?) shouldn't be there? 
      nix_ghc_pkg_tool = ./nix_ghc_pkg_tool.hs;

      configurePhase = "./configure"
       +" --prefix=\$out "
       +" --with-ghc=\$ghcboot/bin/ghc"
       +" --with-gmp-libraries=$gmp/lib"
       +" --with-gmp-includes=${gmp}/include"
       +" --with-readline-libraries=\"$readline/lib\"";

      # now read the main package.conf and create a single package db file for each of them
      # Also create setup hook.

      #  note : I don't know yet wether it's a good idea to have RUNGHC.. It's faster
      # but you can't pass packages, can you?
      postInstall = "
        cp \$nix_ghc_pkg_tool nix_ghc_pkg_tool.hs
        \$out/bin/ghc-\$version --make -o nix_ghc_pkg_tool  nix_ghc_pkg_tool.hs;
        ./nix_ghc_pkg_tool split \$out/lib/ghc-\$version/package.conf \$out/lib/ghc-\$version
        cp nix_ghc_pkg_tool \$out/bin

        if test -x \$out/bin/runghc; then
          RUNHGHC=\$out/bin/runghc # > ghc-6.7/8 ?
        else
          RUNHGHC=\$out/bin/runhaskell # ghc-6.6 and prior 
        fi

        ensureDir \$out/nix-support
        sh=\$out/nix-support/setup-hook
        echo \"RUNHGHC=\$RUNHGHC\" >> \$sh
        
      ";
    };

    core_libs = rec {
        #   name (using lowercase letters everywhere because using installing packages having different capitalization is discouraged) - this way there is not that much to remember?

        cabal_darcs_name = "cabal-darcs";

        # introducing p here to speed things up.
        # It merges derivations (defined below) and additional inputs. I hope that using as few nix functions as possible results in greates speed?
        # unfortunately with x; won't work because it forces nix to evaluate all attributes of x which would lead to infinite recursion
        pkgs = let x = derivations; in {
            # ghc extra packages 
          cabal = { name = "cabal-1.2.3.0"; srcDir = "libraries/Cabal";
                          deps = [x.base x.pretty x.old_locale x.old_time
                            x.directory x.unix x.process x.array x.containers
                            x.rts x.filepath ]; };
          array = { name = "array-0.1.0.0"; srcDir = "libraries/array";
                          deps = [x.base ]; };
          base = { name = "base-3.0.1.0"; srcDir = "libraries/base";
                          deps = [x.rts ]; };
          bytestring = { name = "bytestring-0.9.0.1"; srcDir = "libraries/bytestring";
                          deps = [ x.base x.array ];};
          containers = { name = "containers-0.1.0.1"; srcDir = "libraries/containers";
                          deps = [ x.base x.array ];};
          directory = { name = "directory-1.0.0.0"; srcDir = "libraries/directory";
                          deps = [ x.base x.old_locale x.old_time x.filepath ];};
          filepath = { name = "filepath-1.1.0.0"; srcDir = "libraries/filepath";
                          deps = [ x.base ];};
          ghc = { name = "ghc-${version}"; srcDir = "libraries/Cabal";
                          deps = [ x.base x.old_locale x.old_time x.filepath
                            x.directory x.array x.containers x.hpc x.bytestring
                            x.pretty x.packedstring x.template_haskell x.unix
                            x.process x.readline x.cabal x.random x.haskell98 ]; };
          haskell98 = { name = "haskell98-1.0.1.0"; srcDir = "libraries/haskell98";
                          deps = [ x.base x.old_locale x.old_time x.filepath
                            x.directory x.random x.unix x.process x.array]; };
          hpc = { name = "hpc-0.5.0.0"; srcDir = "libraries/hpc";
                          deps = [ x.base x.old_locale x.old_time x.filepath
                            x.directory x.array x.containers ]; };
          old_locale = { name = "old-locale-1.0.0.0"; srcDir = "libraries/old-locale";
                          deps = [ x.base ]; };
          old_time = { name = "old-time-1.0.0.0"; srcDir = "libraries/old-time";
                          deps = [ x.base x.old_locale ];};
          packedstring = { name = "packedstring-0.1.0.0"; srcDir = "libraries/packedstring";
                          deps = [ x.base x.array ];};
          pretty = { name = "pretty-1.0.0.0"; srcDir = "libraries/pretty";
                          deps = [ x.base ];};
          process = { name = "process-1.0.0.0"; srcDir = "libraries/process";
                          deps = [ x.base x.old_locale x.old_time x.filepath
                            x.directory x.unix ]; };
          random = { name = "random-1.0.0.0"; srcDir = "libraries/random";
                          deps = [ x.base x.old_locale x.old_time ]; };
          readline = { name = "readline-1.0.1.0"; srcDir = "libraries/readline";
                          deps = [ x.base x.old_locale x.old_time x.filepath
                            x.directory x.unix x.process ];};
          rts = rec { 
                  name = "rts-1.0"; srcDir = "rts"; # TODO: Doesn't have .hs files so I should use ctags if creating tags at all
                  deps = [];
                  createTagFiles = [
                      { name = "${name}_haskell_tags";
                        tagCmd = "${toString ctags}/bin/ctags -R .;mv tags \$TAG_FILE"; }
                    ];
          };
          template_haskell = { name = "template-haskell-2.2.0.0"; srcDir = "libraries/template-haskell";
                          deps = [ x.base x.pretty x.array x.packedstring x.containers ];};
          unix = { name = "unix-2.3.0.0"; srcDir = "libraries/unix";
                          deps = [ x.base x.old_locale x.old_time x.filepath x.directory ];};
        };

        toDerivation = attrs : with attrs;
              rec {
                inherit name;

                #aDeps = concatLists ( catAttrs ( subsetmap id args [ "buildInputs" "propagatedBuildInputs" ] ) );
                aDeps = deps;

                # dummy derivation, only creates setup-hook for package database located in the ghc derivation 
                aDeriv = stdenv.mkDerivation {
                    inherit name;
                    phases = "buildPhase fixupPhase";
                    buildInputs = [ ghcPkgUtil ];
                    propagatedBuildInputs = [ ghc ] ++ map delAnnotation  attrs.deps;
                    buildPhase = "setupHookRegisteringPackageDatabase \"${ghc}/lib/ghc-${ghc.version}/${name}.conf\"";
                };

                sourceWithTags = {
                  src = ghc.src;
                  inherit srcDir;
                  name = name + "-src-with-tags";
                  createTagFiles = lib.maybeAttr "createTagFiles" [
                      { name = "${name}_haskell_tags";
                        tagCmd = "${toString hasktags}/bin/hasktags-modified --ctags `find . -type f -name \"*.*hs\"`; sort tags > \$TAG_FILE"; } 
                    ] attrs;
                };
          };
        derivations = with lib; builtins.listToAttrs (lib.concatLists ( lib.mapRecordFlatten 
                  ( n : attrs : let d = (toDerivation attrs); in [ (nv n d) (nv attrs.name d) ] ) pkgs ) );
    }.derivations;
  });

  ghc68 = ghcAndLibraries rec {
    version = "6.8.2";
    src = fetchurl {
      #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.0.20071004-src.tar.bz2;
      #sha256 = "1yyl7sxykmvkiwfxkfzpqa6cmgw19phkyjcdv99ml22j16wli63l";
      url = "http://www.haskell.org/ghc/dist/stable/dist/ghc-${version}-src.tar.bz2";
      md5 = "745c6b7d4370610244419cbfec4b2f84";
      #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.20070912-src.tar.bz2;
      #sha256 = "1b1gvi7hc7sc0fkh29qvzzd5lgnlvdv3ayiak4mkfnzkahvmq85s";
    };

    extra_src = fetchurl {
      url = "http://www.haskell.org/ghc/dist/stable/dist/ghc-${version}-src-extralibs.tar.bz2";
      sha256 = "044mpbzpkbxcnqhjnrnmjs00mr85057d123rrlz2vch795lxbkcn";
      #url = http://www.haskell.org/ghc/dist/stable/dist/ghc-6.8.20070912-src-extralibs.tar.bz2;
      #sha256 = "0py7d9nh3lkhjxr3yb3n9345d0hmzq79bi40al5rcr3sb84rnp9r";
    };
  };
}