-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·81 lines (72 loc) · 2.85 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# Config
LATEST_STABLE=nixpkgs-20.03-darwin
# Variables
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE}")"; pwd -P)"
NIXPATH="darwin=$ROOT_DIR/nix-darwin:darwin-config=$ROOT_DIR/config/nix-darwin:home-manager=$ROOT_DIR/home-manager:home-manager-config=$ROOT_DIR/config/home-manager:nixpkgs-overlays=$ROOT_DIR/overlays:nixpkgs=$ROOT_DIR/nixpkgs-unstable:nixpkgs-stable=$ROOT_DIR/nixpkgs-stable"
# Functions
do_sudo() {
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
echo "✓ sudo authentication successful."
}
init_repo() {
# Setting up base repo
cd "$ROOT_DIR"
git config remote.pjan.url >&- || git remote add pjan [email protected]:pjan/nix.git
# Setting up nixpkgs-unstable repo
cd "$ROOT_DIR/nixpkgs-unstable"
git config remote.channels.url >&- || git remote add channels https://github.com/nixos/nixpkgs-channels
git remote update channels
git checkout nixpkgs-unstable 2>/dev/null || git checkout --track channels/nixpkgs-unstable
git config remote.pjan.url >&- || git remote add pjan [email protected]:pjan/nixpkgs.git
# Setting up nixpkgs-stable repo
cd "$ROOT_DIR/nixpkgs-stable"
git config remote.channels.url >&- || git remote add channels https://github.com/nixos/nixpkgs-channels
git remote update channels
git checkout $LATEST_STABLE 2>/dev/null || git checkout --track channels/$LATEST_STABLE
git config remote.pjan.url >&- || git remote add pjan [email protected]:pjan/nixpkgs.git
# Setting up nix-darwin
cd "$ROOT_DIR/nix-darwin"
git checkout master
git config remote.pjan.url >&- || git remote add pjan [email protected]:pjan/nix-darwin.git
# Setting up home-manager
cd "$ROOT_DIR/home-manager"
git checkout master
git config remote.pjan.url >&- || git remote add pjan [email protected]:pjan/home-manager.git
}
install_nix() {
echo "# Installing Nix Package Manager..."
if [ -d "$HOME/.nix-profile/" ]; then
echo "✗ Nix Package Manager already installed."
else
sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
source ~/.nix-profile/etc/profile.d/nix.sh
nix-channel --remove nixpkgs
echo "✓ Nix Package Manager successfully installed."
fi
}
install_darwin() {
echo "# Installing nix-darwin..."
if [ -f "/run/current-system/darwin-version" ]; then
echo "✗ nix-darwin already installed."
else
export NIX_PATH=$NIXPATH
[ -e /etc/bashrc ] && [ ! -L /etc/bashrc ] && sudo rm /etc/bashrc || true
[ -e /etc/nix/nix.conf ] && [ ! -L /etc/nix/nix.conf ] && sudo rm /etc/nix/nix.conf || true
$(nix-build '<darwin>' -A system --no-out-link)/sw/bin/darwin-rebuild build
$(nix-build '<darwin>' -A system --no-out-link)/sw/bin/darwin-rebuild switch
@source /etc/bashrc
echo "✓ nix-darwin successfully installed."
fi
}
go() {
init_repo
install_nix
install_darwin
}
go
unset do_sudo
unset init_repo
unset install_nix
unset install_darwin
unset go