Skip to content

Commit

Permalink
Move ghcup to XDG dirs
Browse files Browse the repository at this point in the history
Addresses #17
 - Adds `XDG_BIN_HOME` environment variable for user's binaries and adds
   it to appropriate places in Makefile
 - Introduces `GHCUP_USE_XDG_DIRS` to enable `gucp`'s XDG support, see:
   https://www.haskell.org/ghcup/guide/#xdg-support
 - Updates path for sourcing `ghcup` env in `.zshrc`
 - Adds potential deprecation note for `make stack`

This change requires reinstall, however it does not seem to break
existing stack projects. Migration can look as follows:
 1. `~/.ghcup`, `~/.cabal` and `~/.ghc` can be dropped
 2. Reload shell to bring `GHCUP_USE_XDG_DIRS` in scope
 3. Reinstall with `make ghcup` with HLS and `stack` as well - `.zshrc`
    update is not necessary as it's part of this commit
 4. Reload shell again to source ghcup's env

Known issues:
 - Shell completions for `ghcup` don't seem to work (could have been a
   pre-existing issue)
 - Stack must now be updated via `ghcup` (according to a post-install
   log message)
  • Loading branch information
matyama committed Apr 10, 2022
1 parent 5c9bc6f commit a7b800a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# - Furthermore, `.zprofile` might be better place for commands and variables
# that should be set *once* or which **don't need to be updated frequently**

# XDG specification does not define this variable but it is mentioned/assumed by
# some apps/libs (e.g. `ghcup`) so it might be useful to export it anyway.
# - https://www.haskell.org/ghcup/guide/#xdg-support
export XDG_BIN_HOME="${XDG_BIN_HOME:-$HOME/.local/bin}"

# System and architecture
export ARCH=$(uname -m)

Expand Down Expand Up @@ -48,6 +53,11 @@ export RUSTFLAGS="-C target-cpu=native"
export RUST_BACKTRACE=1

# Haskell stack
# - Any value of `GHCUP_USE_XDG_DIRS` will enable XDG support, see:
# https://www.haskell.org/ghcup/guide/#xdg-support
# - Note: `XDG_BIN_HOME` will be used for storing binaries and as mentioned in
# the docs, there might be clash with other tools using it (stack/cabal/ghc)
export GHCUP_USE_XDG_DIRS=1
export STACK_ROOT=${XDG_DATA_HOME}/stack

# Go lang
Expand Down
2 changes: 1 addition & 1 deletion .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fi
[ ! $(command -v fuck) ] || eval $(thefuck --alias)

# Haskell toolchain installer ghcup (https://www.haskell.org/ghcup/)
[ -f "/home/matyama/.ghcup/env" ] && source "/home/matyama/.ghcup/env"
[ -f "${XDG_DATA_HOME}/ghcup/env" ] && source "${XDG_DATA_HOME}/ghcup/env"

# Haskell stack (https://docs.haskellstack.org/en/stable/README/)
[ ! $(command -v stack) ] || eval "$(stack --bash-completion-script stack)"
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ifndef XDG_CONFIG_HOME
XDG_CONFIG_HOME=$(HOME)/.config
endif

ifndef XDG_BIN_HOME
XDG_BIN_HOME=$(HOME)/.local/bin
endif

ifndef XDG_DATA_HOME
XDG_DATA_HOME=$(HOME)/.local/share
endif
Expand Down Expand Up @@ -61,6 +65,10 @@ ifndef TRAVIS_CONFIG_PATH
TRAVIS_CONFIG_PATH=$(XDG_CONFIG_HOME)/travis
endif

ifndef GHCUP_USE_XDG_DIRS
GHCUP_USE_XDG_DIRS=1
endif

ifndef STACK_ROOT
STACK_ROOT=$(XDG_DATA_HOME)/stack
endif
Expand Down Expand Up @@ -97,7 +105,7 @@ $(FONTS_DIR) \
$(ZSH_CUSTOM) \
$(ZSH)/completions \
$(ZSH)/plugins/poetry \
~/.local/bin \
$(XDG_BIN_HOME) \
$(XDG_CONFIG_HOME)/coc \
$(XDG_CONFIG_HOME)/direnv \
$(XDG_CONFIG_HOME)/git \
Expand Down Expand Up @@ -186,6 +194,7 @@ links: \
$(FD_CONFIG_HOME) \
$(RIPGREP_CONFIG_HOME) \
$(STACK_ROOT) \
$(XDG_BIN_HOME) \
$(XDG_CONFIG_HOME)/coc \
$(XDG_CONFIG_HOME)/direnv \
$(XDG_CONFIG_HOME)/git \
Expand All @@ -194,7 +203,6 @@ links: \
$(XDG_CONFIG_HOME)/nvim/scripts \
$(XDG_CONFIG_HOME)/pypoetry \
$(XDG_CONFIG_HOME)/zsh \
~/.local/bin \
$(ZSH_CUSTOM)
# END DEPS
@echo "Linking configuration files:"
Expand All @@ -207,7 +215,7 @@ links: \
ln -svf $$cfg "$(HOME)$${cfg#$(CFG_DIR)}";\
done;\
}
@ln -svft ~/.local/bin \
@ln -svft $(XDG_BIN_HOME) \
$(CFG_DIR)/.local/bin/alacritty_toggle.sh \
$(CFG_DIR)/.local/bin/increase_swap.sh \
$(CFG_DIR)/.local/bin/init_ubuntu.sh \
Expand Down Expand Up @@ -628,6 +636,9 @@ else
@echo ">>> Finish $@ completion setup by reloading zsh with 'zshreload'"
endif

# TODO: ghcup now installs stack as well => deprecate?
# - From `ghcup`'s post-installation log:
# "Additionally, you should upgrade stack only through ghcup."
.PHONY: stack
stack: net-tools
ifneq ($(shell which stack 2> /dev/null),)
Expand Down Expand Up @@ -876,7 +887,7 @@ aws-vault: net-tools
sudo chmod 755 $(AWS_VAULT_BIN)

.PHONY: bat
bat: ~/.local/bin
bat: $(XDG_BIN_HOME)
ifneq ($(shell which bat 2> /dev/null),)
@echo ">>> $$($@ --version) already installed"
else
Expand Down

0 comments on commit a7b800a

Please sign in to comment.