Simple overlay causing infinite loop

This overlay (I just want git gui to work without installing gitFull):

  nixpkgs.overlays = [
    (_final: prev: {
      git = prev.git.override {
        guiSupport = true;
      };
    })
  ];

results in an infinite loop:

error:
       … while checking flake output 'nixosConfigurations'
         at /nix/store/4zvfbmfiqk9dafn99m43kpqwc3z94skk-source/flake.nix:45:7:
           44|       };
           45|       nixosConfigurations.ci = nixpkgs.lib.nixosSystem {
             |       ^
           46|         inherit system;
       … while checking the NixOS configuration 'nixosConfigurations.ci'
         at /nix/store/4zvfbmfiqk9dafn99m43kpqwc3z94skk-source/flake.nix:45:7:
           44|       };
           45|       nixosConfigurations.ci = nixpkgs.lib.nixosSystem {
             |       ^
           46|         inherit system;
       … while evaluating the option `system.build.toplevel':
       … while evaluating definitions from `/nix/store/6zgxj37rf9nsf5r0pd4pvwdazpbpnqi4-source/nixos/modules/system/activation/top-level.nix':
       … while evaluating the option `services.openssh.extraConfig':
       … while evaluating the option `services.openssh.sftpServerExecutable':
       (stack trace truncated; use '--show-trace' to show the full, detailed trace)
       error: infinite recursion encountered

It seems like a pretty straightforward overlay, so I’m unsure what’s causing it.

You can’t write such an overlay because guiSupport adds tk, which has git in its buildtime closure.

$ nix why-depends --derivation nixpkgs#{tk,git}
/nix/store/af0m673vb1wqzsh4viq5pi6a5ia6fm2q-tk-8.6.15.drv
└───/nix/store/3vglhiwwgdf2aj7rp95lh0zbmj6vqirw-libXft-2.3.8.drv
    └───/nix/store/2i34cd1sarmp7bf0lj9hy87kkdnihlr5-fontconfig-2.15.0.drv
        └───/nix/store/bcvbxza1wyq4hw20c9wi5x198iwzb1pr-dejavu-fonts-minimal-2.37.drv
            └───/nix/store/ni65ys6a33lnklcazf9msq8rk3i19y4y-dejavu-fonts-full-2.37.drv
                └───/nix/store/6ap8wizi70f7k8wsb8mm2g5rpxr3lyyg-fontforge-20230101.drv
                    └───/nix/store/wwgysj42lha5dwipaf03n8bgh35gpxpq-libtiff-4.7.0.drv
                        └───/nix/store/wp16i0pn0bi0z633smxkkzi6fci1dhn5-python3.12-sphinx-8.1.3.drv
                            └───/nix/store/ricj6x7q89drx8dxf7pza6hqga0s7g98-python3.12-filelock-3.16.1.drv
                                └───/nix/store/lqv4z47hfa7rxq5rhgwwgafpz0xbg5c9-python3.12-hatch-vcs-0.4.0.drv
                                    └───/nix/store/6hxm579sz8lm5nqvn6k11qyk4f1d9l32-git-2.47.2.drv
1 Like

By curiosity, how this guiSupport could ever work, even without overlay?

git with gui support depends on git without gui support. not an infrec.

1 Like

I just assume that having git with gui support enabled it the actual goal.
If yes that i would not use overlays for this, as an overlay interfere with build/bootstrapping of nixpkgs.
So overriding some basic thing like git would result in a full/nearly full system rebuild.
I think that is not intended.

A better approach here IMHO is to acutally override the package and use that instance for the system closure.

So assuming you have enabled git via progams.git.enable = true, you could set

   programs.git.package = (pkgs.git.override {
        guiSupport = true;
      });

Which should to the job.

If you just added it to the environment.systemPackages do something like

   environment.systemPackages = [
  ....
   (pkgs.git.override {
        guiSupport = true;
      })
   ....
   ];

Yeah that appears to be what they were doing already, and I agree that’s the most maintainable approach here.

The reason I ran into this was that I was trying to work around a situation I got into recently, trying to make sure both the root repo and my personal settings would evaluate without --impure (making this an X-Y problem, it seems :grimacing:). For some unknown reason I’m running into the following error when trying to nix flake check on my private repo:

       error: The option `home-manager.users.victor.programs.git.package' is defined multiple times while it's expected to be unique.

       Definition values:
       - In `/nix/store/k8nkf470zpidpa5nh76lh2x6rxfzpwa4-source/flake.nix': <derivation git-2.47.1>
       - In `/nix/store/1a77vx5nwg5zfbhn536c6si02zfxfm80-source/modules/home-manager.nix': <derivation git-2.47.1>
       Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

I didn’t know how I should fix this. home-manager.users.victor.programs.git.package is only defined in the root repo, but I do set up other things using Home Manager in my private repo, so I’m guessing that’s where the duplicate definition is coming from. But setting mkForce or mkDefault seems a bit like using !important in CSS - something which is bound to come back to bite me if I use it, and something which is probably avoidable by doing the Right Thing™.

Well an overlay is essentially replacing a given attribute everywhere it’s used with respect to a given nixpkgs instance.
If you think mkOverride/mkDefault/mkForce is a hammer, an overlay is like a wrecking ball.

Ultimately any option you choose will have downstream consequences, but setting mkDefault in your root repo seems to be the closest to what you want to do here if you want downstream configs to be able to override that default.

EDIT: and the comparison to CSS doesn’t entirely work here, because in CSS, you can always override the defaults by using narrower selectors; there’s no analogue in the module system, so you must use mkOverride and friends if you want to define an option in multiple modules within the same config.

2 Likes

This does not seem to get rid of the error:

package = lib.mkDefault (
  import ../overrides/git-extras {
    package = pkgs.git.override {
      guiSupport = true;
    };
  }
);

Huh. Same with mkForce.

Are you setting mkDefault in one place or both places?

Only in one. As mentioned, I only set home-manager.users.victor.programs.git.package in one place; the other repo just happens to set some other Home Manager settings.

(On a related note, I can’t make heads or tails of the error messages. It keeps saying one of the definitions is in /nix/store/k8nkf470zpidpa5nh76lh2x6rxfzpwa4-source/flake.nix, but there’s no Git package defined there.)