-
Notifications
You must be signed in to change notification settings - Fork 1
/
darwin-compost.sh
executable file
·65 lines (52 loc) · 1.79 KB
/
darwin-compost.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 -o pipefail
prog=$0
error() {
echo "Whoops! Looks like $1:$2 failed."
echo "Please try rerunning $prog again."
exit 1
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
cd $DIR
source utils.sh
check isDarwin || exitWithMessage 1 "Should only run on darwin."
check isNonRootUser || exitWithMessage 1 "Do not run as root."
if ! check isXcodeInstalled; then
echo "Xcode installation required. Rerun $0 when it is complete";
xcode-select --install
exit 1
fi
setupNix
HOME_NIX=${HOME_NIX-:$DIR/home/home.nix}
export NIX_PATH="$HOME/.nix-defexpr/channels:$NIX_PATH"
if ! check existsOnPath darwin-rebuild; then
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
./result/bin/darwin-installer
. /etc/bashrc
fi
if ! check isLink "/etc/nix/nix.conf"; then
echo -e "$YELLOW /etc/nix/nix.conf is not a link. sudo rm it and link to /etc/static/nix/nix.conf"
fi
ensureOverlay
if ! check fileExists ~/.profile.nix-machines; then
echo "source $DIR/dotfiles/profile" >> ~/.profile
echo "export HOME_NIX='$HOME_NIX'" >> ~/.profile
echo "export NO_REBUILD=$NO_REBUILD" >> ~/.profile
touch ~/.profile.nix-machines
fi
if ! check fileExists ~/.bashrc.nix-machines; then
echo "source $DIR/dotfiles/bashrc" >> ~/.bashrc
echo "export HOME_NIX='$HOME_NIX'" >> ~/.bashrc
echo "export NO_REBUILD=$NO_REBUILD" >> ~/.bashrc
touch ~/.bashrc.nix-machines
fi
export NIX_PATH=darwin-config=$HOME/.nixpkgs/darwin-configuration.nix:$NIX_PATH
export NIX_PATH=$NIX_PATH:$HOME/.nix-defexpr/channels
exec darwin-rebuild switch $@