#!/usr/bin/env bash
# gnoblin-session -- the wayland-sessions Exec= target for the `gnoblin`
# session mode.
#
# The login manager invokes this directly, so it sets up the lookup paths
# gnome-session and anything it launches DIRECTLY need to find the patched
# build in $PREFIX (a dev prefix, not a system install) instead of whatever
# is on the login manager's default PATH/library search path -- via
# gnoblin-env.sh, shared with scripts/run-gnome-shell.sh,
# scripts/run-gnome-devkit.sh, and gnoblin-shell-service.
#
# gnome-shell ITSELF is not launched by this wrapper's PATH/env at all: on a
# systemd session gnome-session starts it via the systemd --user unit
# org.gnoblin.Shell@wayland.service (gnoblin-specific, not the shared
# org.gnome.Shell every other session mode uses -- see the comment in
# gnoblin.session), which sources this same helper itself. That unit only
# exists once `scripts/register-session.sh` has linked it into systemd
# --user; see docs/installation.md.
#
# Installed to $PREFIX/bin/gnoblin-session by scripts/install-session.sh,
# which also bakes this script's absolute path into the installed
# gnoblin.desktop's Exec=. Self-locates its prefix from its own installed
# path, so it keeps working if that prefix is later moved/repackaged.
set -euo pipefail

PREFIX="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "$PREFIX/libexec/gnoblin-env.sh"
gnoblin_env_apply "$PREFIX"

# gnome-session normally re-executes through the user's login shell. NixOS
# login profiles rebuild XDG_DATA_DIRS and remove this package's session file,
# so keep the runtime environment established above for the session manager.
exec gnome-session --no-reexec --session=gnoblin "$@"
