Nix commands fail Github requests (401) without sudo

I’m running NixOS 23.05 with a flake-based system configuration, and any nix commands and nixos-rebuild both fail to download anything from Github with the following error (including output with --debug --show-trace):

acquiring write lock on '/nix/var/nix/temproots/24436'
using cache entry '{"name":"flake-registry.json","type":"file","url":"https://channels.nixos.org/flake-registry.json"}' -> '{"etag":"\"4f4e3dbe9bfed1b95cd7e4a7be99db115891a48c12a2fb3337241d2043844588\"","url":"https://channels.nixos.org/flake-registry.json"}', '/nix/store/h10gk87i8p5j5ii0viz0ss67cx345bwx-flake-registry.json'
looked up 'flake:nixpkgs' -> 'github:NixOS/nixpkgs/nixpkgs-unstable'
ignoring disappeared cache entry '{"name":"source","type":"file","url":"https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable"}'
downloading 'https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable'...
starting download of https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable
finished download of 'https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable'; curl status = 0, HTTP status = 401, body = 90 bytes
error:
       … while fetching the input 'github:NixOS/nixpkgs/nixpkgs-unstable'

       error: unable to download 'https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable': HTTP error 401

       response body:

       {
         "message": "Bad credentials",
         "documentation_url": "https://docs.github.com/rest"
       }
download thread shutting down

That example was with nix search nixpkgs zsh, but any nix command does this. The older non-flake commands, like nix-shell, do not do this, however.

These commands work as normal if I run them as root with sudo.

Does anyone have any tips for debugging this?

Oh, and interestingly, curl-ing the URL manually with curl https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable works just fine.

Is the access-tokens setting present in any nix.conf file?

1 Like

That was it! Thank you!

2 Likes