Option does not exist for nixpkgs-unstable, while it exists for nixpkgs

Hi, sorry for possibly confusing title, but I have this strange problem. I’m trying to transistion to flake NixOS and I need to use two nixpkgs: stable one (23.11) and unstable. A code snippet down below explains it:

  description = "A simple NixOS flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";

  outputs = { self, nixpkgs, nixpkgs-unstable }: {
    nixosConfigurations.ms-7d48 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        # This works, spits out grub-related error, it's ok
        ({ ... }: { nixpkgs.config.allowUnfree = true; } )

        # This doesn't, says: "error: The option 'nixpkgs-unstable' does not exist. Definition values:..."
        ({ ... }: { nixpkgs-unstable.config.allowUnfree = true; } )

What am I doing wrong here?

If I replace url for 23.11 with unstable, it still works. This is so confusing. Is it a bug?

nixpkgs.config is a name of a NixOS option that allows configuring the Nixpkgs instance of the NixOS system. (The nixpkgs part of the option is a name of an attribute in an attribute, it is unrelated to the name of your input variable.) If you use nixpkgs.lib.nixosSystem, the Nixpkgs instance configured will be nixpkgs (though only within the bounds of NixOS). If you used nixpkgs-unstable.lib.nixosSystem, it would be nixpkgs-unstable.

You can pass nixpkgs-unstable to Nix expressions such as NixOS modules e.g. using specialArgs or _module.args but NixOS will not be able to give it any special consideration. If you want to configure such Nixpkgs instances, you will need to do it at the time of instantiation.

  pkgs-unstable = import nixpkgs-unstable {
    system = "x86_64-linux";
    config = {
      allowUnfree = true;
in nixpkgs.lib.nixosSystem {
 # …

Just to inform you: your flake input for unstable is named nixpkgs-unstable but it is referring to the master branch. There is also a unstable branch, which is probably what you want.

1 Like

Thanks for explaining, a little bit confusing, but it works now.

Thanks for mentioning it, I didn’t notice.