There are probably a few dozen posts of me doing this, but this stuff can indeed be hard to find. Here’s one more:
# flake.nix
{
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz";
nixpkgs-unstable.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
};
outputs = { nixpkgs, ... }@inputs: {
nixosConfigurations.foo = nixpkgs.lib.nixosSystem {
specialArgs.flake-inputs = inputs;
modules = [ ./configuration.nix ];
};
};
}
# configuration.nix
{ pkgs, flake-inputs, ... }: {
environment.systemPackages = [
flake-inputs.nixpkgs-unstable.legacyPackages.${pkgs.stdenv.hostPlatform.system}.bar
];
# All your other config
}
Note that your settings from nixpkgs.config wil not apply to the unstable instance. If you want to use unfree packages from unstable, use nixpkgs-unfree. This is just a limitation of flakes, they need to be redesigned to be able to handle that specific use case properly.
You can technically use import, since a flake resolves to its path in /nix/store, and nixpkgs happens to contain a default.nix that does what you’d expect, but at that point you’re bypassing the entire flake concept and should just switch to npins.
I’ll also point out that, depending on your use case, overriding the source of the package you’d like to use from unstable is often a better idea than to do multi-nixpkgs setups.