forked from ryanb/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·65 lines (53 loc) · 1.76 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -e
PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
DOTFILES_DIR=$(dirname "${SCRIPT_DIR}")
os="$(uname -s)"
arch="$(uname -m)"
load_nix_environment() {
if [ "${os}" = "Darwin" ]; then
profile_path="/nix/var/nix/profiles/default"
elif [ "${os}" = "Linux" ]; then
profile_path="${HOME}/.nix-profile"
else
echo "ERROR: Unknown OS: ${os}"
exit 1
fi
if [ -f "${profile_path}/etc/profile.d/nix-daemon.sh" ]; then
. "${profile_path}/etc/profile.d/nix-daemon.sh"
fi
}
# install Homebrew first
if [ "${os}" = "Darwin" ]; then
if ! command -v brew >/dev/null 2>&1; then
echo "INFO: Installing homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
load_nix_environment
# install nix
if ! command -v nix >/dev/null 2>&1; then
sh <(curl -L https://nixos.org/nix/install)
fi
load_nix_environment
# enable flakes
local_config_file="${HOME}/.config/nix/nix.conf"
mkdir -p "$(dirname "${local_config_file}")"
if ! grep -qR "^experimental-features = nix-command flakes" "${local_config_file}" 2>/dev/null; then
echo "experimental-features = nix-command flakes" >>"${local_config_file}"
fi
case "${os}-${arch}" in
"Darwin-x84-64" | "Darwin-arm64")
echo "INFO: Running Home Manager configuration for MacOS ${arch}"
nix run nix-darwin -- switch --flake "${DOTFILES_DIR}"
nix run "${DOTFILES_DIR}#homeConfigurations.${USER}@$(hostname).activationPackage"
;;
"Linux-x86_64")
echo "INFO: Running Home Manager configuration for Linux ${arch}"
nix run "${DOTFILES_DIR}#homeConfigurations.${USER}@linux.activationPackage"
;;
*)
echo "ERROR: unsupported OS and arch: ${os}-${arch}"
;;
esac