-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnix-quick-install.sh
executable file
·96 lines (85 loc) · 3 KB
/
nix-quick-install.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -eu
set -o pipefail
# Figure out system type (TODO don't assume x86_64)
case "$OSTYPE" in
darwin*)
sys="x86_64-darwin"
;;
linux*)
sys="x86_64-linux"
;;
*)
echo >& "unsupported OS type: $OSTYPE"
exit 1
esac
# Make sure /nix exists and is writeable
if [ -a /nix ]; then
if ! [ -w /nix ]; then
echo >&2 "/nix exists but is not writeable, can't set up nix-quick-install-action"
exit 1
else
rm -rf /nix/var/nix-quick-install-action
fi
elif [[ "$sys" =~ .*-darwin ]]; then
sudo $SHELL -euo pipefail << EOF
echo nix >> /etc/synthetic.conf
echo -e "run\\tprivate/var/run" >> /etc/synthetic.conf
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B &>/dev/null \
|| /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t &>/dev/null \
|| echo "warning: failed to execute apfs.util"
diskutil apfs addVolume disk1 APFS nix -mountpoint /nix
mdutil -i off /nix
chown $USER /nix
EOF
else
sudo install -d -o "$USER" /nix
if [[ "$NIX_ON_TMPFS" == "true" || "$NIX_ON_TMPFS" == "True" || "$NIX_ON_TMPFS" == "TRUE" ]]; then
sudo mount -t tmpfs -o size=90%,mode=0755,gid="$(id -g)",uid="$(id -u)" tmpfs /nix
fi
fi
# Fetch nix archive
rel="$(head -n1 "$RELEASE_FILE")"
url="${NIX_ARCHIVES_URL:-https://github.com/nixbuild/nix-quick-install-action/releases/download/$rel}/nix-$NIX_VERSION-$sys.tar.zstd"
archive="$(mktemp)"
curl -sL --retry 3 --retry-connrefused "$url" | zstd -df - -o "$archive"
# Unpack nix
if [[ "$sys" =~ .*-darwin ]]; then
# MacOS tar doesn't have the --skip-old-files, so we use rsync instead
tmpdir="$(mktemp -d)"
tar --keep-old-files --strip-components 1 -x -f "$archive" -C "$tmpdir"
rsync --archive --ignore-existing "$tmpdir/" /nix/
else
tar --skip-old-files --strip-components 1 -x -f "$archive" -C /nix
fi
rm -f "$archive"
# Setup nix.conf
NIX_CONF_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/nix/nix.conf"
mkdir -p "$(dirname "$NIX_CONF_FILE")"
touch "$NIX_CONF_FILE"
if [ -n "${NIX_CONF:-}" ]; then
printenv NIX_CONF > "$NIX_CONF_FILE"
fi
# Setup GitHub access token
if [[ -n "${GITHUB_ACCESS_TOKEN:-}" ]]; then
echo >>"$NIX_CONF_FILE" \
"access-tokens = github.com=$GITHUB_ACCESS_TOKEN"
elif [[ -n "${GITHUB_TOKEN:-}" ]]; then
echo >>"$NIX_CONF_FILE" \
"access-tokens = github.com=$GITHUB_TOKEN"
fi
# Populate the nix db
nix="$(readlink /nix/var/nix-quick-install-action/nix)"
"$nix/bin/nix-store" --load-db < /nix/var/nix-quick-install-action/registration
# Install nix in profile
MANPATH= . "$nix/etc/profile.d/nix.sh"
"$nix/bin/nix-env" -i "$nix"
# Certificate bundle is not detected by nix.sh on macOS.
if [ -z "${NIX_SSL_CERT_FILE:-}" -a -e "/etc/ssl/cert.pem" ]; then
NIX_SSL_CERT_FILE="/etc/ssl/cert.pem"
fi
# Set env
echo "$HOME/.nix-profile/bin" >> $GITHUB_PATH
echo "NIX_PROFILES=/nix/var/nix/profiles/default $HOME/.nix-profile" >> $GITHUB_ENV
echo "NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER" >> $GITHUB_ENV
echo "NIX_SSL_CERT_FILE=$NIX_SSL_CERT_FILE" >> $GITHUB_ENV