Skip to content

gtk3: fall back to packaged schemas for internal settings#507455

Open
ilkecan wants to merge 3 commits into
NixOS:stagingfrom
ilkecan:gtk3-hardcode-schemas
Open

gtk3: fall back to packaged schemas for internal settings#507455
ilkecan wants to merge 3 commits into
NixOS:stagingfrom
ilkecan:gtk3-hardcode-schemas

Conversation

@ilkecan

@ilkecan ilkecan commented Apr 7, 2026

Copy link
Copy Markdown
Member

follow up from: #271037

Summary

Some Qt applications in nixpkgs crash when Qt loads GTK integration and GTK tries to instantiate its own GSettings schemas, most visibly in the GTK file chooser path.

Typical failures look like:

  • Settings schema 'org.gtk.Settings.FileChooser' is not installed
  • No GSettings schemas are installed on the system

The root cause is that GTK 3 library code directly constructs GSettings objects for its own schemas, while those schemas live in package-specific paths in nixpkgs instead of a global location like /usr/share. wrapGAppsHook3 often masks the issue by extending XDG_DATA_DIRS, but Qt applications wrapped only with wrapQtAppsHook can still hit the crash depending on the runtime environment.

Solution

Patch GTK 3 itself so that when GTK asks for one of its own internal schemas, it:

  1. looks in the normal default schema source first
  2. if the schema is missing there, falls back to GTK's own packaged schema directory
  3. keeps the default schema source as the fallback source's parent so overrides and schema references continue to work

That parent relationship is intentional. It does not change the default-first lookup order, because the target schema is still looked up in the fallback source with recursive = FALSE, but it allows fallback-loaded schemas to resolve references through the default source1.

This covers the crash-relevant GTK library schemas:

  • org.gtk.Settings.FileChooser
  • org.gtk.Settings.ColorChooser
  • org.gtk.Settings.EmojiChooser

The fix is deliberately scoped to GTK's own internal schemas rather than arbitrary third-party schemas.

Default-first approach

A hardcoded-first patch would make GTK's packaged schema win even when the schema is already available through the normal default source, and it could weaken environment-driven override behavior. @jtojnar called this out on the earlier draft PR and suggested checking the default source first, then falling back to the hardcoded path only when needed. This PR follows that approach.

Automation

The PR also extends makeHardcodeGsettingsPatch with an opt-in default-first mode and uses it for gtk3 so future GTK updates can regenerate the patch without losing these semantics.

The generated patch currently also includes GTK demo and example callsites because the helper runs over the GTK source tree. Those hunks are not needed for the original Qt crash, but they are harmless and kept to avoid adding extra helper complexity in this change.

Testing

I tested 3 previously crashing applications against the patched gtk3:

  • brewtarget2 no longer crashed when run with a deliberately stripped XDG_DATA_DIRS, while the unpatched nixpkgs build still did
  • scribus3 also stopped crashing on startup, while the unpatched nixpkgs (nixos-25.11) build still crashed
  • ovito doesn't crash when launching filechooser with these changes. confirmed the crash on master.

You can download the pre-built ovito from this PR to test:

nix-store -r /nix/store/04czs9mrbmhzdlwspw8i2r0wc1nqn90n-ovito-3.15.2/bin/ovito \
  --option substituters 'https://ilkecan.cachix.org https://cache.nixos.org/' \
  --option trusted-public-keys '
  ilkecan.cachix.org-1:hXb7Vo9EzaXiEb0elvG6Tt5TrP3zrcadyoX8c+lbeCY=
  cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
  '

Follow-up cleanup

After this lands, we should audit recent wrapGAppsHook3 additions on Qt packages and remove the ones that were only added to work around GTK's internal schema lookup failures. This should be done selectively, since some packages may still need wrapGAppsHook3 for unrelated runtime data.

Relevant issues & PRs (not comprehensive)

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Footnotes

  1. https://docs.gtk.org/gio/ctor.SettingsSchemaSource.new_from_directory.html#description

  2. tested before https://github.com/NixOS/nixpkgs/commit/e7b6af9d4f189e1fc58eec32c01529dc6a05fe43 landed

  3. tested before https://github.com/NixOS/nixpkgs/commit/23b5ac11e2181d087c884c6426591d7fdeb0962b

ilkecan and others added 3 commits April 6, 2026 21:43
Some Qt applications load GTK 3 through Qt's GTK platform theme and
crash when GTK's own schemas are not visible through XDG_DATA_DIRS. This
happens most visibly in the file chooser path when apps are wrapped with
wrapQtAppsHook but not wrapGAppsHook3.

Look up the normal default schema source first so environment-based
overrides keep working, then fall back to GTK's own packaged schema
directory for FileChooser, ColorChooser, and EmojiChooser.

Co-authored-by: Jan Tojnar <jtojnar@gmail.com>
The existing generator always prefers the hardcoded schema directory and
only uses the default schema source as a parent. Some consumers, such as
`gtk3`, need the opposite precedence so environment-driven overrides
continue to work.

Add an opt-in `preferDefaultSchemaSource` mode that first looks up the
schema in the default source and only falls back to the hardcoded
directory when it is missing there. Keep the current hardcoded-first
behavior as the default and cover the new mode with a fixture test.
Use `makeHardcodeGsettingsPatch` with the new default-first lookup mode
and fold patch regeneration into `updateScript`.

The generated patch currently covers the full GTK source tree, so the
checked-in patch now includes the demo and example schema callsites
again in addition to the library callsites that motivated the original
fix.

Co-authored-by: Jan Tojnar <jtojnar@gmail.com>
github-actions[bot]

This comment was marked as outdated.

@ilkecan ilkecan changed the base branch from master to staging April 7, 2026 02:18
@nixpkgs-ci nixpkgs-ci Bot closed this Apr 7, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Apr 7, 2026
@ilkecan ilkecan requested a review from jtojnar April 7, 2026 02:21
@ilkecan ilkecan marked this pull request as ready for review April 7, 2026 02:22
@nixpkgs-ci nixpkgs-ci Bot requested review from a team and 7c6f434c April 7, 2026 02:23
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-darwin: 1001-2500 This PR causes many rebuilds on Darwin and should most likely target the staging branches. labels Apr 7, 2026
@nixos-discourse

Copy link
Copy Markdown

@das-g

das-g commented Apr 14, 2026

Copy link
Copy Markdown
Member

👍 This fixes the same problem for KMyMoney, too. See #509718 (comment)

@Gigahawk Gigahawk mentioned this pull request Jun 9, 2026
14 tasks
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: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants