1{ lib, stdenv, fetchFromGitHub, flex, bison, pkg-config, zlib, libtiff, libpng, fftw
2, cairo, readline, ffmpeg, makeWrapper, wxGTK32, libiconv, netcdf, blas
3, proj, gdal, geos, sqlite, postgresql, libmysqlclient, python3Packages, proj-datumgrid
4, zstd, pdal, wrapGAppsHook
5}:
6
7stdenv.mkDerivation rec {
8 pname = "grass";
9 version = "8.2.1";
10
11 src = with lib; fetchFromGitHub {
12 owner = "OSGeo";
13 repo = "grass";
14 rev = version;
15 hash = "sha256-U3PQd3u9i+9Bc7BSd0gK8Ss+iV9BT1xLBDrKydtl3Qk=";
16 };
17
18 nativeBuildInputs = [
19 pkg-config bison flex makeWrapper wrapGAppsHook
20 gdal # for `gdal-config`
21 geos # for `geos-config`
22 netcdf # for `nc-config`
23 libmysqlclient # for `mysql_config`
24 pdal # for `pdal-config`; remove with next version, see https://github.com/OSGeo/grass/pull/2851
25 ] ++ (with python3Packages; [ python-dateutil numpy wxPython_4_2 ]);
26
27 buildInputs = [
28 cairo zlib proj libtiff libpng fftw sqlite
29 readline ffmpeg postgresql blas wxGTK32
30 proj-datumgrid zstd
31 gdal
32 geos
33 netcdf
34 libmysqlclient
35 pdal
36 ] ++ lib.optionals stdenv.isDarwin [ libiconv ];
37
38 strictDeps = true;
39
40 # On Darwin the installer tries to symlink the help files into a system
41 # directory
42 patches = [ ./no_symbolic_links.patch ];
43
44 # Correct mysql_config query
45 patchPhase = ''
46 substituteInPlace configure --replace "--libmysqld-libs" "--libs"
47 '';
48
49 configureFlags = [
50 "--with-proj-share=${proj}/share/proj"
51 "--with-proj-includes=${proj.dev}/include"
52 "--with-proj-libs=${proj}/lib"
53 "--without-opengl"
54 "--with-readline"
55 "--with-wxwidgets"
56 "--with-netcdf"
57 "--with-geos"
58 "--with-postgres"
59 "--with-postgres-libs=${postgresql.lib}/lib/"
60 # it complains about missing libmysqld but doesn't really seem to need it
61 "--with-mysql"
62 "--with-mysql-includes=${lib.getDev libmysqlclient}/include/mysql"
63 "--with-mysql-libs=${libmysqlclient}/lib/mysql"
64 "--with-blas"
65 "--with-zstd"
66 "--with-fftw"
67 "--with-pthread"
68 ] ++ lib.optionals stdenv.isLinux [
69 "--with-pdal"
70 ] ++ lib.optionals stdenv.isDarwin [
71 "--without-cairo"
72 "--without-freetype"
73 "--without-x"
74 ];
75
76 # Otherwise a very confusing "Can't load GDAL library" error
77 makeFlags = lib.optional stdenv.isDarwin "GDAL_DYNAMIC=";
78
79 /* Ensures that the python script run at build time are actually executable;
80 * otherwise, patchShebangs ignores them. */
81 postConfigure = ''
82 for f in $(find . -name '*.py'); do
83 chmod +x $f
84 done
85
86 patchShebangs */
87 '';
88
89 postInstall = ''
90 wrapProgram $out/bin/grass \
91 --set PYTHONPATH $PYTHONPATH \
92 --set GRASS_PYTHON ${python3Packages.python.interpreter} \
93 --suffix LD_LIBRARY_PATH ':' '${gdal}/lib'
94 ln -s $out/grass*/lib $out/lib
95 ln -s $out/grass*/include $out/include
96 '';
97
98 enableParallelBuilding = true;
99
100 meta = {
101 homepage = "https://grass.osgeo.org/";
102 description = "GIS software suite used for geospatial data management and analysis, image processing, graphics and maps production, spatial modeling, and visualization";
103 license = lib.licenses.gpl2Plus;
104 platforms = lib.platforms.all;
105 maintainers = with lib.maintainers; [ mpickering willcohen ];
106 };
107}