Commit dd94878
Fix GitHub API rate limiting in cli-tests (#2731)
## Problem
The cli-tests on the `main` branch have been failing intermittently in
GitHub Actions since at least October 7, 2025, due to GitHub API rate
limiting when Nix attempts to fetch nixpkgs metadata.
### Error Message
```
unable to download 'https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable': HTTP error 403
API rate limit exceeded for 13.105.49.133.
```
Despite having `GITHUB_TOKEN` configured in both `NIX_CONFIG`
environment variable and `~/.config/nix/nix.conf`, the tests were still
hitting unauthenticated rate limits.
## Root Cause
On macOS runners, the Nix daemon:
- Runs as a different user (not the runner user)
- Reads `/etc/nix/nix.conf` instead of the user's
`~/.config/nix/nix.conf`
- Doesn't inherit environment variables from the runner
This meant that while `nix show-config` showed the access token was
configured, the daemon wasn't actually using it when making GitHub API
requests.
## Solution
This PR implements a two-pronged approach:
### 1. Configure Nix Daemon Properly (Primary Fix)
- On macOS runners, configure `/etc/nix/nix.conf` with the GitHub token
- Ensure the directory and file exist before writing
- Restart the Nix daemon to pick up the new configuration
- In `auto-nix-install` job, configure AFTER Nix is installed (not
before)
### 2. Pass Token via Command-Line Options (Backup)
- Modify `internal/nix/command.go` to pass `--option access-tokens
github.com=$GITHUB_TOKEN` in all nix commands
- This ensures the token is used even if config files aren't picked up
properly
## Changes
- `.github/workflows/cli-tests.yaml`:
- Update "Setup Nix GitHub authentication" step to ensure
`/etc/nix/nix.conf` exists before writing
- Reorder `auto-nix-install` job to configure Nix AFTER installation
completes
- `internal/nix/command.go`: Add GITHUB_TOKEN to nix command args as
--option access-tokens
## Detailed Analysis
For a comprehensive diagnostic report with evidence, timeline, and
alternative solutions considered, see:
**[CLI Tests Failure
Report](https://gist.github.com/savil/e8a527aa70e38ab588a1bd46103123bd)**
## Note on Reproduction
The issue is specific to GitHub Actions environment and cannot be easily
reproduced locally:
- Requires GitHub Actions runner IP pool hitting rate limits
- Intermittent based on shared quota across GitHub Actions
- Depends on macOS Nix daemon configuration
This PR validates the fix directly in CI/CD where the issue occurs.
Fixes the intermittent test failures that have been occurring since
October 7, 2025.
---------
Co-authored-by: Claude <[email protected]>1 parent 75f7e56 commit dd94878
2 files changed
+46
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
184 | 203 | | |
185 | 204 | | |
186 | 205 | | |
| |||
222 | 241 | | |
223 | 242 | | |
224 | 243 | | |
225 | | - | |
226 | | - | |
| 244 | + | |
| 245 | + | |
227 | 246 | | |
228 | 247 | | |
229 | 248 | | |
| 249 | + | |
230 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
231 | 266 | | |
232 | 267 | | |
233 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
8 | 17 | | |
9 | 18 | | |
10 | 19 | | |
| |||
0 commit comments