-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.envrc
115 lines (94 loc) · 4.27 KB
/
.envrc
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# First, check for a supported nix version
MSNV="2.14.0"
OURNV=$(nix eval --raw --expr "builtins.nixVersion")
vercomp=$(nix eval --expr "builtins.compareVersions \"${OURNV}\" \"${MSNV}\"")
if [ "$vercomp" = "-1" ]; then
cat <<-EOF
ERROR: Your Nix is older than the "Minimum Supported Nix Version" (MSNV).
Your Nix: ${OURNV}
MSNV: ${MSNV}
This build can't be guaranteed to succeed correctly or be free of bugs that
the system may otherwise guarantee.
If you can't freely upgrade Nix, then please open a discussion if you would
like the minimum supported Nix version to be adjusted.
EOF
[ -z "$NIX_ALLOW_UNSUPPORTED_VERSION" ] && exit 1
printf "NOTICE: Continuing despite unsupported Nix version.\n\n"
fi
# Next, check that the user is trusted, so the out-of-band binary cache
# can be used (this is required even with ca-derivations)
if ! nix show-config | grep -q "trusted-users =.*${USER}" ; then
cat <<-EOF
ERROR: Your user account must be part of the 'trusted-users' setting in your
Nix configuration to use this project. Please add '$USER' to the
'trusted-users' setting in either:
- your /etc/nixos/configuration.nix
- your /etc/nix/nix.conf
EOF
exit 1
fi
# Make sure the user has [ref:ca-derivations] enabled; otherwise, the ability to fetch
# derivations via Nix won't work due to the lack of self-authentication.
if ! nix show-config | grep -q 'experimental-features.*ca-derivations'; then
cat <<-EOF
ERROR: You must enable the "ca-derivations" in your Nix configuration to use
this project. See https://nixos.wiki/wiki/Ca-derivations for more information
and modify either:
- your /etc/nixos/configuration.nix'
- your /etc/nix/nix.conf'
EOF
exit 1
fi
# Enable the nix-community direnv integration
if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then
source "./buck/nix/etc/nix_direnvrc"
fi
# [tag:nix-direnv-watch-nix-files] Make sure we watch all files relevant to the
# "boostrap phase" here, so that changes appropriately cause the shell to be
# reloaded. Any extra nix files situated near the Flake should be added here.
nix_direnv_watch_file buck/nix/buck2/Cargo.lock buck/nix/buck2/default.nix
nix_direnv_watch_file buck/nix/toolchains/default.nix
nix_direnv_watch_file buck/nix/flake.nix buck/nix/flake.lock
# Enable the flake
use flake ./buck/nix --accept-flake-config
# Disable the log uploader in buck2, since it's not useful for us right now.
# XXX FIXME (aseipp): rethink this if we ever enable reapi support
export BUCK2_TEST_DISABLE_LOG_UPLOAD=true
# [tag:auto-watchman] In order to help keep track of files more accurately, we
# use Watchman, and we automatically start it if it's not already running, and
# the user has allowed it. This is a bit of a hack, but it helps keep the shell
# environment clean.
if [ "$(uname)" = "Darwin" ]; then
# XXX FIXME (aseipp): macOS support
echo "direnv: watchman: not enabling, because we're on macOS"
elif [ ! -f .use_watchman ] && [ -z "$CI_RUNNING" ]; then
# XXX FIXME (aseipp): prompt about this file to the user
echo "direnv: watchman: not enabled, because .use_watchman is missing, and we're not in a CI build"
else
[ "$CI_RUNNING" = "true" ] && \
echo "direnv: watchman: enabling, because we're running in a CI build"
# XXX FIXME (aseipp): shouldn't require systemd on Linux, but in practice
# systemd is the only option for multi-user Nix and the only thing supported by
# upstream, so it is what it is.
[ ! -d /run/systemd/system ] && \
echo "direnv: watchman: ERROR: cannot enable, because you aren't using systemd" && \
exit 1
export WATCHMAN_SOCK=$HOME/.watchman-socket
if ! systemctl --user is-active --quiet watchman; then
echo "direnv: watchman: no service active; starting a transient watchman.service user unit..."
systemd-run -q --user \
-u watchman.service \
--working-directory=$HOME \
-p StateDirectory=watchman \
-p StandardOutput=journal \
-p Restart=on-failure \
watchman --foreground \
-u "$WATCHMAN_SOCK" \
--logfile="$HOME/.config/watchman/log" \
--statefile="$HOME/.config/watchman/state" \
--pidfile="$HOME/.config/watchman/pid"
echo "direnv: watchman: ok, see 'systemctl --user status watchman.service' for details"
else
echo "direnv: watchman: service is already active, continuing..."
fi
fi