install-nix-action/lib/install-nix.sh

51 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2020-02-26 13:12:17 +00:00
#!/usr/bin/env bash
set -euo pipefail
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 https://nixos.org/nix/install) --daemon
# write nix.conf again as installation overwrites it
nixConf
2020-02-26 13:45:57 +00:00
# Enable sandbox on Darwin/Linux
sudo sh -c 'echo sandbox = true >> /etc/nix/nix.conf'
2020-02-26 13:12:17 +00:00
# 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::/nix/var/nix/profiles/per-user/root/channels"