← Back to issue list

snapcraft should use command-chain for hooks

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1824255
Type
issue
State
closed
Author
~anonymouse67
Labels
—
Created
Updated
Closed

Current evaluation

Fixed hook environment setup in merged #2897 (bfac28cea) by embedding the generated snap environment in hook wrappers; released in Snapcraft 3.10.

Resolution: closed resolved

Reason: Merged PR snapcore/snapcraft#2897, commit bfac28cea, restored environment setup for generated hook wrappers. The maintainer marked the issue Fix Committed and confirmed it was included in Snapcraft 3.10.

Evaluated by: mr-cal-bot

No scores available.

Issue body

During snap install, we commonly need to configure a generic config file that has invalid or dummy values built into the snap with runtime files and sometimes we need to use tools available in the core snap (i.e. sed, grep, awk) to do this such as jq, so we stage those tools into the snap. In normal snapcraft.yaml defined apps, the environment variables get setup such that we can just use "jq" in a shell script and it is on the $PATH with $LD_LIBRARY_PATH set appropriately, but we need to use jq from a hook and the environment variables aren't setup at all for hooks. This may be by design but is unfortunate as now we have code like this: ``` # add things from the snap's $PATH to here export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH" # setup LD_LIBRARY_PATH, we need to handle the different architecture paths - # this snippet is copied out of one of the generated snapcraft wrappers case $(arch) in x86_64) MULTI_ARCH_PATH="x86_64-linux-gnu";; arm*) MULTI_ARCH_PATH="arm-linux-gnueabihf";; aarch64) MULTI_ARCH_PATH="aarch64-linux-gnu";; *) echo "architecture $ARCH not supported" exit 1 ;; esac # Note - the env var SNAP_LIBRARY_PATH is set by snapd for hooks, so it can be referenced here export LD_LIBRARY_PATH="$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$MULTI_ARCH_PATH:$SNAP/usr/lib/$MULTI_ARCH_PATH" ``` It would be great if snapcraft or snapd could somehow facilitate adding generic boilerplate code like this for hooks. One easy way I think would be to have snapd gain support for command-chain for hooks like it does for apps today and then in the snap.yaml it would have a snapcraft generated hook that runs before the actual hook in the snap.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Fixed hook environment setup in merged #2897 (bfac28cea) by embedding the generated snap environment in hook wrappers; released in Snapcraft 3.10.
stealth/space-bunny-alpha — closed resolved Hook environment setup was restored by merged #2897 (bfac28cea), with the legacy counterpart in #2893; the fix shipped in Snapcraft 3.10. #2850 also enabled command-chain declarations.
stealth/space-bunny-alpha — closed not a bug Abandoned as handled elsewhere: hook command-chain support shipped in snapcraft#2850 (41c9fb464), followed by environment-aware hook wrappers in #2897.
qwen/qwen3.6-35b-a3b — — Abandoned. The proposal to use command-chain for hooks to automatically configure environment variables was closed without implementation or resolution.
qwen/qwen3.6-35b-a3b — — Proposal to use command-chain for snap hooks to automatically configure environment variables was closed without implementation or discussion. The feature remains unaddressed.
qwen/qwen3.6-35b-a3b — — Closed without implementation. The proposal to apply command-chain to hooks for automatic environment variable setup was abandoned after years of inactivity and zero discussion.
qwen3.6-35b-a3b-mtp-q6 — — Abandoned. The proposal to use command-chain for hooks to automatically configure PATH and LD_LIBRARY_PATH was closed without implementation or comments.

Update history

Date Change
created

Related work

  • Likely Fixed By: snapcore/snapcraft#2897 (confidence 100%)

    Merged fix included the generated snap environment in hook wrappers.

  • Likely Fixed By: snapcore/snapcraft#2893 (confidence 95%)

    Cited as the corresponding fix for legacy snaps without bases.

  • Related To: snapcore/snapcraft#2850 (confidence 90%)

    Added command-chain declarations in snapcraft.yaml, while #2897 resolved the reported environment regression.

Related issues

Issue Project State Summary Similarity
#3296 meta: write stubs for command-chain using hooks when needed snapcraft merged Merged #3296 in commit 95225991f, adding Snapcraft metadata generation of stub hooks for command-chain-based hooks.
77%
#1797468 Add support for hook command-chains snapcraft (launchpad) closed Hook command-chain support shipped in canonical/snapcraft#2850 (41c9fb464); LP #1797468 was later closed as stale after nearly eight years.
76%
#1848381 snapcraft doesn't allow setting the environment for hooks snapcraft (launchpad) closed Fixed by merged canonical/snapcraft#3565 (commit 79c5a5f0d), which added schema support for hook environment properties.
76%
#1973173 snapcraft 7.x/edge generates command-chain executables even when all apps and hooks use adapter:none snapcraft (launchpad) closed snapcraft 7.x/edge primed a command-chain wrapper even with all apps/hooks using adapter:none. Fixed by PR #3741 (commit ec190695c), released in snapcraft 7.0.1.
74%
#3741 parts: replace snapcraft command-chain with environment snapcraft merged Merged #3741 as ec190695c, replacing core22 snapcraft_runner command-chain handling with command-chain and global LD_LIBRARY_PATH/PATH defaults while deprecating adapter.
74%
#1794261 Put environment in command-chain instead of the opaque wrapper snapcraft (launchpad) closed Fixed by merged PR snapcore/snapcraft#2291 (commit e0f567833), moving plugin environments and runnables from opaque per-app wrappers into a dedicated runner.
71%
#1812003 hooks should be made executable instead of erroring out snapcraft (launchpad) closed Fixed by merged PR snapcore/snapcraft#2440 (commit c2f5a0dc0), which packages recognized hooks as executable instead of rejecting non-executable source files.
70%