Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lf- opened this issue Oct 2, 2023 · 5 comments
Open
Labels
fetching Networking with the outside (non-Nix) world flakes performance

Comments

@lf-
Copy link
Member

lf- commented Oct 2, 2023

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 👍 to issues you find important.

@lf- lf- added the bug label Oct 2, 2023
@roberth roberth added fetching Networking with the outside (non-Nix) world flakes performance and removed bug labels Oct 6, 2023
@hraban
Copy link
Member

hraban commented Jun 23, 2024

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-
Copy link
Member Author

lf- commented Jun 23, 2024

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

@hraban
Copy link
Member

hraban commented Jun 23, 2024

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-
Copy link
Member Author

lf- commented Jun 23, 2024

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
Copy link
Member

hraban commented Jul 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetching Networking with the outside (non-Nix) world flakes performance
Projects
None yet
Development

No branches or pull requests

3 participants