From beda5b3d8db782ce412bb3ac30a72353f7d87836 Mon Sep 17 00:00:00 2001 From: Ivan Mincik Date: Thu, 20 Jun 2024 08:17:11 +0000 Subject: [PATCH] packaging: Add Nix files for creating development environment and the package (#3889) --- .gitignore | 1 + flake.lock | 57 ++++++++++++++++++++ flake.nix | 80 ++++++++++++++++++++++++++++ package.nix | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/.gitignore b/.gitignore index 2cc7f3da721..0db3adb55f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /emacs.desktop *~ *.lock +!flake.lock *.pyc OBJ.* locale/scriptstrings/* diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..ff511760ebb --- /dev/null +++ b/flake.lock @@ -0,0 +1,57 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1717285511, + "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1717284937, + "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..d3d2b47e995 --- /dev/null +++ b/flake.nix @@ -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` + netcdf # for `nc-config` + pkg-config + ] ++ (with python3Packages; [ pytest python-dateutil numpy wxPython_4_2 ]) + + # from package buildInputs + ++ [ + blas + cairo + ffmpeg + fftw + freetype + gdal + geos + lapack + libGLU + libpng + libsvm + 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" + echo + echo "Note: run 'nix flake update' from time to time to update dependencies." + ''; + }; + }; + + flake = { }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 00000000000..2a5def372c2 --- /dev/null +++ b/package.nix @@ -0,0 +1,150 @@ +{ lib +, stdenv +, makeWrapper +, wrapGAppsHook + +, withOpenGL ? true + +, bison +, blas +, cairo +, ffmpeg +, fftw +, flex +, freetype +, gdal +, geos +, lapack +, libGLU +, libiconv +, libpng +, libsvm +, 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); + }; + + nativeBuildInputs = [ + makeWrapper + wrapGAppsHook + + bison + flex + gdal # for `gdal-config` + geos # for `geos-config` + netcdf # for `nc-config` + pkg-config + ] ++ (with python3Packages; [ python-dateutil numpy wxPython_4_2 ]); + + buildInputs = [ + blas + cairo + ffmpeg + fftw + freetype + gdal + geos + lapack + libpng + libsvm + libtiff + libxml2 + netcdf + pdal + postgresql + proj + readline + sqlite + wxGTK32 + zlib + zstd + ] ++ lib.optionals withOpenGL [ libGLU ] + ++ lib.optionals stdenv.isDarwin [ libiconv ]; + + strictDeps = true; + + configureFlags = [ + "--with-blas" + "--with-cairo-ldflags=-lfontconfig" + "--with-cxx" + "--with-fftw" + "--with-freetype" + "--with-geos" + "--with-gdal" + "--with-lapack" + "--with-libsvm" + "--with-nls" + "--with-openmp" + "--with-pdal" + "--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-sqlite" + "--with-zstd" + "--without-bzlib" + "--without-mysql" + "--without-odbc" + ] ++ lib.optionals (! withOpenGL) [ + "--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 scripts running 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"; + }; +})