Skip to content

makeBinaryWrapper: If prefix/suffix already exists, remove the original - #451031

Merged
K900 merged 1 commit into
NixOS:stagingfrom
SuperSamus:make-binary-wrapper-deduplicate
Dec 11, 2025
Merged

K900 merged 1 commit into
NixOS:stagingfrom
SuperSamus:make-binary-wrapper-deduplicate

Conversation

@SuperSamus

@SuperSamus SuperSamus commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor

This is mostly meant for wrapQtApps, which is why it's implemented only for makeBinaryWrapper.

Qt apps are often launched on top of each other, creating a problem: many of the paths in XDG_DATA_PATHS, QT_PLUGIN_PATH and NIXPKGS_QT6_QML_IMPORT_PATH become duplicated, and these envars are already massive by themselves without this problem.
Starting KDE Plasma, and most paths are seen twice. Open Konsole, and it becomes three times. If it was opened with CTRL+ALT+T, four times.
Why is this a problem?

  • The more these paths are duplicated, the slower it becomes to copy the envars, and for the programs to parse them.
  • Some programs are buggy and malfunction if the environment variable block is too big. For instance, the EA App (via Wine) is unable to launch games if there are more than 32768 characters in the block, a number easily surpassable due to this problem.1
  • It's ugly typing env and seeing this massive wall of duplicated paths.

Because there is no reason for the same path to appear multiple times, this change removes a path if it's already in the list, adding it back to the start or the end.

Notes

I am unable to locally test this change due to the massive amount of rebuilds.

I did test the functionality of the C code outside nixpkgs.
In terms of performance, I tested adding new paths with both the old and new algorithm, and there is no measurable difference: it's basically dependent only on the length of the string, meaning that performance should be improved thanks to the deduplication.
If the path does exist, the algorithm is fast: I tested calling set_env_prefix and set_env_suffix back and forth with the same value (80 characters long) 1000 times, on an environment variable that is 3000 characters long: it takes only about 1.5 ms.

(Also, should this change apply only to the prefix and not the suffix?)

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.

Add a 👍 reaction to pull requests you find important.

Footnotes

  1. The problem is with the EA App itself, not Wine (the issue is also on Windows). I tried to contact EA, and obviously they ignored me. ↩

This is mostly meant for `wrapQtApps`, which is why it's implemented only for `makeBinaryWrapper`.
Qt apps are often launched on top of each other, creating a problem: many of the paths in `XDG_DATA_PATHS`, `QT_PLUGIN_PATH` and `NIXPKGS_QT6_QML_IMPORT_PATH` become duplicated, and these envars are already massive by themselves without this problem.
Starting KDE Plasma, and most paths are seen twice. Open Konsole, and it becomes three times. If it was opened with CTRL+ALT+T, four times.
Why is this a problem?
- The more these paths are duplicated, the slower it becomes to copy the envars, and for the programs to parse them.
- Some programs are buggy and malfunction if the environment variable block is too big. For instance, the EA App (via Wine) is unable to launch games if there are more than 32768 characters in the block, a number easily surpassable due to this problem.
- It's ugly typing `env` and seeing this massive wall of duplicated paths.

Because there is no reason for the same path to appear multiple times, this change removes a path if it's already in the list, adding it back to the start or the end.
@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-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. labels Oct 11, 2025
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/6044

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/6065

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/6119

@SuperSamus

Copy link
Copy Markdown
Contributor Author

Small note about the EA App, the latest version of Wine intentionally doesn't import some environment variables in order to dampen the issue. But everything else still stands.

@K900
K900 added this pull request to the merge queue Dec 11, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 11, 2025
@SuperSamus

Copy link
Copy Markdown
Contributor Author

@K900 eval failed because #469928 wasn't merged yet.

@K900
K900 added this pull request to the merge queue Dec 11, 2025
Merged via the queue into NixOS:staging with commit 0fdcb95 Dec 11, 2025
@SuperSamus
SuperSamus deleted the make-binary-wrapper-deduplicate branch February 3, 2026 14:36
@K900 K900 mentioned this pull request Feb 7, 2026
3 of 13 tasks
nixos-cuda-channel-updater Bot pushed a commit to nixos-cuda/nixpkgs that referenced this pull request Jul 31, 2026
0fdcb95 (makeBinaryWrapper: If prefix/suffix already exists, remove
the original (NixOS#451031), 2025-12-11) changed the C code generated by
makeBinaryWrapper.  The tests for makeBinaryWrapper check the exact code
that's generated, so they need updating.

Fixes NixOS#505339.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 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