forked from reflex-frp/reflex-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenable-nixcache
executable file
·31 lines (28 loc) · 1.21 KB
/
enable-nixcache
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
#!/usr/bin/env bash
set -euo pipefail
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. "$DIR/common-setup.sh"
nixconf="/etc/nix/nix.conf"
our_cache="https://nixcache.reflex-frp.org"
caches_line="binary-caches = https://cache.nixos.org $our_cache"
our_key="JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI="
keys_line="binary-cache-public-keys = ryantrinkle.com-1:$our_key cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
if [ ! -e "$nixconf" ] || ! grep -q 'binary-caches\|binary-cache-public-keys\|binary-caches-parallel-connections' "$nixconf" ; then
cat | sudo tee -a "$nixconf" <<EOF
$caches_line
$keys_line
binary-caches-parallel-connections = 40
EOF
elif ! grep -q "$our_cache" "$nixconf" || ! grep -q "$our_key" "$nixconf" ; then
backup="$nixconf.$(date -u +"%FT%TZ").bak"
sudo cp "$nixconf" "$backup"
echo "$nixconf already exists"
echo "backup saved at $backup"
echo "adding caches"
if ! grep -q "$our_cache" "$nixconf" ; then
sudo sed -i.bak 's|^\(binary-caches[ =].*\)$|\1 '"$our_cache"'|' "$nixconf"
fi
if ! grep -q "$our_key" "$nixconf" ; then
sudo sed -i.bak 's|^\(binary-cache-public-keys[ =].*\)$|\1 ryantrinkle.com-1:'"$our_key"'|' "$nixconf"
fi
fi