1{
2 lib,
3 stdenv,
4 callPackage,
5 fetchFromGitHub,
6 makeWrapper,
7 wrapGAppsHook3,
8
9 withOpenGL ? !stdenv.hostPlatform.isDarwin,
10
11 bison,
12 blas,
13 cairo,
14 ffmpeg,
15 fftw,
16 flex,
17 freetype,
18 gdal,
19 geos,
20 lapack,
21 libGLU,
22 libiconv,
23 libpng,
24 libsvm,
25 libtiff,
26 libxml2,
27 llvmPackages,
28 netcdf,
29 pdal,
30 pkg-config,
31 libpq,
32 proj,
33 python3Packages,
34 readline,
35 sqlite,
36 wxGTK32,
37 zlib,
38 zstd,
39}:
40
41stdenv.mkDerivation (finalAttrs: {
42 pname = "grass";
43 version = "8.4.1";
44
45 src = fetchFromGitHub {
46 owner = "OSGeo";
47 repo = "grass";
48 rev = finalAttrs.version;
49 hash = "sha256-q1jOimQi+24I1ZBf6Z0cvAyXcBFBpT5aWSNeG6n6y0k=";
50 };
51
52 nativeBuildInputs = [
53 makeWrapper
54 wrapGAppsHook3
55
56 bison
57 flex
58 gdal # for `gdal-config`
59 geos # for `geos-config`
60 netcdf # for `nc-config`
61 pkg-config
62 ]
63 ++ (with python3Packages; [
64 python-dateutil
65 numpy
66 wxpython
67 ]);
68
69 buildInputs = [
70 blas
71 cairo
72 ffmpeg
73 fftw
74 freetype
75 gdal
76 geos
77 lapack
78 libpng
79 libsvm
80 libtiff
81 libxml2
82 netcdf
83 pdal
84 libpq
85 proj
86 readline
87 sqlite
88 wxGTK32
89 zlib
90 zstd
91 ]
92 ++ lib.optionals withOpenGL [ libGLU ]
93 ++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]
94 ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ];
95
96 strictDeps = true;
97
98 configureFlags = [
99 "--with-blas"
100 "--with-cairo-ldflags=-lfontconfig"
101 "--with-cxx"
102 "--with-fftw"
103 "--with-freetype"
104 "--with-geos"
105 "--with-gdal"
106 "--with-lapack"
107 "--with-libsvm"
108 "--with-nls"
109 "--with-openmp"
110 "--with-pdal"
111 "--with-postgres"
112 "--with-postgres-libs=${libpq}/lib/"
113 "--with-proj-includes=${proj.dev}/include"
114 "--with-proj-libs=${proj}/lib"
115 "--with-proj-share=${proj}/share/proj"
116 "--with-sqlite"
117 "--with-zstd"
118 "--without-bzlib"
119 "--without-mysql"
120 "--without-odbc"
121 ]
122 ++ lib.optionals (!withOpenGL) [
123 "--without-opengl"
124 ]
125 ++ lib.optionals stdenv.hostPlatform.isDarwin [
126 "--without-cairo"
127 "--without-freetype"
128 "--without-x"
129 ];
130
131 # Otherwise a very confusing "Can't load GDAL library" error
132 makeFlags = lib.optional stdenv.hostPlatform.isDarwin "GDAL_DYNAMIC=";
133
134 /*
135 Ensures that the python script run at build time are actually executable;
136 otherwise, patchShebangs ignores them.
137 */
138 postConfigure = ''
139 for f in $(find . -name '*.py'); do
140 chmod +x $f
141 done
142
143 patchShebangs */
144 '';
145
146 postInstall = ''
147 wrapProgram $out/bin/grass \
148 --set PYTHONPATH $PYTHONPATH \
149 --set GRASS_PYTHON ${python3Packages.python.interpreter} \
150 --suffix LD_LIBRARY_PATH ':' '${gdal}/lib'
151 ln -s $out/grass*/lib $out/lib
152 ln -s $out/grass*/include $out/include
153 '';
154
155 enableParallelBuilding = true;
156
157 passthru.tests = {
158 grass = callPackage ./tests.nix { grass = finalAttrs.finalPackage; };
159 };
160
161 meta = with lib; {
162 description = "GIS software suite used for geospatial data management and analysis, image processing, graphics and maps production, spatial modeling, and visualization";
163 homepage = "https://grass.osgeo.org/";
164 license = licenses.gpl2Plus;
165 maintainers = with maintainers; [ mpickering ];
166 teams = [ teams.geospatial ];
167 platforms = platforms.all;
168 mainProgram = "grass";
169 };
170})