1{
2 lib,
3 stdenv,
4 wrapQtAppsHook,
5 fetchFromGitHub,
6 unstableGitUpdater,
7 cmake,
8 ninja,
9 pkg-config,
10 eigen_3_4_0,
11 zlib,
12 libpng,
13 boost,
14 guile,
15 python3,
16 qtbase,
17}:
18
19stdenv.mkDerivation {
20 pname = "libfive";
21 version = "0-unstable-2025-07-23";
22
23 src = fetchFromGitHub {
24 owner = "libfive";
25 repo = "libfive";
26 rev = "e8370983e7bc6d49409affcc34fc70c673cc876f";
27 hash = "sha256-Jtf3yEnIySsLdSt5G3VdU3nUV55LHnES23fCAilXjNw=";
28 };
29
30 nativeBuildInputs = [
31 wrapQtAppsHook
32 cmake
33 ninja
34 pkg-config
35 python3.pkgs.pythonImportsCheckHook
36 ];
37 buildInputs = [
38 eigen_3_4_0
39 zlib
40 libpng
41 boost
42 guile
43 python3
44 qtbase
45 ];
46
47 preConfigure = ''
48 substituteInPlace studio/src/guile/interpreter.cpp \
49 --replace '"libfive/bind/guile"' \
50 '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"' \
51 --replace '(app_resource_dir + ":" + finder_build_dir).toLocal8Bit()' \
52 '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"'
53
54 substituteInPlace libfive/bind/guile/CMakeLists.txt \
55 --replace "LIBFIVE_FRAMEWORK_DIR=$<TARGET_FILE_DIR:libfive>" \
56 "LIBFIVE_FRAMEWORK_DIR=$out/lib" \
57 --replace "LIBFIVE_STDLIB_DIR=$<TARGET_FILE_DIR:libfive-stdlib>" \
58 "LIBFIVE_STDLIB_DIR=$out/lib"
59
60 substituteInPlace libfive/bind/python/CMakeLists.txt \
61 --replace ' ''${PYTHON_SITE_PACKAGES_DIR}' \
62 " $out/${python3.sitePackages}" \
63
64 substituteInPlace libfive/bind/python/libfive/ffi.py \
65 --replace "os.path.join('libfive', folder)" \
66 "os.path.join('$out/${python3.sitePackages}/libfive', folder)" \
67
68 export XDG_CACHE_HOME=$(mktemp -d)/.cache
69 '';
70
71 cmakeFlags = [
72 "-DGUILE_CCACHE_DIR=${placeholder "out"}/${guile.siteCcacheDir}"
73 ];
74
75 env = lib.optionalAttrs stdenv.cc.isClang {
76 NIX_CFLAGS_COMPILE = "-Wno-error=enum-constexpr-conversion";
77 };
78
79 postInstall =
80 lib.optionalString stdenv.hostPlatform.isDarwin ''
81 # No rules to install the mac app, so do it manually.
82 mkdir -p $out/Applications
83 cp -r studio/Studio.app $out/Applications/Studio.app
84
85 install_name_tool -add_rpath $out/lib $out/Applications/Studio.app/Contents/MacOS/Studio
86
87 makeWrapper $out/Applications/Studio.app/Contents/MacOS/Studio $out/bin/Studio
88 ''
89 + ''
90 # Link "Studio" binary to "libfive-studio" to be more obvious:
91 ln -s "$out/bin/Studio" "$out/bin/libfive-studio"
92
93 # Create links since libfive looks for the library in a specific path.
94 mkdir -p "$out/${python3.sitePackages}/libfive/src"
95 ln -s "$out"/lib/libfive.* "$out/${python3.sitePackages}/libfive/src/"
96 mkdir -p "$out/${python3.sitePackages}/libfive/stdlib"
97 ln -s "$out"/lib/libfive-stdlib.* "$out/${python3.sitePackages}/libfive/stdlib/"
98
99 # Create links so Studio can find the bindings.
100 mkdir -p "$out/libfive/bind"
101 ln -s "$out/${python3.sitePackages}" "$out/libfive/bind/python"
102 '';
103
104 pythonImportsCheck = [
105 "libfive"
106 "libfive.runner"
107 "libfive.shape"
108 "libfive.stdlib"
109 ];
110
111 passthru.updateScript = unstableGitUpdater {
112 tagFormat = "";
113 };
114
115 meta = with lib; {
116 description = "Infrastructure for solid modeling with F-Reps in C, C++, and Guile";
117 homepage = "https://libfive.com/";
118 maintainers = with maintainers; [
119 hodapp
120 kovirobi
121 wulfsta
122 ];
123 license = with licenses; [
124 mpl20
125 gpl2Plus
126 ];
127 platforms = with platforms; all;
128 };
129}