Skip to content

Commit

Permalink
dev: Add Nix files for building dev environment and the package
Browse files Browse the repository at this point in the history
  • Loading branch information
imincik committed Jun 18, 2024
1 parent 5591ec8 commit 816549f
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 0 deletions.
25 changes: 25 additions & 0 deletions REQUIREMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ Note: also the respective development packages (commonly named `xxx-dev` or
on GitHub)
[https://subversion.apache.org/](https://subversion.apache.org/)

## Automatic development environment activation using Nix

- Install Nix
[(learn more about this installer)](https://zero-to-nix.com/start/install)

```bash
curl --proto '=https' --tlsv1.2 -sSf \
-L https://install.determinate.systems/nix \
| sh -s -- install
```

- Run following command in source code root directory

```bash
nix develop
```

- Optionally, use `direnv` to activate the environment automatically when
moving to the source code directory

```bash
echo "use flake" > .envrc
direnv allow
```

## Note

SUN Solaris users may go here to download precompiled libraries etc.:
Expand Down
57 changes: 57 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
description = "GRASS GIS";

nixConfig = {
bash-prompt = "\\[\\033[1m\\][grass-dev]\\[\\033\[m\\]\\040\\w >\\040";
};

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {

systems = [ "x86_64-linux" ];

perSystem = { config, self', inputs', pkgs, system, ... }: {

packages.grass = pkgs.callPackage ./package.nix { };

devShells.default = pkgs.mkShell {
buildInputs =
# from package nativeBuildInputs
with pkgs; [
bison
flex
gdal # for `gdal-config`
geos # for `geos-config`
libmysqlclient # for `mysql_config`
netcdf # for `nc-config`
pkg-config
] ++ (with python3Packages; [ pytest python-dateutil numpy wxPython_4_2 ])

# from package buildInputs
++ [
blas
cairo
ffmpeg
fftw
gdal
geos
libGLU
libmysqlclient
libpng
libtiff
libxml2
netcdf
pdal
postgresql
proj
readline
sqlite
wxGTK32
zlib
zstd
] ++ lib.optionals stdenv.isDarwin [ libiconv ];

shellHook = ''
echo -e "\nWelcome to a GRASS development environment !"
echo "Build GRASS using following commands:"
echo
echo " 1. ./configure --prefix=\$(pwd)/app"
echo " 2. make -j$(nproc)"
echo " 3. make install"
echo
echo "Run tests:"
echo
echo " 1. export PYTHONPATH=\$(app/bin/grass --config python_path):\$PYTHONPATH"
echo " 2. export LD_LIBRARY_PATH=\$(app/bin/grass --config path)/lib:\$LD_LIBRARY_PATH"
echo " 3. pytest"
# Force GRASS to create grassdata and config file in source code directory.
export HOME=$(pwd)
'';
};
};

flake = { };
};
}
143 changes: 143 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{ lib
, stdenv
, makeWrapper
, wrapGAppsHook

, bison
, blas
, cairo
, ffmpeg
, fftw
, flex
, gdal
, geos
, libiconv
, libmysqlclient
, libpng
, libtiff
, libxml2
, netcdf
, pdal
, pkg-config
, postgresql
, proj
, python3Packages
, readline
, sqlite
, wxGTK32
, zlib
, zstd
}:

stdenv.mkDerivation (finalAttrs: {
pname = "grass";
version = "dev";

src = lib.cleanSourceWith {
src = ./.;
filter = path: type:
! (lib.hasSuffix ".nix" path);
};

patches = lib.optionals stdenv.isDarwin [
# Fix conversion of const char* to unsigned int.
./clang-integer-conversion.patch
];

# Correct mysql_config query
postPatch = ''
substituteInPlace configure --replace "--libmysqld-libs" "--libs"
'';

nativeBuildInputs = [
makeWrapper
wrapGAppsHook

bison
flex
gdal # for `gdal-config`
geos # for `geos-config`
libmysqlclient # for `mysql_config`
netcdf # for `nc-config`
pkg-config
] ++ (with python3Packages; [ python-dateutil numpy wxPython_4_2 ]);

buildInputs = [
blas
cairo
ffmpeg
fftw
gdal
geos
libmysqlclient
libpng
libtiff
libxml2
netcdf
pdal
postgresql
proj
readline
sqlite
wxGTK32
zlib
zstd
] ++ lib.optionals stdenv.isDarwin [ libiconv ];

strictDeps = true;

configureFlags = [
"--with-blas"
"--with-geos"
# It complains about missing libmysqld but doesn't really seem to need it
"--with-mysql"
"--with-mysql-includes=${lib.getDev libmysqlclient}/include/mysql"
"--with-mysql-libs=${libmysqlclient}/lib/mysql"
"--with-netcdf"
"--with-postgres"
"--with-postgres-libs=${postgresql.lib}/lib/"
"--with-proj-includes=${proj.dev}/include"
"--with-proj-libs=${proj}/lib"
"--with-proj-share=${proj}/share/proj"
"--with-pthread"
"--with-readline"
"--without-opengl"
] ++ lib.optionals stdenv.isDarwin [
"--without-cairo"
"--without-freetype"
"--without-x"
];

# Otherwise a very confusing "Can't load GDAL library" error
makeFlags = lib.optional stdenv.isDarwin "GDAL_DYNAMIC=";

/* Ensures that the python script run at build time are actually executable;
* otherwise, patchShebangs ignores them. */
postConfigure = ''
for f in $(find . -name '*.py'); do
chmod +x $f
done
patchShebangs */
'';

postInstall = ''
wrapProgram $out/bin/grass \
--set PYTHONPATH $PYTHONPATH \
--set GRASS_PYTHON ${python3Packages.python.interpreter} \
--suffix LD_LIBRARY_PATH ':' '${gdal}/lib'
ln -s $out/grass*/lib $out/lib
ln -s $out/grass*/include $out/include
'';

enableParallelBuilding = true;

meta = with lib; {
description = "GIS software suite used for geospatial data management and analysis, image processing, graphics and maps production, spatial modeling, and visualization";
homepage = "https://grass.osgeo.org/";
license = licenses.gpl2Plus;
maintainers = with maintainers; teams.geospatial.members;
platforms = platforms.all;
mainProgram = "grass";
};
})

0 comments on commit 816549f

Please sign in to comment.