summaryrefslogtreecommitdiff
path: root/shell.nix
blob: 056cd5d47149c5d8160a458a705de5dcdce845ac (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
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
# From Mathieu's PR

# {ghc}:

# with import <nixpkgs> {};

# let
#   gfortranlibdir = "${gfortran7.cc.lib}";
#   # XXX Workaround https://ghc.haskell.org/trac/ghc/ticket/11042.
#   libHack = if stdenv.isDarwin then {
#       DYLD_LIBRARY_PATH = [gfortranlibdir];
#     } else {
#       LD_LIBRARY_PATH = [gfortranlibdir];
#     };
# in
# haskell.lib.buildStackProject ({
#   name = "haskell-sundials";
#   buildInputs = [blas liblapack sundials zlib];
#   inherit ghc;
#   # XXX Workaround https://ghc.haskell.org/trac/ghc/ticket/11042.
#   extraArgs = ["--extra-lib-dirs=${gfortranlibdir}"];
# } // libHack)
  

{ nixpkgs ? import <nixpkgs>
  {}
, compiler ? "ghc822"
, doBenchmark ? false }:

let

  inherit (nixpkgs) pkgs;

f = { mkDerivation, ad, base, diagrams-lib, diagrams-rasterific, gcc
    , hmatrix, hmatrix-gsl, HUnit, inline-c, plots, pretty, QuickCheck, stdenv, sundials, vector }:

mkDerivation {
  pname = "haskell-sundials";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  executableHaskellDepends = [
    ad
    base
    diagrams-lib
    diagrams-rasterific
    gcc
    hmatrix
    hmatrix-gsl
    HUnit
    inline-c
    plots
    QuickCheck
    pretty
    vector
  ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Cocoa] else []);
  executableSystemDepends = [
    pkgs.blas
    pkgs.liblapack
    patched-gsl
    sundials
    pkgs.zlib
  ] ++ (if pkgs.stdenv.isDarwin then [pkgs.darwin.apple_sdk.frameworks.Accelerate] else []);
  license = stdenv.lib.licenses.bsd3;
};

haskellPackages = if compiler == "default"
  then pkgs.haskellPackages
  else pkgs.haskell.packages.${compiler};

variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

patched-hmatrix = pkgs.haskellPackages.hmatrix.overrideAttrs (oldAttrs: rec {
  src = nixpkgs.fetchgit {
    url = git://github.com/albertoruiz/hmatrix;
    rev = "d83b17190029c11e3ab8b504e5cdc917f5863120";
    sha256 = "11wr59wg21rky59j3kkd3ba6aqns9gkh0r1fnhwhn3fp7zfhanqn";
  };
  postUnpack = ''
    sourceRoot=''${sourceRoot}/packages/base
    echo Source root reset to ''${sourceRoot}
  '';
});

patched-hmatrix-gsl = pkgs.haskellPackages.hmatrix-gsl.overrideAttrs (oldAttrs: rec {
  src = nixpkgs.fetchgit {
    url = git://github.com/albertoruiz/hmatrix;
    rev = "d83b17190029c11e3ab8b504e5cdc917f5863120";
    sha256 = "11wr59wg21rky59j3kkd3ba6aqns9gkh0r1fnhwhn3fp7zfhanqn";
  };
  postUnpack = ''
    sourceRoot=''${sourceRoot}/packages/gsl
    echo Source root reset to ''${sourceRoot}
  '';
});

patched-gsl = pkgs.gsl.overrideAttrs (oldAttrs: rec {
  src = nixpkgs.fetchgit {
    url = git://github.com/idontgetoutmuch/gsl;
    rev = "c2035977d65cd804169ff3370da6723cf879be75";
    sha256 = "1fqp77gp9nl3av1z58cwg8fivik4rff394wgjzc76ayd04y0d1k7";
    };
  version = "2.5";
  name = "gsl-${version}";
  doCheck = false;
  CFLAGS = "-DDEBUG";
});

drv = variant (haskellPackages.callPackage f {
  hmatrix = patched-hmatrix;
  hmatrix-gsl = patched-hmatrix-gsl;
});

in

  if pkgs.lib.inNixShell then drv.env else drv