nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 cmake,
7 opencv4,
8 ceres-solver,
9 suitesparse,
10 metis,
11 eigen,
12 setuptools,
13 pkg-config,
14 pybind11,
15 numpy,
16 pyyaml,
17 lapack,
18 gtest,
19 gflags,
20 glog,
21 pytestCheckHook,
22 networkx,
23 pillow,
24 exifread,
25 gpxpy,
26 pyproj,
27 python-dateutil,
28 joblib,
29 repoze-lru,
30 xmltodict,
31 distutils,
32 cloudpickle,
33 scipy,
34 sphinx,
35 matplotlib,
36 fpdf,
37}:
38
39buildPythonPackage rec {
40 pname = "opensfm";
41 version = "unstable-2023-12-09";
42 pyproject = true;
43
44 src = fetchFromGitHub {
45 owner = "mapillary";
46 repo = "OpenSfM";
47 rev = "7f170d0dc352340295ff480378e3ac37d0179f8e";
48 sha256 = "sha256-l/HTVenC+L+GpMNnDgnSGZ7+Qd2j8b8cuTs3SmORqrg=";
49 };
50
51 patches = [
52 ./0002-cmake-find-system-distributed-gtest.patch
53 ./0003-cmake-use-system-pybind11.patch
54 ./0004-pybind_utils.h-conflicts-with-nixpkgs-pybind.patch
55 ./0005-fix-numpy-2-test-failures.patch # not upstreamed due to cla, but you're free upstream it -@pbsds
56 ./fix-scripts.patch
57 ];
58
59 postPatch = ''
60 substituteInPlace opensfm/src/CMakeLists.txt \
61 --replace-fail "cmake_minimum_required(VERSION 3.0)" "cmake_minimum_required(VERSION 3.10)"
62
63 rm opensfm/src/cmake/FindGlog.cmake
64 rm opensfm/src/cmake/FindGflags.cmake
65
66 # HAHOG is the default descriptor.
67 # We'll test both HAHOG and SIFT because this is
68 # where segfaults might be introduced in future
69 echo 'feature_type: SIFT' >> data/berlin/config.yaml
70 echo 'feature_type: HAHOG' >> data/lund/config.yaml
71
72 # make opensfm correctly import glog headers
73 export CXXFLAGS=-DGLOG_USE_GLOG_EXPORT
74
75 sed -i -e 's/^.*BuildDoc.*$//' setup.py
76 '';
77
78 build-system = [ setuptools ];
79
80 nativeBuildInputs = [
81 cmake
82 pkg-config
83 sphinx
84 ];
85
86 buildInputs = [
87 ceres-solver
88 suitesparse
89 metis
90 eigen
91 lapack
92 gflags
93 gtest
94 glog
95 pybind11
96 ];
97
98 dependencies = [
99 numpy
100 scipy
101 pyyaml
102 opencv4.cxxdev
103 networkx
104 pillow
105 matplotlib
106 fpdf
107 exifread
108 gpxpy
109 pyproj
110 python-dateutil
111 joblib
112 repoze-lru
113 xmltodict
114 cloudpickle
115 ];
116
117 nativeCheckInputs = [
118 pytestCheckHook
119 distutils
120 ];
121
122 dontUseCmakeBuildDir = true;
123 cmakeFlags = [
124 "-Bcmake_build"
125 "-Sopensfm/src"
126 ];
127
128 disabledTests = [
129 "test_run_all" # Matplotlib issues. Broken integration is less useless than a broken build
130 "test_match_candidates_from_metadata_bow" # flaky
131 ]
132 ++ lib.optionals stdenv.hostPlatform.isDarwin [
133 "test_reconstruction_incremental"
134 "test_reconstruction_triangulation"
135 ];
136
137 pythonImportsCheck = [ "opensfm" ];
138
139 meta = {
140 broken = stdenv.hostPlatform.isDarwin;
141 maintainers = [
142 lib.maintainers.pbsds
143 lib.maintainers.SomeoneSerge
144 ];
145 license = lib.licenses.bsd2;
146 changelog = "https://github.com/mapillary/OpenSfM/blob/${src.rev}/CHANGELOG.md";
147 description = "Open source Structure-from-Motion pipeline from Mapillary";
148 homepage = "https://opensfm.org/";
149 };
150}