-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
126 lines (102 loc) · 2.78 KB
/
setup.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
readonly NIXPKGS_VERSION="23.05"
# Environment Setup Script.
echo "Start setup."
echo
# Treat unset variables
set -u
# Immediately exit if it returns a non-zero status.
set -e
# Get absolute path of this script
abs_path="$(
cd "$(dirname "${0}")"
pwd
)"
readonly abs_path
# Import functions
source ./function/install/xcode_command_line_tools.sh
source ./function/install/homebrew.sh
source ./function/install/nix.sh
source ./function/install/home_manager.sh
source ./function/install/fisher.sh
source ./function/add_nix_channels.sh
#######################################
# Deploy dot files to ${HOME}
# Globals:
# HOME
# Arguments:
# dotfiles::Array
# Returns:
# None
#######################################
deploy_dotfiles() {
# TODO: Implement error handling related to arguments and dependencies
local -ra dotfiles=("${@}")
prepare_sub_dir() {
local -ra dotfiles=("${@}")
for file in "${dotfiles[@]}"; do
if [[ "${file}" =~ [:word:]*/[:word:]* ]]; then
mkdir -p "${HOME}/.$(dirname "${file}")"
fi
done
}
prepare_sub_dir "${dotfiles[@]}"
for dotfile in "${dotfiles[@]}"; do
ln -sfn "${abs_path}"/"${dotfile}" "${HOME}"/."${dotfile}"
done
}
#######################################
# Entry point
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
main() {
# List of dotfiles to deploy
local -a dotfiles=(
config/home-manager
config/fish/fish_plugins
)
# List of nix-channels to add
local -a nix_channels=()
# Run only on macOS
if [ "$(uname)" == 'Darwin' ]; then
install::xcode_command_line_tools
install::homebrew
nix_channels+=(
"nixpkgs=https://nixos.org/channels/nixpkgs-${NIXPKGS_VERSION}-darwin"
"unstable=https://nixos.org/channels/nixpkgs-unstable"
)
echo "Install a package under homebrew management."
echo
# For Apple Silicon devices, applications installed with Homebrew may require Rosetta2, so install it
if [ "$(uname -a)" == 'arm64' ]; then
sudo softwareupdate --install-rosetta --agree-to-license
fi
brew bundle --file="${abs_path}"/Brewfile
echo
fi
# Run only on non-NixOS
if ! type -t nixos-version >/dev/null 2>&1; then
dotfiles+=(config/nix)
fi
# Install Nix
install::nix
# Install Home Manager
install::home_manager "${NIXPKGS_VERSION}"
# Delete existing ${HOME}/.config/home-manager directory to replace it with a file under git management
rm -rf "${HOME}/.config/home-manager"
# Deploy dot files to ${HOME}
deploy_dotfiles "${dotfiles[@]}"
# Reflecting the configuration under home-manager management
add_nix_channels "${nix_channels[@]}"
home-manager switch
# Install fisher and fish plugins
install::fisher
echo "Setup is complete."
}
# Run
main