How to prevent flake from downloading registry at every flake command?

it constantly annoys me it taking 3-5 seconds downloading the flake registry when it is irrelevant

I don’t know if there’s a way to decrease the frequency in which the registry is checked for updates.
But something I do (and you may find even better) is pinning the registry to use the same version of nixpkgs as your system.

{
  nix.registry.nixpkgs.flake = inputs.nixpkgs; # For flake commands
  nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; # For legacy commands
}

I’m not sure if there’s a way to get overlays working with this, that would be fun.

2 Likes

In addition to what @lelgenio did, you can also do this to avoid downloading the flake registry altogether

  inputs.flake-registry = {
    url = "github:nixos/flake-registry";
    flake = false;
  };
  nix.settings.flake-registry = "${inputs.flake-registry}/flake-registry.json";
2 Likes

I’m setting

nix.nixPath = [ "nixpkgs=${pkgs.path}" ];

which, if I understand correctly, takes the default pkgs instantiation of nixpkgs after applying overlays. So that should work?

I don’t think that works, I tried using this:

nix.registry.nixpkgs.to = {
  type = "path";
  path = pkgs.path;
};
nix.nixPath = [ "nixpkgs=${pkgs.path}" ];

And neither nix run (uses registry) nor comma (uses nixPath) could find packages from overlays.

Ah, interesting, but you got the normal nixpkgs then?
Could this have to do with lazyness? I think there are some gurus that understand in-depth nixpkgs instantiation here?

So then maybe an explicit instance could help? Something like

nix.nixPath [ "nixpkgs=${import inputs.nixpkgs { inherit (pkgs) system config; overlays = [ ... ]; }}" ];

But I guess this is kind of ugly (a new nixpkgs instance), so there must be a better way?