summary refs log tree commit diff
path: root/pkgs/applications/science/logic/monosat/default.nix
blob: fba3bc4790607bdec0df4c26a76de3236a20e628 (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
{ stdenv, fetchFromGitHub, cmake, zlib, gmp, jdk8,
  # The JDK we use on Darwin currenly makes extensive use of rpaths which are
  # annoying and break the python library, so let's not bother for now
  includeJava ? !stdenv.hostPlatform.isDarwin, includeGplCode ? true }:

with stdenv.lib;

let
  boolToCmake = x: if x then "ON" else "OFF";

  rev    = "2deeadeff214e975c9f7508bc8a24fa05a1a0c32";
  sha256 = "09yhym2lxmn3xbhw5fcxawnmvms5jd9fw9m7x2wzil7yvy4vwdjn";

  pname   = "monosat";
  version = substring 0 7 sha256;

  src = fetchFromGitHub {
    owner = "sambayless";
    repo  = pname;
    inherit rev sha256;
  };

  core = stdenv.mkDerivation {
    name = "${pname}-${version}";
    inherit src;
    buildInputs = [ cmake zlib gmp jdk8 ];

    cmakeFlags = [ "-DJAVA=${boolToCmake includeJava}" "-DGPL=${boolToCmake includeGplCode}" ];

    postInstall = optionalString includeJava ''
      mkdir -p $out/share/java
      cp monosat.jar $out/share/java
    '';

    passthru = { inherit python; };

    meta = {
      description = "SMT solver for Monotonic Theories";
      platforms   = platforms.unix;
      license     = if includeGplCode then licenses.gpl2 else licenses.mit;
      homepage    = https://github.com/sambayless/monosat;
      broken = true;
    };
  };

  python = { buildPythonPackage, cython }: buildPythonPackage {
    inherit pname version src;

    # The top-level "source" is what fetchFromGitHub gives us. The rest is inside the repo
    sourceRoot = "source/src/monosat/api/python/";

    propagatedBuildInputs = [ core cython ];

    # This tells setup.py to use cython
    MONOSAT_CYTHON = true;

    # The relative paths here don't make sense for our Nix build
    # Also, let's use cython since it should produce faster bindings
    # TODO: do we want to just reference the core monosat library rather than copying the
    # shared lib? The current setup.py copies the .dylib/.so...
    postPatch = ''

      substituteInPlace setup.py \
        --replace '../../../../libmonosat.dylib' '${core}/lib/libmonosat.dylib' \
        --replace '../../../../libmonosat.so'  '${core}/lib/libmonosat.so'
    '';
  };
in core