8000 sdl{2-compat,3}: clean up dependencies by LordGrimmauld · Pull Request #414472 · NixOS/nixpkgs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sdl{2-compat,3}: clean up dependencies #414472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2025
Merged

Conversation

LordGrimmauld
Copy link
Contributor

Tray support in sdl3 is nice, but completely unsupported by SDL2. Thus, it makes little sense to pull in all the dependencies needed for tray into sdl2-compat.

Similarly, both sdl2 and sdl3 support zenity as a dialog backend. This is optional, and will by default only be used if dbus/portal backend fails. The classic SDL2 technically supported zenity upstream, but we never enabled that support. Similarly, sdl3 supports zenity, but our implementation was broken, always returning zenity was not available. Zenity can still be made available, either by setting the override or adding zenity to $PATH in a wrapper of a consumer package.

While testing these, i needed the installed-tests output to execute the test binaries in an interactive session.
It might make sense to use the installedTests output e.g. in a VM test to make sure these override interfaces don't break.

I also found ibus support requires dbus support and added an assertion for that.

This is currently a draft: I am not yet entirely decided on some aspects, and i would like to write VM tests for these things. sdl3 also still depends on libdecor which in turn pulls in gtk3 into the closure. Arguably this is fine: SDL2_classic also depended on libdecor, and the closure size was still acceptable. But, if there is a reasonable way to drop it, we wouldn't need any gtk for the sdl going into ffmpeg, which could be nice!

cc @NixOS/sdl, feedback welcome

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.

The `installedTests` contains various test binaries,
some of which only useful on a running system.
Motivation for providing this output is to eventually test
tray support in a VM test, which needs a running dbus session.
@LordGrimmauld LordGrimmauld changed the base branch from master to staging June 6, 2025 09:44
@nixpkgs-ci nixpkgs-ci bot closed this Jun 6, 2025
@nixpkgs-ci nixpkgs-ci bot reopened this Jun 6, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 1001-2500 This PR causes many rebuilds on Darwin and should most likely target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 2501-5000 This PR causes many rebuilds on Linux and should target the staging branches. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. labels Jun 6, 2025
Copy link
Member
@pbsds pbsds left a comment

Choose a reason for hiding this comment

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

I'm generally onboard with the goal and approach 👍
The VM test could be done here, in a followup or maybe not at all. I don't think dropping libdecor from the closure is feasible on linux given the stance of gtk, unless of course we resort to patching it to dlopen a magical /run path like graphics does. That however makes it way less usable on FHS distros

waylandSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
x11Support ? !stdenv.hostPlatform.isAndroid && !stdenv.hostPlatform.isWindows,
zenitySupport ? false, # sdl3 will default to dbus and fail gracefully if zenity is not available.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe provide an alternative for those who consider using an override

Suggested change
zenitySupport ? false, # sdl3 will default to dbus and fail gracefully if zenity is not available.
zenitySupport ? false, # sdl3 will default to dbus and fail gracefully if zenity is not available. sdl3 can still use zenity if available in PATH.

Copy link
Member

Choose a reason for hiding this comment

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

perhaps also this, considering this is about hermeticity and not support

Suggested change
zenitySupport ? false, # sdl3 will defa 8000 ult to dbus and fail gracefully if zenity is not available.
withZenity ? false, # sdl3 will default to dbus and fail gracefully if zenity is not available.

discussed in NixOS/rfcs#169 although not merged or active

Copy link
Contributor Author

Choose a reason for hiding this comment

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

valid argument, done.

@LordGrimmauld
Copy link
Contributor Author

libdecor only uses gtk3 for a plugin - it could be argued the plugin being searched in /run/current-system (or some other path) would be the expected behavior. Or, we might not even need that plugin, if that is only relevant for outdated gnome (needs testing). I did expect that one to be by far the most complex.

@LordGrimmauld LordGrimmauld force-pushed the sdl-tray-flag branch 2 times, most recently from 351c266 to aa521da Compare June 6, 2025 13:28
Copy link
Contributor
@marcin-serwin marcin-serwin left a comment

Choose a reason for hiding this comment

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

The original motivation behind the zenity dependency was not the general dialog handler but the Wayland_ShowMessageBox function. It is called when the library initialization failed for some reason and it always uses zenity, it can't use dbus since dbus may not be initialized. If the zenity fails to launch the user will just see nothing in such cases. That being said, I'm still in favor of removing it since the closure size reduction is significant.

As for the libdecor, after skimming the source I think we could build the gtk plugin in a separate derivation and then point LIBDECOR_PLUGIN_DIR to it in the wrapGAppsHook. That way gtk apps and sessions could still rely on it. The downside is that the plugin will be added as a dependency even to apps that don't use libdecor but I think it's preferable compared to every libdecor dependent having gtk3 in its closure.

Comment on lines 57 to 59
# sdl3 will default to dbus and fail gracefully if zenity is not available.
# sdl3 can still use zenity if available in $PATH
withZenity ? false,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are defaulting it to false then I would drop this entirely: It is much easier to provide it via PATH than to recompile the whole package just to replace some strings.

@LordGrimmauld
Copy link
Contributor Author

Ah, indeed, simple message box now fails, and adding zenity to path makes it work:
image

the relevant code is in https://github.com/libsdl-org/SDL/blob/7dd5e765df239986f78c9b0016e3f3023d885084/src/video/wayland/SDL_waylandvideo.c#L681-L693 for the wayland driver.

However:
Because of https://github.com/libsdl-org/SDL/blob/7dd5e765df239986f78c9b0016e3f3023d885084/src/video/wayland/SDL_waylandmessagebox.h#L27, it actually becomes external API, which means the assumption "not needed when we have dbus" is invalid. That is kinda ugly....

