Skip to content

freecad: build with netgen enabled (fixes #382847)#408577

Open
eteq wants to merge 2 commits intoNixOS:masterfrom
eteq:fix-freecad
Open

freecad: build with netgen enabled (fixes #382847)#408577
eteq wants to merge 2 commits intoNixOS:masterfrom
eteq:fix-freecad

Conversation

@eteq
Copy link

@eteq eteq commented May 19, 2025

This is a fix to the freecad package.nix that I think closes #382847 - note that the first step that sent me down this path was from @dyfrgi
in #382847 (comment), so I added their commit from that comment as the first commit in this PR (credit where credit is due!).

Now the more iffy parts:

  • This is my first PR to nixos/nixpkgs/nix anything really... I did read through CONTRIBUTING but there's a lot there so I might need some handholding if I missed something important...
  • I don't really know how to do any testing for the problem this actually fixes. The core problem from freecad-wayland: The FEM module is built without NETGEN support. Meshing will not work!!! #382847 requires going through several GUI steps to trigger the error, and while I tested locally and this prevents the error, I don't have any idea how to add a regression test for that (or even if I'm supposed to...)
  • The python312 change was necessary for a lot of the freecad features (including but not exclusively the one in #freecad-wayland: The FEM module is built without NETGEN support. Meshing will not work!!! #382847), which is a bit mysterious because it seems unrelated... perhaps this implies the buildInputs should be python312 instead of python? But that might cause more mucking up of the dependency tree.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label May 19, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels May 19, 2025
@dyfrgi
Copy link
Contributor

dyfrgi commented May 19, 2025

Thanks for the credit! It's not necessary to use the commit, though, it's not formatted right for nixpkgs anyway. Plus it's clear from the followups that I missed several things. Thanks for following up on this bug!

Most of this will still be necessary with an update to 1.0.1.

I'm not a nixpkgs developer either, but I think the title of this PR should be a bit different. Something like "freecad: build with netgen enabled (#382847)" would likely be appropriate. I'd probably squash all the commits into one commit with the same title, too. Take a look at some recent commits to the repo to see the general idea.

Copy link
Contributor

@LordGrimmauld LordGrimmauld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple notes:
First of, welcome to nixpkgs 👋

Second, make sure nixpkgs isn't broken in intermediary commits. This ensures people later bisecting through nixpkgs don't get dropped into a broken state between your changes. For this, it might make sense to do two commits:

  • freecad: update python (contains the python312Packages bump)
  • freecad: enable netgen support (with a commit message body that points to the issue, and a short explanation why.)

Adding "-DBUILD_NETGEN=ON" in a commit without adding netgen to inputs would be broken. Remember that commits need to follow the pattern <package>: <change>. Similarly, the PR title should probably be freecad: add netgen support. I am not a committer, i can't force-edit your title.

Further: The python changes are fine. While technically python3Packages is preferred over python312Packages, we will soon bump python to point to 3.13 by default, which would break shiboken2 (see #407932). This means pinning to 3.12 until we drop Qt5 from freecad is a good idea, you did everything right.

@grimmauld-bot
Copy link

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 408577


aarch64-linux

✅ 3 packages built:
  • freecad
  • freecad-qt6
  • freecad-wayland

@grimmauld-bot
Copy link

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 408577


x86_64-linux

✅ 3 packages built:
  • freecad
  • freecad-qt6
  • freecad-wayland

@eteq eteq changed the title Fix freecad freecad: build with netgen enabled (#382847) May 23, 2025
eteq and others added 2 commits May 23, 2025 00:07
netgen and the FEM plugin's use of it wasn't being built, causing the
FEM plugin to fail  (NixOS#382847). This commit explicitly turns on them on
and adds netgen as a dependency.

Co-authored-by: Michael Leuchtenburg <michael@slashhome.org>
the freecad python deps are based on the python nix package, which was
updated to 3.12 but freecad's python deps were still 3.11.  This commit
updates the dependent packages to be for 3.12.
@eteq eteq changed the title freecad: build with netgen enabled (#382847) freecad: build with netgen enabled (fixes #382847) May 23, 2025
@eteq
Copy link
Author

eteq commented May 23, 2025

Alright I squashed to two commits along the lines of your suggestion, @LordGrimmauld, thanks for the review!

And in the netgen one I changed your status to co-author, @dyfrgi, which I think rightly reflects the work you did setting me down the path to finish the job.

Do I need to ping someone with merge rights too or just sit tight until they can get to this?

@LordGrimmauld
Copy link
Contributor

I adopted freecad in #408873, so technically i am package maintainer now. I rely on freecad for some aspects in my thesis, so i already noticed whenever it broke.
While i do not have merge permissions, at least this means you get a package maintainer approval - which typically does result in a merge within a few days.

@grimmauld-bot
Copy link

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 408577
Commit: 2485c747cc444bb13e98b004b0fac22244e61ee2


x86_64-linux

✅ 3 packages built:
  • freecad
  • freecad-qt6
  • freecad-wayland

@LordGrimmauld
Copy link
Contributor

LordGrimmauld commented May 23, 2025

image
The netgen menu does open, HOWEVER: Hitting apply results in a real nasty segfault:

Program received signal SIGSEGV, Segmentation fault.
#0  /nix/store/cg9s562sa33k78m63njfn1rw47dp9z0i-glibc-2.40-66/lib/libc.so.6(+0x41470) [0x7f4a57071470]
#1  0x7f4923b28323 in netgen::OCCGeometry::GetEdge(TopoDS_Shape const&) const from /nix/store/wldkbf7csbf8sdxq61slfpx17y65l8ih-netgen-6.2.2501/lib/libnglib.so+0x23
#2  0x7f4923b1e496 in netgen::OCCSetLocalMeshSize(netgen::OCCGeometry const&, netgen::Mesh&, netgen::MeshingParameters const&, netgen::OCCParameters const&) from /nix/store/wldkbf7csbf8sdxq61slfpx17y65l8ih-netgen-6.2.2501/lib/libnglib.so+0xc26
#3  0x7f49239f784d in netgen::NetgenGeometry::GenerateMesh(std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/wldkbf7csbf8sdxq61slfpx17y65l8ih-netgen-6.2.2501/lib/libnglib.so+0x63d
#4  0x7f4980e65e87 in netgen::OCCGenerateMesh(netgen::OCCGeometry&, std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/libNETGENPlugin.so+0x27
#5  0x7f4980e5acb1 in NETGENPlugin_Mesher::Compute() from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/libNETGENPlugin.so+0x391
#6  0x7f4980f7efac in Fem::FemMeshShapeNetgenObject::execute() from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/Fem.so+0x17c
#7  0x7f491dfbf9d0 in FemGui::TaskDlgMeshShapeNetgen::clicked(int) from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/FemGui.so+0x70
#8  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5(+0x334cde) [0x7f4a57a30cde]
#9  0x7f4a586c227f in QDialogButtonBox::clicked(QAbstractButton*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x3f
#10  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5(+0x31b971) [0x7f4a586c2971]
#11  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5(+0x334cb2) [0x7f4a57a30cb2]
#12  0x7f4a58611ce2 in QAbstractButton::clicked(bool) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x42
#13  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5(+0x26afda) [0x7f4a58611fda]
#14  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5(+0x26c925) [0x7f4a58613925]
#15  0x7f4a58613b74 in QAbstractButton::mouseReleaseEvent(QMouseEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x134
#16  0x7f4a5855bb98 in QWidget::event(QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x298
#17  0x7f4a585184ce in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x7e
#18  0x7f4a58520899 in QApplication::notify(QObject*, QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x13b9
#19  0x7f4a5b4f18f8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/libFreeCADGui.so+0xd8
#20  0x7f4a579f57d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5+0x128
#21  0x7f4a5851e91e in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool, bool) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x1be
#22  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5(+0x1cf0f6) [0x7f4a585760f6]
#23  /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5(+0x1d266f) [0x7f4a5857966f]
#24  0x7f4a585184ce in QApplicationPrivate::notify_helper(QObject*, QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Widgets.so.5+0x7e
#25  0x7f4a5b4f18f8 in Gui::GUIApplication::notify(QObject*, QEvent*) from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/libFreeCADGui.so+0xd8
#26  0x7f4a579f57d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5+0x128
#27  0x7f4a57e21383 in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Gui.so.5+0x923
#28  0x7f4a57df1574 in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Gui.so.5+0xb4
#29  /nix/store/m0mk8wjmpa08zz8zsm5cri0aqyvjj6fj-qtbase-5.15.16-bin/lib/qt-5.15.16/plugins/platforms/../../../../../x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5XcbQpa.so.5(+0x6de2a) [0x7f4a514b3e2a]
#30  /nix/store/bkpj51fz88rbyjd60i6lrp0xdax1b24g-glib-2.84.1/lib/libglib-2.0.so.0(+0x6181e) [0x7f4a531b881e]
#31  /nix/store/bkpj51fz88rbyjd60i6lrp0xdax1b24g-glib-2.84.1/lib/libglib-2.0.so.0(+0x63a90) [0x7f4a531baa90]
#32  /nix/store/bkpj51fz88rbyjd60i6lrp0xdax1b24g-glib-2.84.1/lib/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7f4a531bb2bc]
#33  0x7f4a57a53469 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5+0x69
#34  0x7f4a579f3ff2 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5+0x132
#35  0x7f4a579fcee2 in QCoreApplication::exec() from /nix/store/x39ids55l0q41haifyqgjkcalnah21b3-qtbase-5.15.16/lib/libQt5Core.so.5+0x92
#36  0x7f4a5b40af1f in Gui::Application::runApplication() from /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/lib/libFreeCADGui.so+0xbbf
#37  /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/bin/freecad() [0x407ce6]
#38  /nix/store/cg9s562sa33k78m63njfn1rw47dp9z0i-glibc-2.40-66/lib/libc.so.6(+0x2a47e) [0x7f4a5705a47e]
#39  /nix/store/cg9s562sa33k78m63njfn1rw47dp9z0i-glibc-2.40-66/lib/libc.so.6(__libc_start_main+0x89) [0x7f4a5705a539]
#40  /nix/store/7p308w4c1pasdwv95ql0rwam48mcd0hr-freecad-1.0.1/bin/freecad() [0x408055]

No other log output.
Interestingly, this is a qt segfault, not netgen. Nvm, thats just event handling, the crash happens in netgen.

@LordGrimmauld
Copy link
Contributor

LordGrimmauld commented May 23, 2025

Ah no, it is netgen, i can't read

@LordGrimmauld
Copy link
Contributor

strace says:

openat(AT_FDCWD, "/tmpNETGEN_3825524_190303824.out", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)

Might it be missing / somewhere in the code and it should open /tmp/NETGEN_3825524_190303824.out ?

@LordGrimmauld
Copy link
Contributor

LordGrimmauld added a commit to LordGrimmauld/FreeCAD that referenced this pull request May 23, 2025
Previously, FreeCAD attempted to write at apths in `/`,
such as `/tmpNETGEN_3825524_190303824.out`.
This was discovered while packaging netgen support for FreeCAD in nixpkgs [1].

The fix is trivial: Just add to `/tmp/` to actually be in the tmp directory.

[1] NixOS/nixpkgs#408577 (comment)
LordGrimmauld added a commit to LordGrimmauld/FreeCAD that referenced this pull request May 23, 2025
Previously, FreeCAD attempted to write at apths in `/`,
such as `/tmpNETGEN_3825524_190303824.out`.
This was discovered while packaging netgen support for FreeCAD in nixpkgs [1].

The fix is trivial: Just add to `/tmp/` to actually be in the tmp directory.

[1] NixOS/nixpkgs#408577 (comment)
@LordGrimmauld
Copy link
Contributor

I am currently testing this change - if it does work, you might want to cherry-pick LordGrimmauld@0a0a656 into here.

@dyfrgi
Copy link
Contributor

dyfrgi commented May 23, 2025

Nice find, @LordGrimmauld. That code hasn't changed in 9 years. I wonder why we're triggering the bug now and weren't before? There must be something in the way that code is called that changed without breaking any tests (are there tests for this?) and without anyone noticing.

In the original repo, that function looks different than it does here. In fact, it looked different to begin with - it calls a helper function from the SALOME kernel to get the base tmpdir.

I wonder if that function was not being called before?

@LordGrimmauld
Copy link
Contributor

I wonder if that function was not being called before?

I suspect people run freecad in containers a lot. Writing to / isn't much of an issue in flatpak i believe, fuse just hides that away? But indeed, this is a bit surprising. It might also just be noone was running netgen to start with...

@LordGrimmauld
Copy link
Contributor

Also, patching to /tmp/ still crashes despite the openat now returning a valid file descriptor, see FreeCAD/FreeCAD#21542 (comment)

@LordGrimmauld
Copy link
Contributor

Okay, i give up for now. Just a bunch of crashes and no sane way to debug...

@eteq
Copy link
Author

eteq commented Jun 1, 2025

Curiously, in my own testing I'm seeing a segfault at the same spot now (I could swear I wasn't initially, but I might be mis-remembering getting it to work on a non-nix install...), but I don't see any attempts to access /tmp* in my strace, @LordGrimmauld . What I do get as a stack trace that localizes the segfault to:

#0  /nix/store/cg9s562sa33k78m63njfn1rw47dp9z0i-glibc-2.40-66/lib/libc.so.6(+0x41470) [0x7f051ba41470]
#1  0x7f040b93c323 in netgen::OCCGeometry::GetEdge(TopoDS_Shape const&) const from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0x23
#2  0x7f040b932496 in netgen::OCCSetLocalMeshSize(netgen::OCCGeometry const&, netgen::Mesh&, netgen::MeshingParameters const&, netgen::OCCParameters const&) from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0xc26
#3  0x7f040b80b84d in netgen::NetgenGeometry::GenerateMesh(std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0x63d
#4  0x7f04bf55be87 in netgen::OCCGenerateMesh(netgen::OCCGeometry&, std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/ipvcprybfap6c1yarffqm8dhq7hmbyv6-freecad-1.0.0/lib/libNETGENPlugin.so+0x27
...

are you seeing a different stack trace, @LordGrimmauld, or were you not able to get debug symbols to get this in the first place (that is, I'm trying to figure out if segfault is separate from the /tmp... problem, or if this is somehow a problem in my local runtime/testing setup)

@LordGrimmauld
Copy link
Contributor

Curiously, in my own testing I'm seeing a segfault at the same spot now (I could swear I wasn't initially, but I might be mis-remembering getting it to work on a non-nix install...), but I don't see any attempts to access /tmp* in my strace, @LordGrimmauld . What I do get as a stack trace that localizes the segfault to:

#0  /nix/store/cg9s562sa33k78m63njfn1rw47dp9z0i-glibc-2.40-66/lib/libc.so.6(+0x41470) [0x7f051ba41470]
#1  0x7f040b93c323 in netgen::OCCGeometry::GetEdge(TopoDS_Shape const&) const from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0x23
#2  0x7f040b932496 in netgen::OCCSetLocalMeshSize(netgen::OCCGeometry const&, netgen::Mesh&, netgen::MeshingParameters const&, netgen::OCCParameters const&) from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0xc26
#3  0x7f040b80b84d in netgen::NetgenGeometry::GenerateMesh(std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/ggzwxvx2vmrd1ax1x9iymna9k7jwj5mw-netgen-6.2.2501/lib/libnglib.so+0x63d
#4  0x7f04bf55be87 in netgen::OCCGenerateMesh(netgen::OCCGeometry&, std::shared_ptr<netgen::Mesh>&, netgen::MeshingParameters&) from /nix/store/ipvcprybfap6c1yarffqm8dhq7hmbyv6-freecad-1.0.0/lib/libNETGENPlugin.so+0x27
...

are you seeing a different stack trace, @LordGrimmauld, or were you not able to get debug symbols to get this in the first place (that is, I'm trying to figure out if segfault is separate from the /tmp... problem, or if this is somehow a problem in my local runtime/testing setup)

its the same stack trace. And while i initially suspected the version comparison for smesh was broken (comparing strings against bitshifted numbers), fixing that also did not help. At which point i gave up.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 9, 2025
@LordGrimmauld LordGrimmauld mentioned this pull request Jun 14, 2025
13 tasks
@LordGrimmauld LordGrimmauld mentioned this pull request Aug 12, 2025
13 tasks
@LordGrimmauld LordGrimmauld mentioned this pull request Oct 13, 2025
13 tasks
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

freecad-wayland: The FEM module is built without NETGEN support. Meshing will not work!!!

8 participants