This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·120 lines (104 loc) · 4 KB
/
install
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
#!/bin/bash
{ # Prevent script running if partially downloaded
set -euo pipefail
# Lifted from https://github.com/kalbasit/shabka/blob/8f6ba74a9670cc3aad384abb53698f9d4cea9233/os-specific/darwin/setup.sh#L22
sudo_prompt() {
echo "Please enter your password for sudo authentication"
sudo -k
sudo echo "sudo authenticaion successful!"
while true ; do sudo -n true ; sleep 60 ; kill -0 "$$" || exit ; done 2>/dev/null &
}
install_command_line_tools() {
# Unattended installation of Command Line Tools
# Found on apple.stackexchange.com at https://apple.stackexchange.com/questions/107307/how-can-i-install-the-command-line-tools-completely-from-the-command-line/195963#195963
# Homebrew uses a similar technique https://github.com/Homebrew/install/blob/878b5a18b89ff73f2f221392ecaabd03c1e69c3f/install#L297
xcode-select -p >/dev/null || {
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
CLT=$( softwareupdate -l |
grep "\*.*Command Line Tools" |
head -n 1 |
awk -F ":" '{print $2}' |
sed -e 's/^ *//' |
tr -d '\n' )
softwareupdate -i "$CLT" --verbose
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
}
echo "Command Line Tools are installed at $(xcode-select -p)"
}
install_nix() {
command -v nix >/dev/null || {
# printf responses based on:
# - Would you like to see a more detailed list of what we will do? n
# - Can we use sudo? y
# - Ready to continue? y
printf "n\ny\ny" | sh <(curl -fsSL https://nixos.org/nix/install) --daemon --darwin-use-unencrypted-nix-store-volume
# Update local shell
source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
}
nix-shell -p nix-info --run "nix-info -m"
}
install_nix_darwin() {
command -v darwin-rebuild >/dev/null || {
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer --out-link /tmp/nix-darwin
# nix-darwin controls nix.conf
sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.backup-before-nix-darwin
# printf based on:
# - Would you like to edit the configuration.nix before starting? n
# - Would you like to manage <darwin> with nix-channel? y
# - Would you like to load Darwin configuration in /etc/bashrc? y
# - Would you like to load Darwin configuration in /etc/zshrc? y
# - Would you like to create /run? y
printf "n\ny\ny\ny\ny" | /tmp/nix-darwin/bin/darwin-installer
}
}
install_home_manager() {
if [ ! $( nix-channel --list | grep home-manager ) ]; then
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
fi
}
install_homebrew() {
command -v brew || {
printf "\n" | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
brew doctor
}
clone_repository() {
repository="https://github.com/TheOptimist/systemosaurus.git"
clone_target="${HOME}/.nixpkgs"
if [ $( cat "${clone_target}/.git/config" | grep "${repository}" ) ]; then
cd "${clone_target}"
git status
cd -
else
rm -rf "${clone_target}"
git clone https://github.com/TheOptimist/systemosaurus.git "${clone_target}"
fi
}
darwin_build() {
for filename in shells bashrc zshrc; do
filepath="/etc/${filename}"
if [ -f "${filepath}" ] && [ ! -L "${filepath}" ]; then
sudo mv "${filepath}" "${filepath}.backup-before-nix-darwin"
fi
done
set +u # Unbound INSIDE_EMACS variable in /etc/bashrc_Apple_Terminal
source /etc/static/bashrc
set -u
export NIX_PATH=$HOME/.nix-defexpr/channels:$NIX_PATH
darwin-rebuild switch -I "darwin-config=$HOME/.nixpkgs/configuration.nix"
}
# Run the installation workflow
sudo_prompt
install_command_line_tools
install_nix
install_nix_darwin
install_home_manager
install_homebrew
clone_repository
darwin_build
# Clean dock settings of applications
defaults write com.apple.dock persistent-apps -array
defaults write com.apple.dock recent-apps -array
killall Dock
} # Prevent script running if partially downloaded