NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
11.59k stars 1.45k forks source link

nix refetches the global registry json pointlessly for locally overriden flakes #9087

Open lf- opened 9 months ago

lf- commented 9 months ago

Describe the bug

This is arguably in some respects the same bug as #7075 but only takes ${timeToCompleteHttpRequest}.

Given the following setup, nix will refetch the global registry when building things from non-fully-qualified flake reference:

~ » cat ~/.config/nix/registry.json
{
  "flakes": [
    {
      "from": {
        "id": "nixpkgs",
        "type": "indirect"
      },
      "to": {
        "lastModified": 1692557222,
        "narHash": "sha256-TCOtZaioLf/jTEgfa+nyg0Nwq5Uc610Z+OFV75yUgGw=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "0b07d4957ee1bd7fd3bdfd12db5f361bd70175a6",
        "type": "github"
      }
    }
  ],
  "version": 2
}

~ » nix run --debug nixpkgs#hello
performing daemon worker op: 11
acquiring write lock on '/nix/var/nix/temproots/2597173'
performing daemon worker op: 1
using cache entry '{"name":"flake-registry.json","type":"file","url":"https://channels.nixos.org/flake-registry.json"}' -> '{"etag":"W/\"5af996fe37b5c4ba47ef9b3d545ba977b527e2dcdc6e926dda7787b7db6bcf6e\"","url":"https://channels.nixos.org/flake-registry.json"}', '/nix/store/5fjljy6g6l4lfdxcb1hjkg4bwrs2kqpx-flake-registry.json'
downloading 'https://channels.nixos.org/flake-registry.json'...
starting download of https://channels.nixos.org/flake-registry.json
finished download of 'https://channels.nixos.org/flake-registry.json'; curl status = 0, HTTP status = 304, body = 0 bytes

Steps To Reproduce

  1. Pin nixpkgs or another flake in the user or system registry.json
  2. nix run --debug nixpkgs#hello
  3. Observe that nix is performing a network request unnecessarily

Expected behavior

Nix should not refetch the registry if it can resolve the flake reference entirely locally.

nix-env --version output

~ » nix-env --version nix-env (Nix) 2.17.0

Additional context

Priorities

Add :+1: to issues you find important.

hraban commented 1 month ago

Particularly inconvenient when debugging a network issue with a tool you know is in the store but you can't use nix shell nixpkgs#..., even with nixpkgs pinned, because it wants to fetch the registry first.

lf- commented 1 month ago

FYI this bug is fixed in https://lix.systems because we simply vendored the flake registry.

hraban commented 4 weeks ago

FYI this bug is fixed in https://lix.systems because we simply vendored the flake registry.

It definitely seems sensible to allow pinning the registries list itself, along with the individual pins.

lf- commented 4 weeks ago

Actually you can do that today if you want, set flake-registry to a path to a download of the json file from https://github.com/nixos/flake-registry in nix.conf, and it will just work IIRC! When we vendored it, the patch was totally trivial because basically all that support already exists in CppNix. Or you can set it to empty string and it will disable the online registry.

The real boon of Lix's strategy is it's fixed by default and so we can honestly call this bug fixed in Lix despite barely changing the code because un-fixing it requires re-enabling the online flake registry fetch functionality that we simultaneously deprecated.

hraban commented 2 weeks ago

Actually you can do that today if you want, set flake-registry to a path to a download of the json file from https://github.com/nixos/flake-registry in nix.conf, and it will just work IIRC!

Perfect! This is 👌 and should absolutely be the default. One fewer round trip! And no network calls at all for packages in the store. Very nice, thank you.