2022-12-03 00:01:48 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# NOTE: Untested on case of no home-manager
|
2023-03-24 16:39:29 +00:00
|
|
|
set -xveu
|
2022-12-03 00:01:48 +00:00
|
|
|
# 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"
|
|
|
|
|
2023-01-13 06:08:31 +00:00
|
|
|
# Manage nix.conf. Ideally, this should be done with snapshot-based version
|
2023-03-23 20:49:13 +00:00
|
|
|
# and with preview on-the-spot, with some timeout (like deploy-rs)
|
2023-01-13 06:08:31 +00:00
|
|
|
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}
|
|
|
|
fi
|
2023-06-01 15:26:10 +00:00
|
|
|
sudo cp "${HOME_MANAGER_DIR}/nix.conf" /etc/nix/
|
|
|
|
sudo cp "${HOME_MANAGER_DIR}/${USER}/nix.conf" /etc/nix/ | echo "no nix.conf for ${USER}. Totally OK."
|
2023-03-23 20:49:13 +00:00
|
|
|
sudo cp "${SCRIPT_DIR}/upload-to-cache.sh" /etc/nix/
|
2023-03-24 04:50:49 +00:00
|
|
|
sudo chmod +x /etc/nix/*.sh
|
|
|
|
# Reload nix daemon so that new changes are applied.
|
|
|
|
sudo launchctl stop org.nixos.nix-daemon
|
|
|
|
sudo launchctl start org.nixos.nix-daemon
|
2023-01-13 06:08:31 +00:00
|
|
|
|
2023-01-03 05:48:12 +00:00
|
|
|
# Mason is bad: it puts binaries onto xdg.data
|
2023-01-12 20:04:55 +00:00
|
|
|
# let's make mason starts fresh, just in case we introduce RPATH hacks
|
|
|
|
# that injects binary for Mason to use.
|
2023-03-24 16:39:29 +00:00
|
|
|
sudo rm -rf ~/.local/share/nvim/mason
|
2023-01-03 05:48:12 +00:00
|
|
|
|
2023-03-23 00:08:04 +00:00
|
|
|
# NOTE: https://discourse.nixos.org/t/relative-path-support-for-nix-flakes/18795
|
|
|
|
# nix flake update is required for relative paths to work
|
|
|
|
nix flake update
|
2023-03-24 16:39:29 +00:00
|
|
|
nix flake update "${SCRIPT_DIR}/../nix-conf/home-manager"
|
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
|
2023-01-12 20:04:55 +00:00
|
|
|
nix-shell -p home-manager --run "home-manager switch --flake $HOME_MANAGER_DIR $@"
|
2022-12-03 00:01:48 +00:00
|
|
|
else
|
2023-01-12 20:04:55 +00:00
|
|
|
home-manager switch -b backup --flake "$HOME_MANAGER_DIR" $@
|
2022-12-03 00:01:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-03-22 23:35:03 +00:00
|
|
|
# Attempt to reload running instances
|
|
|
|
tmux source-file ~/.config/tmux/tmux.conf
|
|
|
|
|