···11+From c4f452ef6ae083ed21095313582f6d1bd775cbf3 Mon Sep 17 00:00:00 2001
22+From: Andreas Rammhold <andreas@rammhold.de>
33+Date: Thu, 2 Nov 2023 17:32:07 +0100
44+Subject: [PATCH] NIXOS: don't ignore PYTHONPATH
55+66+On NixOS or rather within nixpkgs we provide the runtime Python
77+packages via the PYTHONPATH environment variable. FreeCAD tries its
88+best to ignore Python environment variables that are being inherited
99+from the environment. For Python versions >=3.11 it also tries to
1010+initialize the interpreter config without any environmental data. We
1111+have to initialize the configuration *with* the information from the
1212+environment for our packaging to work.
1313+1414+Upstream has purposely isolated the environments AFAIK and thus
1515+shouldn't accept this patch (as is). What they might accept (once
1616+support for older Python versions has been dropped) is removing the
1717+PYTHONPATH specific putenv calls.
1818+---
1919+ src/Base/Interpreter.cpp | 2 +-
2020+ src/Main/MainGui.cpp | 3 ---
2121+ 2 files changed, 1 insertion(+), 4 deletions(-)
2222+2323+diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp
2424+index 52c47168af..9966bd0013 100644
2525+--- a/src/Base/Interpreter.cpp
2626++++ b/src/Base/Interpreter.cpp
2727+@@ -554,7 +554,7 @@ void initInterpreter(int argc,char *argv[])
2828+ {
2929+ PyStatus status;
3030+ PyConfig config;
3131+- PyConfig_InitIsolatedConfig(&config);
3232++ PyConfig_InitPythonConfig(&config);
3333+3434+ status = PyConfig_SetBytesArgv(&config, argc, argv);
3535+ if (PyStatus_Exception(status)) {
3636+diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp
3737+index 48ae847ef4..28813df383 100644
3838+--- a/src/Main/MainGui.cpp
3939++++ b/src/Main/MainGui.cpp
4040+@@ -112,17 +112,14 @@ int main( int argc, char ** argv )
4141+ // See https://forum.freecad.org/viewtopic.php?f=18&t=20600
4242+ // See Gui::Application::runApplication()
4343+ putenv("LC_NUMERIC=C");
4444+- putenv("PYTHONPATH=");
4545+ #elif defined(FC_OS_MACOSX)
4646+ (void)QLocale::system();
4747+- putenv("PYTHONPATH=");
4848+ #elif defined(__MINGW32__)
4949+ const char* mingw_prefix = getenv("MINGW_PREFIX");
5050+ const char* py_home = getenv("PYTHONHOME");
5151+ if (!py_home && mingw_prefix)
5252+ _putenv_s("PYTHONHOME", mingw_prefix);
5353+ #else
5454+- _putenv("PYTHONPATH=");
5555+ // https://forum.freecad.org/viewtopic.php?f=4&t=18288
5656+ // https://forum.freecad.org/viewtopic.php?f=3&t=20515
5757+ const char* fc_py_home = getenv("FC_PYTHONHOME");
5858+--
5959+2.42.0
6060+
+4-3
pkgs/applications/graphics/freecad/default.nix
···108108 qtx11extras
109109 ];
110110111111+ patches = [
112112+ ./0001-NIXOS-don-t-ignore-PYTHONPATH.patch
113113+ ];
114114+111115 cmakeFlags = [
112116 "-Wno-dev" # turns off warnings which otherwise makes it hard to see what is going on
113117 "-DBUILD_FLAT_MESH:BOOL=ON"
···127131 export NIX_LDFLAGS="-L${gfortran.cc}/lib64 -L${gfortran.cc}/lib $NIX_LDFLAGS";
128132 '';
129133130130- # Their main() removes PYTHONPATH=, and we rely on it.
131134 preConfigure = ''
132132- sed '/putenv("PYTHONPATH/d' -i src/Main/MainGui.cpp
133133-134135 qtWrapperArgs+=(--prefix PYTHONPATH : "$PYTHONPATH")
135136 '';
136137