This one's pretty fucking weird. Almost immediately after I set up hibernation on my system as per the Arch wiki guide (https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation), I've wound up in a situation where my environment variables are no longer sourced for either the shell or the KDE graphical session.
My current environment setup is as follows. I have the script
/etc/profile.d/xdgbase.sh which first defines the XDG base directory variables system-wide.
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-"$HOME/.local/state"}"
After this, I have
.bashrc and
.bash_profile source my separate alias and env var setups respectively.
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
shopt -s autocd
source $XDG_CONFIG_HOME/shell/aliasrc
[[ -f ~/.bashrc ]] && . ~/.bashrc
export HISTFILE="$XDG_STATE_HOME"/bash_history
HISTIGNORE=" cd *: clear"
source $XDG_CONFIG_HOME/shell/envrc
I also have the pre-startup script
env.sh for KDE Plasma to simply source my
envrc config for the graphical session.
source $XDG_CONFIG_HOME/shell/envrc
However, now after setting up hibernation, both
.bash_profile and
env.sh consistently fail to automatically source
envrc, causing every variable in that file to be empty/undefined. Even after attempting to revert the hibernation setup, this is still a problem now and I have no idea what might have gone wrong on the way.
How could this have possibly happened, and how might I be able to rework my current setup to fix this?
Narrowing it down further:
- .bashrc is unaffected and continues to source aliasrc just fine.
- envrc can still be sourced just fine manually in an interactive bash session, loading all the usual env vars I have.
- .bash_profile all of a sudden fails immediately after exporting HISTFILE, meaning that both the HISTIGNORE and envrc lines get ignored for whatever reason despite them throwing no issues.
- .config/plasma-workspace/env/env.sh, I still have no clue about.
+ [[ -f /home/_/.bashrc ]]
+ . /home/_/.bashrc
++ [[ hxB != *i* ]]
++ return
+ export HISTFILE=/home/_/.local/state/bash_history
+ HISTFILE=/home/_/.local/state/bash_history
+ HISTIGNORE=' cd *: clear'
+ source /home/_/.config/shell/envrc
++ export VISUAL=nvim EDITOR=nvim
++ VISUAL=nvim
++ EDITOR=nvim
++ PATH=/home/_/.local/bin::/home/_/.local/bin::/home/_/.local/bin::/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/home/_/.dotnet/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
+++ tty
++ GPG_TTY=/dev/pts/2
++ XINITRC=/home/_/.config/X11/xinitrc
++ XSERVERRC=/home/_/.config/X11/xserverrc
++ XCOMPOSEFILE=/home/_/.config/X11/xcompose
++ XCOMPOSECACHE=/home/_/.cache/X11/xcompose
++ GTK_RC_FILES=/home/_/.config/gtk-1.0/gtkrc
++ GTK2_RC_FILES=/home/_/.config/gtk-2.0/gtkrc
++ INPUTRC=/home/_/.config/inputrc
++ WGETRC=/home/_/.config/wgetrc
++ GNUPGHOME=/home/_/.local/share/gnupg
++ PASSWORD_STORE_DIR=/home/_/.local/share/pass
++ PYTHONSTARTUP=/home/_/.config/pythonrc
++ PYTHONUSERBASE=/home/_/.local/share/python
++ PYTHONPYCACHEPREFIX=/home/_/.cache/python
++ GRADLE_USER_HOME=/home/_/.local/share/gradle
++ ANDROID_HOME=/home/_/.local/share/android
++ NPM_CONFIG_USERCONFIG=/home/_/.config/npm/npmrc
++ CARGO_HOME=/home/_/.local/share/cargo
++ WINEPREFIX=/home/_/.local/share/wineprefixes/default
It is with great embarrassment that I must admit the entire reason for this was because the
envrc file itself wasn't well written to begin with.
export \
VISUAL=nvim \
EDITOR=nvim \
GPG_TTY=$(tty) \
...
The problem with this is the fact that it was all one monster command separated by newlines and backslashes, however the extra line breaks in between caused it to break when sourced automatically. Completely unrelated to hibernation in the end.