-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
glycin-loaders: replace glycinPathsPatch with setup hook
#364572
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
883d3dd
glycin-loaders: don't use `with lib;`
pluiedev 30054bc
glycin-loaders: replace glycinPathsPatch with setup hook
pluiedev a6d1992
snapshot: don't use `with lib;`
pluiedev 2dd23b7
loupe: don't use `with lib;`
pluiedev 16ab70a
authenticator: remove unneeded glycin-loaders dependency
getchoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # glycin-loaders {#glycin-loaders-hook} | ||
|
|
||
| [Glycin](https://gitlab.gnome.org/GNOME/glycin) is a library for sandboxed and extendable image loading. | ||
|
|
||
| For most applications using it, individual image formats are loaded through binaries provided by `glycin-loaders`. The paths of these loaders must be injected into the environment via [`wrapGAppsHook`](#ssec-gnome-hooks). Likewise, `glycin` itself requires a patch to its internal sandbox in order to find certain binaries and understand the `/nix/store` model. | ||
|
|
||
| In Nixpkgs, this is all handled through the `glycin-loaders` setup hook. | ||
|
|
||
| ## Example code snippet {#glycin-loaders-hook-example-code-snippet} | ||
|
|
||
| ```nix | ||
| { | ||
| lib, | ||
| rustPlatform, | ||
| glycin-loaders, | ||
| wrapGAppsHook4, | ||
| }: | ||
|
|
||
| rustPlatform.buildRustPackage { | ||
| # ... | ||
|
|
||
| cargoHash = "..."; | ||
|
|
||
| nativeBuildInputs = [ wrapGAppsHook4 ]; | ||
|
|
||
| buildInputs = [ glycin-loaders ]; | ||
|
|
||
| # ... | ||
| } | ||
| ``` | ||
|
|
||
| ## Variables controlling glycin-loaders {#glycin-loaders-hook-variables-controlling} | ||
|
|
||
| ### `glycinCargoDepsPath` {#glycin-cargo-deps-path} | ||
|
|
||
| Path to a directory containing the `glycin` crate to patch. Defaults to the crate directory created by `cargoSetupHook`, or `./vendor/`. | ||
|
|
||
| ### `dontPatchGlycinLoaders` {#dont-patch-glycin} | ||
|
|
||
| Disables the patching of `glycin` crates in your Cargo dependencies. | ||
|
|
||
| ### `dontWrapGlycinLoaders` {#dont-wrap-glycin} | ||
|
|
||
| Disable adding the Glycin loaders path `XDG_DATA_DIRS` with `wrapGAppsHook`. |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| glycinLoadersPatchHook() { | ||
| echo "executing glycinLoadersPatchHook" | ||
|
|
||
| local glycinPath | ||
|
|
||
| if [[ -z ${glycinCargoDepsPath:-} ]]; then | ||
| # When cargoSetupHook is used, `cargoDepsCopy` would be set and preferred. | ||
| # Otherwise, fallback to vendor/ | ||
| local cargoDepsPath=${cargoDepsCopy:-vendor} | ||
| fi | ||
|
|
||
| while read -r path; do | ||
| # Ensure the paths we're patching exist (and that this crate probably isn't something like glycin-utils) | ||
| if [[ -f $path/src/sandbox.rs ]]; then | ||
| glycinPath="$path" | ||
| break | ||
| fi | ||
| done < <(find "$cargoDepsPath" -type d -name 'glycin*') | ||
|
|
||
| if [[ -z ${glycinPath:-} ]]; then | ||
| echo >&2 "error: glycin was not found within the cargo dependencies at '$cargoDepsPath'." | ||
| echo >&2 "are you sure glycin-loaders is still required?" | ||
| exit 1 | ||
| fi | ||
| echo "patching glycin crate at '$glycinPath'" | ||
|
|
||
| substituteInPlace "$glycinPath/src/sandbox.rs" \ | ||
| --replace-fail '"/usr"' '"/nix/store"' \ | ||
| --replace-fail '"bwrap"' '"@bwrap@"' | ||
|
|
||
| # Replace hash of file we patch in vendored glycin. | ||
| jq \ | ||
| --arg hash "$(sha256sum "$glycinPath/src/sandbox.rs" | cut -d' ' -f 1)" \ | ||
| '.files."src/sandbox.rs" = $hash' \ | ||
| "$glycinPath/.cargo-checksum.json" | | ||
| sponge "$glycinPath/.cargo-checksum.json" | ||
| } | ||
|
|
||
| glycinLoadersWrapperArgsHook() { | ||
| echo "executing glycinLoadersWrapperArgsHook" | ||
| gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "@out@/share") | ||
| } | ||
|
|
||
| if [[ -z ${dontPatchGlycinLoaders:-} ]]; then | ||
| prePatchHooks+=(glycinLoadersPatchHook) | ||
| fi | ||
|
|
||
| if [[ -z ${dontWrapGlycinLoaders:-} ]]; then | ||
| preFixupPhases+=(glycinLoadersWrapperArgsHook) | ||
| fi |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.