Best way to use an package from unstable in a stable nixos

Hi all,

I have a nixos based on the stable channel. However, I need to cherry-pick some packages from unstable. I succeed in for classic packages by using an on overlay this way:

....
 outputs = { nixos-hardware, home-manager, nixos, nixos-unstable, ... }:
    let
      system = "x86_64-linux";
 
      pkgs = import nixos {
        inherit system;
        config.allowUnfree = true;
      };
      unstable-pkgs = import nixos-unstable {
        inherit system;
        config.allowUnfree = true;
      };
      nixpkgs.overlays = [
        (final: prev: {
          vivaldi = unstable-pkgs.vivaldi;
          });
        ];
    in
    {
      nixosConfigurations = {
 mysystem = nixos.lib.nixosSystem {
          inherit system;
          modules = [
            ({
             inherit nixpkgs;
            })
...

However, I would like to also cherry-pick some python packages without success for the moment.
If I try to add them the same way as other apps it just breaks the installation of python. Here is the way I tried:

....
outputs = { nixos-hardware, home-manager, nixos, nixos-unstable, ... }:
   let
     system = "x86_64-linux";

     pkgs = import nixos {
       inherit system;
       config.allowUnfree = true;
     };
     unstable-pkgs = import nixos-unstable {
       inherit system;
       config.allowUnfree = true;
     };
     nixpkgs.overlays = [
       (final: prev: {
         python3Packages.typer = unstable-pkgs.python3Packages.typer;
         });
       ];
   in
   {
     nixosConfigurations = {
mysystem = nixos.lib.nixosSystem {
         inherit system;
         modules = [
           ({
            inherit nixpkgs;
           })
...

Any idea of the best way to do that?

You can pass unstable-pkgs to your modules using specialArgs and use it like

....
 outputs = { nixos-hardware, home-manager, nixos, nixos-unstable, ... }:
    let
      system = "x86_64-linux";
 
      pkgs = import nixos {
        inherit system;
        config.allowUnfree = true;
      };
      unstable-pkgs = import nixos-unstable {
        inherit system;
        config.allowUnfree = true;
      };
    in
    {
      nixosConfigurations = {
 mysystem = nixos.lib.nixosSystem {
          inherit system;
          specialArgs = { inherit unstable-pkgs; }
          modules = [
            ({pkgs, unstable-pkgs, ...}:
              {
                environment.systemPackages = [ 
                  pkgs.jq # get jq from stable branch
                  unstable-pkgs.vivaldi # get vivaldi from unstable branch
                  ];
              })
...

Sory for bad formatting i am cutruntly on phone

Thanks for the answer. I don’t want to do that because I don’t want to modify all the modules I use afterward. I would like those modules not knowing I override them.