Overide modules with flakes

I have a flake with inputs for nixos-21.05 and nixos-unstable. I want to use most modules form nixos-21.5. But some I want to override with the module from nixos-unstable. How can I do that?

Try this: NixOS - NixOS 21.05 manual

I seen that, but it depends on channels which I don’t won’t to use them. I think they don’t even work with flakes.

Disabling the original modules can be done as described in the manual, then you import the other like this:

imports = [ "${nixpkgs-unstable}/nixos/modules/foo/bar/baz.nix" ];

(Assuming that nixpkgs-unstable is the name of the input and that it is currently in scope.


imports = [ "${nixpkgs-unstable}/nixos/modules/foo/bar/baz.nix" ];

i got an infinite loop error
but with

specialArgs {
        unstableModule = "${nixpkgs-unstable}/nixos/modules/foo/bar/baz.nix";

and then

imports = [ unstableModule ];

it worked