Last active
October 5, 2024 16:42
-
-
Save hallundbaek/9579afad28970f984ccfbeafb68a8d2e to your computer and use it in GitHub Desktop.
A first attempt at creating a override for trying out the new FreeCAD 1.0rc1 on NixOS. Ideally the gtest should probably use the one from nixpkgs, but that resulted in issues that were easier solved by simply pulling the repo directly. Same goes for OndselSolver which should probably be its own package, alas I didn't do that.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkgs.freecad.overrideAttrs ( | |
final: prev: { | |
version = "1.0rc1"; | |
src = pkgs.fetchFromGitHub { | |
owner = "FreeCAD"; | |
repo = "FreeCAD"; | |
rev = "1.0rc1"; | |
hash = "sha256-bhRqWjYtwQ1mzZg03OmTFCt4eVgbc+YZnMNgwvRGvjc="; | |
}; | |
prePatch = | |
let | |
ondselSolver = pkgs.fetchFromGitHub { | |
owner = "Ondsel-Development"; | |
repo = "OndselSolver"; | |
rev = "6bf651cd31dfdcde8d6842b492b93d284f4579fe"; | |
hash = "sha256-ONxFATHIHKfzxDeIJlIMl2u/ZMahIk46+T2h4Ac+qrQ="; | |
}; | |
googletest = pkgs.fetchFromGitHub { | |
owner = "google"; | |
repo = "googletest"; | |
rev = "v1.15.2"; | |
hash = "sha256-1OJ2SeSscRBNr7zZ/a8bJGIqAnhkg45re0j3DtPfcXM="; | |
}; | |
in | |
prev.prePatch or "" | |
+ '' | |
cp -r ${ondselSolver}/* src/3rdParty/OndselSolver | |
chmod -R +w src/3rdParty/OndselSolver | |
cp -r ${googletest} tests/lib/googletest | |
echo "add_subdirectory(googletest)" > tests/lib/CMakeLists.txt | |
chmod -R +w tests/lib | |
''; | |
patches = [ ./NIXOS-don-t-ignore-PYTHONPATH-also-fix-ondsel-pc-paths.patch ]; | |
buildInputs = prev.buildInputs or [] ++ [ | |
pkgs.yaml-cpp | |
pkgs.microsoft-gsl | |
]; | |
cmakeFlags = prev.cmakeFlags or [] ++ [ | |
"-DINSTALL_TO_SITEPACKAGES:BOOL=OFF" | |
]; | |
preBuild = | |
prev.preBuild or "" | |
+ '' | |
export NIX_LDFLAGS="-L${pkgs.yaml-cpp}/lib $NIX_LDFLAGS"; | |
''; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/3rdParty/OndselSolver/OndselSolver.pc.in b/src/3rdParty/OndselSolver/OndselSolver.pc.in | |
index 076f352..4c94cdb 100644 | |
--- a/src/3rdParty/OndselSolver/OndselSolver.pc.in | |
+++ b/src/3rdParty/OndselSolver/OndselSolver.pc.in | |
@@ -1,7 +1,7 @@ | |
prefix=@CMAKE_INSTALL_PREFIX@ | |
exec_prefix=@CMAKE_INSTALL_PREFIX@ | |
-libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ | |
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ | |
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@ | |
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ | |
Name: @PROJECT_NAME@ | |
Description: @PROJECT_DESCRIPTION@ | |
@@ -9,4 +9,4 @@ Version: @PROJECT_VERSION@ | |
Requires: | |
Libs: -L${libdir} -lOndselSolver | |
-Cflags: -I${includedir} | |
\ No newline at end of file | |
+Cflags: -I${includedir} | |
diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp | |
index 2bdc54c..8fad746 100644 | |
--- a/src/Base/Interpreter.cpp | |
+++ b/src/Base/Interpreter.cpp | |
@@ -593,7 +593,7 @@ void initInterpreter(int argc, char* argv[]) | |
PyConfig config; | |
PyConfig_InitIsolatedConfig(&config); | |
config.isolated = 0; | |
- config.user_site_directory = 1; | |
+ config.use_environment = 1; | |
status = PyConfig_SetBytesArgv(&config, argc, argv); | |
if (PyStatus_Exception(status)) { | |
diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp | |
index 36087cf..89d49d2 100644 | |
--- a/src/Main/MainGui.cpp | |
+++ b/src/Main/MainGui.cpp | |
@@ -114,10 +114,8 @@ int main(int argc, char** argv) | |
// See https://forum.freecad.org/viewtopic.php?f=18&t=20600 | |
// See Gui::Application::runApplication() | |
putenv("LC_NUMERIC=C"); | |
- putenv("PYTHONPATH="); | |
#elif defined(FC_OS_MACOSX) | |
(void)QLocale::system(); | |
- putenv("PYTHONPATH="); | |
#elif defined(__MINGW32__) | |
const char* mingw_prefix = getenv("MINGW_PREFIX"); | |
const char* py_home = getenv("PYTHONHOME"); | |
@@ -125,7 +123,6 @@ int main(int argc, char** argv) | |
_putenv_s("PYTHONHOME", mingw_prefix); | |
} | |
#else | |
- _putenv("PYTHONPATH="); | |
// https://forum.freecad.org/viewtopic.php?f=4&t=18288 | |
// https://forum.freecad.org/viewtopic.php?f=3&t=20515 | |
const char* fc_py_home = getenv("FC_PYTHONHOME"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for making this override! I tried my hand at it previously, but got stuck on the Ondsel subrepository initialization step. Your gist was what I needed to get it done.
Here's a couple notes from my usage (NixOS, using
nixpkgs.overlays
):I had to convert the copied patch file to CRLF line endings, or else the patch would fail with
Hunk #1 FAILED at 114 (different line endings).
.I did so with
nix-shell -p dos2unix
followed byunix2dos NIXOS-don-t-ignore-PYTHONPATH-also-fix-ondsel-pc-paths.patch
and confirmingfile NIXOS-don-t-ignore-PYTHONPATH-also-fix-ondsel-pc-paths.patch
prints out a mention of "CRLF".Additionally the OndselSolver diff section should be LF only apparently. So I had to split that into a separate file and ensure it was LF with
dos2unix
.Had to add
patchFlags = [ "-p1" "--binary" ];
again for CRLF reasons (binary mode does not strip the CR )Final form when adding to
nixpkgs.overlays
was a bit modified, specifically references toprev
became references toold
:Then I used
freecad
as normal in myenvironment.systemPackages
:The build process was quite slow; I just let it run overnight and in the morning I had
1.0.0rc1
:)