About libdecor: good point. Would that be wrapGAppsHook3-only, or gtk4 too?
And: Do you want to take a look at that, or do you want me to poke when i have time?

@LordGrimmauld
Copy link
Contributor Author

I suppose we should then keep zenity default-enabled then... But then the actual question is, does sdl2-compat message box call the sdl3 zenity-backed message box?

SDL2_classic did have the zenity logic: https://github.com/libsdl-org/SDL/blob/341629636681f88fac444b92a3d2cbf8e88cf065/src/video/wayland/SDL_waylandmessagebox.c#L55
But, we never enabled that in nixpkgs, and apparently nothing broke. So i am a little confused about what is going on.

Is this just bad maintenance of SDL before we picked it up, or is this actually not needed?

@LordGrimmauld
Copy link
Contributor Author

Apparently SDL2-era we just had programs do wrapping for zenity:

Not sure this is the ideal solution...

@LordGrimmauld
Copy link
Contributor Author

only SDL_messagebox.h ends up in the include directory, but i have yet to check whether it can use different backends than just zenity.

@marcin-serwin
Copy link
Contributor

About libdecor: good point. Would that be wrapGAppsHook3-only, or gtk4 too?

Not sure, I'm not very familiar with these hooks.

And: Do you want to take a look at that, or do you want me to poke when i have time?

I'll take a stab at it over the weekend.

I suppose we should then keep zenity default-enabled then...

Well, we have the option to just ignore it and hope the user has it in PATH. Arch doesn't list zenity in sdl3 deps, neither does Debian. It's also not mentioned anywhere in the SDL3 docs as a required dependency, you have to read the code to realize that it's actually required for this functionality. It's a subpar experience for Wayland users but it's an option.

only SDL_messagebox.h ends up in the include directory, but i have yet to check whether it can use different backends than just zenity.

If I recall correctly it'll call only zenity if the video driver is wayland. The issue with this interface is that it assumes that the OS provides some generic message box that can be used for catastrophic app failures. This is true for Windows, macOS or Android but on Linux this assumption fails. On X11 SDL3 draws a simple message box itself, on Wayland it hopes zenity is in PATH and on KMSDRM just does nothing. Not really sure if there's a principled fix for this.

@marcin-serwin
Copy link
Contributor

Possible long term solution: convince Freedesktop Group to add something like xdg-alert to the xdg-utils -> wait for all major distros to pick it up -> convince SDL authors to switch from zenity to xdg-alert.

@LordGrimmauld
Copy link
Contributor Author

Okay i just checked, i also missed the fact ibus has quite the long gtk dep chain.
In light of that, we shouldn't drop zenity tbh. Dropping tray from SDL2 is valid, and maybe making zenity an override flag for when we do drop it might be valid - but disabling it by default is too much for no real gain.
The libdecor thingy can also help in general, but that too won't drop gtk from sdl. So trying to do the zenity thing is probably not a good idea.

@marcin-serwin
Copy link
Contributor

In light of that, we shouldn't drop zenity tbh.

+1

maybe making zenity an override flag for when we do drop it might be valid

IMO this override just introduces needless complexity.

zenity is used not only for error reporting, but also for file
dialogs if dbus is disabled/unavailable. This needs a patched path too.
@LordGrimmauld LordGrimmauld marked this pull request as ready for review June 6, 2025 21:22
@LordGrimmauld
Copy link
Contributor Author
LordGrimmauld commented Jun 6, 2025

Alright, then there is not much more to be done here. VM test improvements is still on my list of things to do, but does not need to happen here. With zenity kept in the closure, these changes are pretty safe i believe.

lib.optionalString testSupport ''
substituteInPlace test/CMakeLists.txt \
--replace-fail 'set(noninteractive_timeout 10)' 'set(noninteractive_timeout 30)'

substituteInPlace test/testtray.c \
--replace-warn '../test/' '${placeholder "installedTests"}/share/assets/'
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for using --replace-warn instead of --replace-fail here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because its a test output. I believe the package shouldn't hard-fail if a test binary might not have built successfully, that is my reasoning. It should be loud enough to find if something goes wrong, but not be annoying when it breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

testtray is not part of our CI, so that one failing to replace doesn't actually affect anything.

Copy link
Contributor
@marcin-serwin marcin-serwin left a comment

Choose a reason for hiding this comment

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

Diff lgtm

@pbsds
Copy link
Member
pbsds commented Jun 7, 2025

builds on linux and darwin

@pbsds pbsds merged commit ce6542e into NixOS:staging Jun 7, 2025
19 of 24 checks passed
@marcin-serwin
Copy link
Contributor

As for the libdecor, after skimming the source I think we could build the gtk plugin in a separate derivation and then point LIBDECOR_PLUGIN_DIR to it in the wrapGAppsHook. That way gtk apps and sessions could still rely on it. The downside is that the plugin will be added as a dependency even to apps that don't use libdecor but I think it's preferable compared to every libdecor dependent having gtk3 in its closure.

To follow up on this because I got distracted: this approach is unfortunately not viable because sdl3 apps built without using wrapGAppsHook would still need the access to plugins dir to display decorations in compositors without server side decorations. Ideally LIBDECOR_PLUGIN_DIR would be set by the user session and perhaps we could even add it somewhere for NixOS but that doesn't help with FHS distros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 1001-2500 This PR causes many rebuilds on Darwin and should most likely target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 2501-5000 This PR causes many rebuilds on Linux and should target the staging branches. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0