blog.anqou.net
rss
author
tags

nix flake update で GitHub authenticated request を使う

GitHub へのアクセスにはレートリミットが存在し、適当にアクセスしていると容易く制限に引っかかることがあります。 Nix のエコシステムは GitHub にかなり強く依存しており、特に nix flake update のようなコマンドは GitHub にアクセスできないと以下のようなエラーを出して正しく動作してくれません:

$ nix flake update
warning: error: unable to download 'https://api.github.com/repos/NixOS/nixpkgs/commits/nixos-25.11': HTTP error 403

       response body:

       {"message":"API rate limit exceeded for 198.51.100.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}; using cached version

エラーメッセージを読むと分かるように、GitHub への authenticated request(つまりログインした状態でのリクエスト)を用いれば、このレートリミットを緩和することができます。 nix flake update の場合 --option access-tokens を使うことで GitHub の API トークンを渡し authenticated request を使わせられます。例えば gh コマンドのセットアップを仮定すると次のように実行します:

nix flake update --option access-tokens "github.com=$(gh auth token)"