diff --git a/pkgs/grass/default.nix b/pkgs/grass/default.nix index d27e21a..35b322b 100644 --- a/pkgs/grass/default.nix +++ b/pkgs/grass/default.nix @@ -90,7 +90,11 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; - patches = lib.optionals stdenv.isDarwin [ + patches = [ + # Backport of https://github.com/OSGeo/grass/pull/3899 + # by @landam . Remove for GRASS 8.5. + ./grass_config_dir.patch + ] ++ lib.optionals stdenv.isDarwin [ # Fix conversion of const char* to unsigned int. ./clang-integer-conversion.patch ]; diff --git a/pkgs/grass/grass_config_dir.patch b/pkgs/grass/grass_config_dir.patch new file mode 100644 index 0000000..799f6f1 --- /dev/null +++ b/pkgs/grass/grass_config_dir.patch @@ -0,0 +1,103 @@ +diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py +index 9c42a77487..eec3291242 100644 +--- a/gui/wxpython/core/utils.py ++++ b/gui/wxpython/core/utils.py +@@ -811,7 +811,9 @@ def GetSettingsPath(): + if sys.platform == "win32": + return os.path.join(os.getenv("APPDATA"), "GRASS%d" % version) + +- return os.path.join(os.getenv("HOME"), ".grass%d" % version) ++ return os.path.join( ++ os.getenv("GRASS_CONFIG_DIR") if os.getenv("GRASS_CONFIG_DIR") else os.getenv("HOME"), ++ ".grass%d" % version) + + + def StoreEnvVariable(key, value=None, envFile=None): +diff --git a/lib/gis/home.c b/lib/gis/home.c +index 166f6f2f19..e584a5e3c1 100644 +--- a/lib/gis/home.c ++++ b/lib/gis/home.c +@@ -100,6 +100,7 @@ const char *G_config_path(void) + static int initialized_config; + static const char *config_path = 0; + char buf[GPATH_MAX]; ++ static const char *config_dir = NULL; + + if (G_is_initialized(&initialized_config)) + return config_path; +@@ -107,7 +108,10 @@ const char *G_config_path(void) + #ifdef __MINGW32__ + sprintf(buf, "%s%c%s", getenv("APPDATA"), HOST_DIRSEP, CONFIG_DIR); + #else +- sprintf(buf, "%s%c%s", G_home(), HOST_DIRSEP, CONFIG_DIR); ++ config_dir = getenv("GRASS_CONFIG_DIR"); ++ if (!config_dir) ++ config_dir = G_home(); ++ sprintf(buf, "%s%c%s", config_dir, HOST_DIRSEP, CONFIG_DIR); + #endif + config_path = G_store(buf); + +diff --git a/lib/init/grass.py b/lib/init/grass.py +index 6d9d8b3b3e..fad0946d70 100755 +--- a/lib/init/grass.py ++++ b/lib/init/grass.py +@@ -351,6 +351,7 @@ Geographic Resources Analysis Support System (GRASS GIS). + FLAG {standard_flags} + + {env_vars}: ++ GRASS_CONFIG_DIR {config_dir_var} + GRASS_GUI {gui_var} + GRASS_HTML_BROWSER {html_var} + GRASS_ADDON_PATH {addon_path_var} +@@ -394,6 +395,7 @@ def help_message(default_gui): + mapset=_("initial GRASS mapset"), + full_mapset=_("fully qualified initial mapset directory"), + env_vars=_("Environment variables relevant for startup"), ++ config_dir_var=_("set root path for configuration directory"), + gui_var=_("select GUI (text, gui, gtext)"), + html_var=_("set html web browser for help pages"), + addon_path_var=_( +@@ -454,7 +456,9 @@ def get_grass_config_dir(): + directory = os.path.join(win_conf_path, grass_config_dirname) + else: + grass_config_dirname = f".grass{GRASS_VERSION_MAJOR}" +- directory = os.path.join(os.getenv("HOME"), grass_config_dirname) ++ directory = os.path.join( ++ os.getenv("GRASS_CONFIG_DIR") if os.getenv("GRASS_CONFIG_DIR") else os.getenv("HOME"), ++ grass_config_dirname) + if not os.path.isdir(directory): + try: + os.mkdir(directory) +diff --git a/lib/init/variables.html b/lib/init/variables.html +index 4c84a7803a..6fd10d7f17 100644 +--- a/lib/init/variables.html ++++ b/lib/init/variables.html +@@ -124,6 +124,13 @@ PERMANENT + available are RLE, ZLIB, and LZ4. The compressors BZIP2 and ZSTD + must be enabled when configuring GRASS for compilation. + ++