/
install-nix.sh
executable file
·50 lines (38 loc) · 1.44 KB
/
install-nix.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
#!/usr/bin/env bash
set -euo pipefail
nixPath="${1:-/nix/var/nix/profiles/per-user/root/channels}"
export here=$(dirname "${BASH_SOURCE[0]}")
nixConf() {
sudo mkdir -p /etc/nix
# Workaround a segfault: https://github.com/NixOS/nix/issues/2733
sudo sh -c 'echo http2 = false >> /etc/nix/nix.conf'
# Set jobs to number of cores
sudo sh -c 'echo max-jobs = auto >> /etc/nix/nix.conf'
# Allow binary caches for runner user
sudo sh -c 'echo trusted-users = root runner >> /etc/nix/nix.conf'
}
if [[ $OSTYPE =~ darwin ]]; then
# Catalina workaround https://github.com/NixOS/nix/issues/2925
$here/create-darwin-volume.sh
# Disable spotlight indexing of /nix to speed up performance
sudo mdutil -i off /nix
fi
nixConf
# Needed due to multi-user being too defensive
export ALLOW_PREEXISTING_INSTALLATION=1
sh <(curl -L https://nixos.org/nix/install) --daemon
# write nix.conf again as installation overwrites it
nixConf
# macOS needs certificates hints
if [[ $OSTYPE =~ darwin ]]; then
cert_file=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
echo "::set-env name=NIX_SSL_CERT_FILE::$cert_file"
export NIX_SSL_CERT_FILE=$cert_file
sudo launchctl setenv NIX_SSL_CERT_FILE "$cert_file"
fi
# Reload the daemon to pick up changes
sudo pkill -HUP nix-daemon
# Set paths
echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin"
echo "::add-path::/nix/var/nix/profiles/default/bin"
echo "::set-env name=NIX_PATH::${nixPath}"