NixOS, Flakes packages from unstable

This is my noob config for NixOS.
flake.nix:

{
  description = "My Super Duper NixOS Configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = inputs @ {
    self,
    nixpkgs,
    nixpkgs-unstable,
    ...
  }: let
    system = "x86_64-linux";
    lib = nixpkgs.lib;
    pkgs = nixpkgs.legacyPackages.${system};
    pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
  in {
    nixosConfigurations = {
      nixsrv1-1 = lib.nixosSystem {
        inherit system;
        modules = [
          ./hosts/nixsrv1-1/configuration.nix
        ];
        specialArgs = {
          inherit nixpkgs-unstable;
        };
      };
    };
  };
}

packages.nix:

{
  config,
  lib,
  pkgs,
  pkgs-unstable,
  ...
}: {
  environment.systemPackages = with pkgs-unstable; [
    alejandra
  ];
}

Error:

error: attribute 'pkgs-unstable' missing

I don’t understand this problem. Please give me some input!

Thanks

Where are you importing/calling packages.nix? It seems like pkgs-unstable is not passed there.

Hi @robsliwi, packages.nix is listed in: hosts/nixsrv1-1/configuration.nix:

{
  config,
  lib,
  pkgs,
  pkgs-unstable,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
    ./network.nix
    ./packages.nix

    ...

  ];

...

}

This one is passing nixpkgs-unstable through the modules, on the other side you’re expecting pkgs-unstable as an attribute:

Now you have basically two options: change the name of the attribute/parameter in both configuration and packages.nix or pass pkgs-unstable in the specialArgs.

And the following is worth a read: Mixing stable and unstable packages on flake-based NixOS system - #4 by waffle8946

Does it help somehow? :slight_smile:

1 Like

Yes, thank you! This was my problem :slight_smile:

New package.nix:

{
  inputs,
  config,
  pkgs,
  pkgsUnstable,
  ...
}: {
  _module.args.pkgsUnstable = import inputs.nixpkgs-unstable {
    inherit (pkgs.stdenv.hostPlatform) system;
    inherit (config.nixpkgs) config;
  };

  environment.systemPackages = with pkgsUnstable; [
    alejandra
  ];
}

Works!