gytis-ivaskevicius / flake-utils-plus

Use Nix flakes without any fluff.
MIT License
494 stars 54 forks source link

fix: Override option nixpkgs.config to avoid failed assertion #144

Closed lordkekz closed 6 months ago

lordkekz commented 7 months ago

Fixes #142

Note that other modules could conceivably be affected if they read the value of config.nixpkgs.config, but I find that exceedingly unlikely.

gytis-ivaskevicius commented 7 months ago

why mkforce is required there?

lordkekz commented 7 months ago

Because we need to override the value that other modules have set. Let's say nixpkgs.config is being set by some module cheese.nix

{ config, outputs, lib, ... }: {
  nixpkgs.config.allowUnfree = true;
}

And flake-utils-plus will add a module similar to this:

{ config, outputs, lib, ... }: {
  nixpkgs.pkgs = // generated from channels
}

Now, nixpkgs will throw an assertion failure because you can only set either nixpkgs.config or nixpkgs.pkgs but not both. In the nixpkgs.pkgs which flake-utils-plus generates, the value nixpkgs.config is being applied, so we won't lose information by using the generated pkgs.

To get rid of the nixpkgs assertion failure, we need to reset nixpkgs.config to an empty set in the final evaluation; to override the nixpkgs.config which cheese.nix presumably sets without mkDefault or such, we need to choose a higher priority, like mkForce. If we used a priority less than or equal to the definitions in cheese.nix, it would have no effect.

I think it's fine to use mkForce here because no user could ever want to override it; doing so would just break the configuration.

gytis-ivaskevicius commented 6 months ago

Thanks!