Skip to content

Hook points ​

Your provision hook clones the repo. To put an SSH config, credential helper, or insteadOf rewrite in place before it runs, add a provision:before hook to a layer:

sh
cat > .paraspace/layers/project/hooks/provision:before <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
git config --global url."git@github.com:".insteadOf https://github.com/
EOF

When para runs provision, it first runs all provision:before hooks, then all provision hooks, then all provision:after hooks. Within each group, it runs hooks in stack order, starting with the top layer.

The same sequence applies to boot, image-build, and custom hooks called through "$PARA_RUN_HOOK". If a provision:before hook fails, para stops before running any provision hooks.

Run hooks before a specific operation ​

To run hooks immediately before cloning, add this call before the clone command:

sh
# .paraspace/layers/project/hooks/provision
"$PARA_RUN_HOOK" clone:before

This runs every clone:before hook at that point in the script. Custom hook points need no registration.

Define hooks/clone:before in any layer that needs to run code before cloning:

sh
cat > .paraspace/layers/project/hooks/clone:before <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
git config --global url."git@github.com:".insteadOf https://github.com/
EOF

If several layers define the same hook, para runs each implementation in stack order, starting with the top layer. This also applies to provision and boot. Keep each implementation independent so it works with different layer stacks.

Naming ​

para does not add another set of before/after calls to hooks whose names already end in :before or :after. For example, running provision:before does not trigger provision:before:before or provision:before:after.

provision, boot, and image-build are para's names. Every other name in hooks/ is yours.

Pass data between hooks ​

Hooks run in separate processes. When passing data between them:

  • Export variables needed by a called hook. An assignment such as repo_url=… is not available to child processes unless exported. Use a file for values that must persist after the hook finishes.

  • Pass required variables when switching users. su - and sudo can remove variables from the environment. For example:

    sh
    su - "$PARA_USER" -c "PARA_LAYER_DIR=$PARA_LAYER_DIR install-my-dotfiles"
  • Don't re-source ~/.paraspace/env inside a hook. It unsets $PARA_LAYER_DIR and $PARA_HOOK_CHAIN, removing the layer path and the call history used to detect recursion.

Reading a failure ​

para reports failures at each level of a nested hook call when hooks use set -e:

text
error: hook failed (exit 7): project/hooks/keys:setup
  chain: provision > clone:before > keys:setup
error: hook failed (exit 7): project/hooks/clone:before
  chain: provision > clone:before
error: hook failed (exit 7): project/hooks/provision

The first error identifies the failing hook. Its chain: shows the nested calls that reached it. Later errors identify the callers that also failed. Automatic before/after calls appear in the chain alongside explicit hook calls.

para returns the failing hook's exit status.

Start hooks with set -euo pipefail, as the generated stubs do. Without set -e or explicit error handling, a hook can continue after a failed "$PARA_RUN_HOOK" call and exit zero. para up would then report the workspace as ready despite the failure.

para rejects recursive hook calls:

text
error: hook cycle: provision > clone:before > provision

Sequential calls to the same hook are allowed. If you call boot:after from inside a boot hook, para runs the matching hooks at that call and again after all boot hooks finish.

Released under the MIT License.