45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# This script upgrades Nix to specific version.
|
|
# https://nixos.org/manual/nix/stable/installation/upgrading.html
|
|
set -eo pipefail
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
source "${GIT_ROOT}/scripts/colors.sh"
|
|
source "${GIT_ROOT}/nix/scripts/source.sh"
|
|
source "${GIT_ROOT}/nix/scripts/version.sh"
|
|
|
|
nix_upgrade() {
|
|
echo -e "Upgrading Nix interpreter to: ${GRN}${NIX_VERSION}${RST}" >&2
|
|
nix-channel --update
|
|
nix-env --install --attr "nixpkgs.${NIX_PACKAGE}" "nixpkgs.cacert"
|
|
if [[ "$(uname -s)" == "Darwin" ]]; then
|
|
echo "Restarting Nix daemon Launchd service" >&2
|
|
launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
elif [[ "$(uname -s)" == "Linux" ]] && [[ "$(nix_install_type)" == "multi" ]]; then
|
|
echo "Restarting Nix daemon Systemd service" >&2
|
|
systemctl daemon-reload
|
|
systemctl restart nix-daemon
|
|
fi
|
|
}
|
|
|
|
# Allow for sourcing the script
|
|
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
|
|
return
|
|
fi
|
|
|
|
if [[ "$(nix_current_version)" == "${NIX_VERSION}" ]]; then
|
|
echo -e "Nix interpreter already on version: ${GRN}${NIX_VERSION}${RST}"
|
|
exit 0
|
|
fi
|
|
|
|
NIX_INSTALL_TYPE=$(nix_install_type)
|
|
if [[ "${NIX_INSTALL_TYPE}" == "nixos" ]]; then
|
|
echo -e "${YLW}WARNING:${RST} Upgrade Nix in your NixOS configuration!" >&2
|
|
exit 0
|
|
elif [[ "${NIX_INSTALL_TYPE}" == "single" ]]; then
|
|
nix_upgrade
|
|
elif [[ "${NIX_INSTALL_TYPE}" == "multi" ]]; then
|
|
sudo -i bash -c "source ${PWD}/${0}; nix_upgrade"
|
|
fi
|