-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap
executable file
·113 lines (92 loc) · 2.56 KB
/
bootstrap
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
set -eu
check_required_application() {
if ! command -v curl; then
echo "Please install curl before start"
exit 1
fi
if ! command -v zsh; then
echo "Please install zsh before start"
exit 1
fi
}
install_nix() {
if ! command -v nix; then
echo "Installing nix..."
if [[ "$(uname)" == "Linux" ]]; then
curl -L https://nixos.org/nix/install | sh
fi
if [[ "$(uname)" == "Darwin" ]]; then
sh <(curl -L https://nixos.org/nix/install)
fi
fi
}
install_home_manager() {
# shellcheck disable=SC1090
source ~/.nix-profile/etc/profile.d/nix.sh
if ! command -v home-manager; then
echo "Installing home-manager..."
export NIX_PATH="$HOME/.nix-defexpr/channels"
nix-shell '<home-manager>' -A install
fi
}
install_nix_darwin() {
if ! command -v darwin-rebuild; then
echo "Installing nix-darwin..."
nix-shell '<darwin>' -A installer
darwin-rebuild switch
fi
}
add_nix_channel() {
# shellcheck disable=SC1091
# shellcheck disable=SC2116
if [[ "$(uname)" == "Linux" ]]; then
source "$HOME/.nix-profile/etc/profile.d/nix.sh" # Use unstable channel
else
export PATH="$PATH:/run/current-system/sw/bin"
fi
nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --add https://github.com/rycee/home-manager/archive/master.tar.gz home-manager
if [[ "$(uname)" == "Darwin" ]]; then
nix-channel --add https://github.com/LnL7/nix-darwin/archive/master.tar.gz darwin
fi
nix-channel --update
}
populate_nix_config() {
if [[ "$(uname)" == "Linux" ]]; then
echo -e "Populating nixpkgs config files for home manager..."
rm -rf "$HOME/.config/nixpkgs"
rm -rf "$HOME/.config/home-manager"
ln -sfn "$PWD"/nixpkgs "$HOME/.config"
ln -sfn "$PWD/home-manager" "$HOME/.config/home-manager"
fi
if [[ "$(uname)" == "Darwin" ]]; then
echo -e "Populating nixpkgs config files for nix-darwin..."
rm -rf "$HOME/.nixpkgs"
rm -rf "$HOME/home-manager"
ln -sfn "$PWD"/nixpkgs "$HOME/.nixpkgs"
ln -sfn "$PWD"/home-manager "$HOME/home-manager"
fi
}
install_tpm() {
echo "Installing tpm"
if [ -d ~/.tmux/plugins/tpm ]; then
rm -rf ~/.tmux/plugins/tpm
fi
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
export PATH="$HOME/.nix-profile/bin:$PATH"
zsh -c "$HOME/.tmux/plugins/tpm/bindings/install_plugins"
}
main() {
install_nix
add_nix_channel
populate_nix_config
if [[ "$(uname)" == "Linux" ]]; then
install_home_manager
else
install_nix_darwin
fi
install_tpm
echo -e "Done!"
}
main