Conflict between overlays and pkgs options (using flakes?)

I use an overlay to “inject” the stable pkgs into the unstable branch, but I get a conflict with a pkg option that uses the same keyword, stable.

  • pkgs.stable: I use the overlay below so that I can use pkgs from the stable branch if they are broken on unstable. I’m unsure if this implementation is the recommended one, I’m still learning.
  • The kicad package defines an option called stable (see here) .

It turns out that the kicad option conflicts with the overlay. I can not install the package but get instead a cryptic error that I traced back to this issue:

   error: expected a Boolean but found a set: { _type = "pkgs"; AAAAAASomeThingsFailToEvaluate = «thunk»; AMB-plugins = «thunk»; ArchiSteamFarm = «thunk»; AusweisApp2 = «thunk»; BeatSaberModManager = «thunk»; CHOWTapeModel = «thunk»; ChowCentaur = «thunk»; ChowKick = «thunk»; ChowPhaser = «thunk»; «19881 attributes elided» }
   at /nix/store/xnjw9gmfmpppdj6bxpw6cfkspc3h6xwl-source/pkgs/applications/science/electronics/kicad/default.nix:276:20:
      275|   meta = rec {
      276|     description = (if (stable)
         |                    ^
      277|     then "Open Source Electronics Design Automation suite"

This is unexpected (for me) since one is a package option and the other should be nested under pgks. How should I go about this? Running KiCAD from nix-shell works as expected.


Appendix

Stable overlay on unstable, in file stable.nix:

{ inputs, ... }:
let
  overlay-stable = final: prev: {
    stable = import inputs.nixpkgs-stable {
      system = "x86_64-linux";
      config.allowUnfree = true;
    };
  };
in
{
  nixpkgs.overlays = [ overlay-stable ];
}

Then, in my flake:

inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";

···

nixosConfigurations = {
    server = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        inherit inputs;
      };
      modules = [
        ./overlays
        ./nixos/hosts/server.nix
        home-manager.nixosModules.home-manager
      ];
    };
  };

I use flakes. Is this a flake specific issue? I’m quite new to this…

Instead of using overlays why not just access your stable package set via specialArgs. You already have inputs in your specialArgs, so you can just do this in a module:

{ inputs, pkgs, ... }:
let
  stable = inputs.nixpkgs-stable.legacyPackags.${pkgs.hostPlatform.system};
in {
}

If you don’t like adding ${pkgs.hostPlatform.system} everytime. you can add another special arg to short hand it i.e. add an stable special arg.
This is also more explicit and faster. Notice that each overlay you add makes your nixos evaluation noticeable slower because nix has to process another fix point.

1 Like

I managed to overcome the issue with the following snippet. But I remain skeptic, how come that the scope of my overlay stable clashes with the package option stable?

home.packages = with pkgs; [
  (kicad-small.override {
    stable = true;
  })
];

Thanks for the tip! I’ll give this a go and see if it works for me. I have no reason to use the overlay approach I described above. I’ll try the specialArgs approach then :slight_smile:

This is probably because of pkgs.callPackage, which for a given “function returning a derivation” will try to inject function arguments with the same name from pkgs. So the stable argument in kicad gets filled out with pkgs.stable.

This is an unfortunate interaction of pkgs being a single flat namespace, and callPackage not understanding which arguments make sense to inject, so it just injects anything that has a matching name in pkgs.

3 Likes

That did the trick! I’ve replaced my stable overlay using extraArgs. I had a bit of trouble but found this tutorial: Downgrading or Upgrading Packages | NixOS & Flakes Book