-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall
executable file
·100 lines (81 loc) · 2.43 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
#!/bin/sh
set -eu
NIX_INSTALL_URL="${NIX_INSTALL_URL:-https://nixos.org/nix/install}"
TOOLBOX_CHANNEL_URL="${1:-https://github.com/Caascad/toolbox/archive/master.tar.gz}"
log() {
args="$*"
printf "\033[32m[toolbox]:\033[0m %s\n" "$args"
}
log_warning() {
args="$*"
printf "\033[33m[toolbox]:\033[0m %s\n" "$args"
}
log_run() {
cmd="$1"
log "Running: $cmd"
eval "$cmd"
}
_sourceNix() {
NIX_SH="$HOME/.nix-profile/etc/profile.d/nix.sh"
if [ -f "$NIX_SH" ]; then
# shellcheck source=/dev/null
. "$NIX_SH"
fi
}
_isNixInstalled() {
nix --version >/dev/null 2>&1
}
_isSubstituterConfigured() {
nix show-config | grep -q "toolbox.cachix.org"
}
_isChannelInstalled() {
nix-channel --list | grep -q toolbox
}
_addCacheConfig() {
if test -f ~/.config/nix/nix.conf
then
log_warning "$HOME/.config/nix/nix.conf exists."
log "Please make sure the following options are properly set:"
log " substituters = https://cache.nixos.org https://toolbox.cachix.org"
log " trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= toolbox.cachix.org-1:ZFzO+86jD4G5ukgmLOnQRxjVmMcqu+60JTusH6pv8/8="
log " experimental-features = nix-command"
else
mkdir -p "$HOME"/.config/nix/
cat << EOF > "$HOME"/.config/nix/nix.conf
substituters = https://cache.nixos.org https://toolbox.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= toolbox.cachix.org-1:ZFzO+86jD4G5ukgmLOnQRxjVmMcqu+60JTusH6pv8/8=
experimental-features = nix-command
EOF
fi
}
log "Initializing setup ..."
if _isNixInstalled ; then
log "Nix is already installed"
else
log "Looks like nix is not installed yet"
log_run "curl -L \"$NIX_INSTALL_URL\" | sh"
_sourceNix
fi
if _isSubstituterConfigured; then
log "Cache is already configured"
else
log "Adding toolbox binary cache"
_addCacheConfig
fi
if _isChannelInstalled; then
log "Channel is already configured"
else
log "Adding toolbox channel"
log_run "nix-channel --add $TOOLBOX_CHANNEL_URL toolbox"
fi
log "Updating channel"
log_run "nix-channel --update toolbox"
log "Installing toolbox"
log_run "nix build -f '<toolbox>' toolbox --no-link"
log_run "nix-env -f '<toolbox>' -iA toolbox"
log "Installation finished !"
log "Don't forget to configure your .bashrc with:"
echo ""
cat <<EOF
. /home/$USER/.nix-profile/etc/profile.d/nix.sh
EOF