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":""}' -> '{"etag":"\"4f4e3dbe9bfed1b95cd7e4a7be99db115891a48c12a2fb3337241d2043844588\"","url":""}', '/nix/store/h10gk87i8p5j5ii0viz0ss67cx345bwx-flake-registry.json'
looked up 'flake:nixpkgs' -> 'github:NixOS/nixpkgs/nixpkgs-unstable'
ignoring disappeared cache entry '{"name":"source","type":"file","url":""}'
downloading ''...
starting download of
finished download of ''; curl status = 0, HTTP status = 401, body = 90 bytes
       … while fetching the input 'github:NixOS/nixpkgs/nixpkgs-unstable'

       error: unable to download '': HTTP error 401

       response body:

         "message": "Bad credentials",
         "documentation_url": ""
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 works just fine.

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

1 Like

That was it! Thank you!