Skip to content

Commit

Permalink
Replace auxiliary ~/.zshenv
Browse files Browse the repository at this point in the history
This commit removes (or rather replaces) the auxiliary `.zshenv` script
which was symlinked directly under `$HOME`.

This was unsatisfactory w.r.t. the XDG directory spec, even more so that
the sole purpose of the script was to export `ZDOTDIR` and source the
actual config file.

So instead of doing that there is new systemd user-specific config under
`.config/environment.d/` which is loaded during session login and thus
_before_ shell login, and which now configures the `ZDOTDIR`.

Note that these conf files are loaded and merged in the lexicographic
order of their names (hence the choice of `00-default.conf`). Also, any
change to these files will typically need a new login to be caught and
applied (user unit can be updated using
`systemctl daemon-reload --user`, but that change won't affect services
started _before_ - e.g., terminal, VMs, etc.).

An alternative solution would be to use `.pam_environment`, but a) it's
directly under HOME too, and b) it's been deprecated.

Finally, in order to migrate just
 1. Run `make links`
 2. Remove the deprecated `~/.zshenv`
 3. Re-login
  • Loading branch information
matyama committed Mar 11, 2024
1 parent 3bbe43a commit 4f7f79b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .config/environment.d/00-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Default (systemd) user-specific environment setup
# https://wiki.archlinux.org/title/environment_variables#Per_user
#
# Note: Changes here will only apply consistently _after_ new session login.

# Point `ZDOTDIR` to custom configs under `XDG_CONFIG_HOME` before shell login
ZDOTDIR=${XDG_CONFIG_HOME:-$HOME/.config}/zsh
9 changes: 0 additions & 9 deletions .zshenv

This file was deleted.

6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ $(FONTS_DIR) \
$(XDG_BIN_HOME) \
$(XDG_CACHE_HOME)/vm \
$(XDG_CACHE_HOME)/zsh \
$(XDG_CONFIG_HOME)/coc \
$(XDG_CONFIG_HOME)/direnv \
$(XDG_CONFIG_HOME)/environment.d \
$(XDG_CONFIG_HOME)/git \
$(XDG_CONFIG_HOME)/maven \
$(XDG_CONFIG_HOME)/npm \
Expand Down Expand Up @@ -159,6 +159,7 @@ links: \
$(STACK_ROOT) \
$(XDG_BIN_HOME) \
$(XDG_CONFIG_HOME)/direnv \
$(XDG_CONFIG_HOME)/environment.d \
$(XDG_CONFIG_HOME)/git \
$(XDG_CONFIG_HOME)/maven \
$(XDG_CONFIG_HOME)/npm \
Expand All @@ -171,13 +172,14 @@ links: \
$(ZDOTDIR) \
$(ZSH_CUSTOM)
@echo "Linking configuration files:"
@ln -svft ~ $(CFG_DIR)/.zshenv
@{ \
for cfg in $$(find $(CFG_DIR)/.config $(CFG_DIR)/.local/share -type f); do \
ln -svf $$cfg "$(HOME)$${cfg#$(CFG_DIR)}";\
done;\
}
@ln -svft $(XDG_BIN_HOME) $(CFG_DIR)/.local/bin/*
@echo "Refreshing systemd user environment (note: requires session restart)"
@systemctl daemon-reload --user
@echo "Making 'resolvectl' act as 'resolvconf': https://superuser.com/a/1544697"
@sudo ln -svf /usr/bin/resolvectl /usr/local/bin/resolvconf
@echo "Making 'g++' act as 'musl-g++': https://github.com/rust-lang/cargo/issues/3359"
Expand Down

0 comments on commit 4f7f79b

Please sign in to comment.