10 # The JDK we use on Darwin currently makes extensive use of rpaths which are
11 # annoying and break the python library, so let's not bother for now
12 includeJava ? !stdenv.hostPlatform.isDarwin,
13 includeGplCode ? true,
17 boolToCmake = x: if x then "ON" else "OFF";
20 sha256 = "0q3a8x3iih25xkp2bm842sm2hxlb8hxlls4qmvj7vzwrh4lvsl7b";
25 src = fetchFromGitHub {
32 # Python 3.8 compatibility
34 url = "https://github.com/sambayless/monosat/commit/a5079711d0df0451f9840f3a41248e56dbb03967.patch";
35 sha256 = "1p2y0jw8hb9c90nbffhn86k1dxd6f6hk5v70dfmpzka3y6g1ksal";
39 # source behind __linux__ check assumes system is also x86 and
40 # tries to disable x86/x87-specific extended precision mode
41 # https://github.com/sambayless/monosat/issues/33
42 commonPostPatch = lib.optionalString (!stdenv.hostPlatform.isx86) ''
43 substituteInPlace src/monosat/Main.cc \
44 --replace 'defined(__linux__)' '0'
47 core = stdenv.mkDerivation {
48 name = "${pname}-${version}";
50 postPatch = commonPostPatch;
51 nativeBuildInputs = [ cmake ];
60 "-DJAVA=${boolToCmake includeJava}"
61 "-DGPL=${boolToCmake includeGplCode}"
63 # file RPATH_CHANGE could not write new RPATH
64 "-DCMAKE_SKIP_BUILD_RPATH=ON"
67 postInstall = lib.optionalString includeJava ''
68 mkdir -p $out/share/java
69 cp monosat.jar $out/share/java
72 passthru = { inherit python; };
75 description = "SMT solver for Monotonic Theories";
76 mainProgram = "monosat";
77 platforms = platforms.unix;
78 license = if includeGplCode then licenses.gpl2 else licenses.mit;
79 homepage = "https://github.com/sambayless/monosat";
80 maintainers = [ maintainers.acairncross ];
98 propagatedBuildInputs = [
103 # This tells setup.py to use cython, which should produce faster bindings
104 MONOSAT_CYTHON = true;
106 # After patching src, move to where the actually relevant source is. This could just be made
107 # the sourceRoot if it weren't for the patch.
111 cd src/monosat/api/python
114 # The relative paths here don't make sense for our Nix build
115 # TODO: do we want to just reference the core monosat library rather than copying the
116 # shared lib? The current setup.py copies the .dylib/.so...
118 substituteInPlace setup.py \
119 --replace 'library_dir = "../../../../"' 'library_dir = "${core}/lib/"'
122 nativeCheckInputs = [ pytestCheckHook ];
125 "test_assertAtMostOne"