dotfiles/scripts/hm-switch.sh

34 lines
1.1 KiB
Bash
Raw Normal View History

2022-12-03 00:01:48 +00:00
#!/usr/bin/env sh
# NOTE: Untested on case of no home-manager
set -xv
# Where this script located
2023-01-15 09:54:40 +00:00
SCRIPT_DIR=$(readlink -f $(dirname $0))
2022-12-03 00:01:48 +00:00
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
HOME_MANAGER_DIR="${SCRIPT_DIR}/../nix-conf/home-manager"
# Manage nix.conf. Ideally, this should be done with snapshot-based version
# and with preview on-the-spot, with some timeout
if [ -f /etc/nix/nix.conf ]; then
# managed nix.conf
BACKUP_FILE="/etc/nix/nix.conf.backup"
echo "overwriting /etc/nix/nix.conf. Please find latest backup in ${BACKUP_FILE}"
sudo cp /etc/nix/nix.conf ${BACKUP_FILE}
sudo cp "${HOME_MANAGER_DIR}/hwtr/nix.conf" /etc/nix/
fi
# Mason is bad: it puts binaries onto xdg.data
# let's make mason starts fresh, just in case we introduce RPATH hacks
# that injects binary for Mason to use.
rm -rf ~/.local/share/nvim/mason
2022-12-03 00:01:48 +00:00
# test if we have home-manager, if not, attempt to use nix to put home-manager to
# our environment
2023-01-14 14:37:40 +00:00
if ! command -v home-manager ; then
nix-shell -p home-manager --run "home-manager switch --flake $HOME_MANAGER_DIR $@"
2022-12-03 00:01:48 +00:00
else
home-manager switch -b backup --flake "$HOME_MANAGER_DIR" $@
2022-12-03 00:01:48 +00:00
fi