Flake registry from a private GitHub repo?

I’m trying to use a flake registry to see if that would help us syncing our projects’ dependencies and make our cache a bit more useful and cut down on times individual developers are stuck waiting for a massive rebuild of Haskell packages.

Ideally I’d like to keep the registry file, flake-registry.json, in private repo on GitHub, but I can’t work out if there’s a way to set the nixConfig.flake-registry so it works. All I find online suggests that if I want to fetch an individual file using curl then I’ll need to add headers to the request… something that I don’t think is possible to set up using nixConfig in a flake. Or is it?

I’ve also tried using URIs with the protocol 'git+httpsbut that seems to not be supported for theflake-regsitry` (even though it works fine for inputs).

Is there a way to do this at all?

It’s actually possible to download a raw file from a private repo using a URL like

  nixConfig.flake-registry = "https://${GITHUB_TOKEN}@raw.githubusercontent.com/<user|org>/<repo>/<branch>/flake-registry.json";

but I’m not sure it’s possible to read the GitHub token from the environment.

I configure my system to set system registry entries with nix.registry such as

    nix.registry = {
      nixpkgs = {
        from.type = "indirect";
        from.id = "nixpkgs";
        to.type = "git";
        to.url = "file:///nix/nixpkgs";
      };
      nixos-hardware = {
        from.type = "indirect";
        from.id = "nixos-hardware";
        to.type = "git";
        to.url = "file:///nix/flake-cache/nixos-hardware.git";
      };
    };

or

  nix.registry = {
    nixpkgs = {
      from = {
        type = "indirect";
        id = "nixpkgs";
      };
      to = {
        type = "git";
        url = "https://github.com/nixos/nixpkgs.git";
      };
    };
    nixos-hardware = {
      from = {
        type = "indirect";
        id = "nixos-hardware";
      };
      to = {
        type = "git";
        url = "https://github.com/nixos/nixos-hardware.git";
      };
    };
  };

nix registry list then shows those entries.

However, as far as I can tell, nixos-rebuild still pulls global flake:nixpkgs unless the root flake has a value for inputs.nixpkgs.url. I haven’t yet tried to figure out why.

There is currently a bug in nix that ignores any but the global registry under some commands.

It is fixed on master IIRC.

2 Likes

It’s also fixed in nixpkgs-unstable and nix 2.28.3

4 Likes