Load software from two different channels

Hello dear Nix wizards

So far I had the stable channel for most of the applications plus nixos-22.11 for just one application. And it was working fine

Now I would like to add the stable channel, nixos-22.11 and nixos-22.11 for applications of my choosing.

What I tried so far is:

nixpkgs.config = {
  # Allow proprietary packages
  allowUnfree = true;

  # Create an alias for the *22.11* channel, make sure to add the said channel
  packageOverrides = pkgs: {
    stable = import <nixos-22.11> {                 # pass the nixpkgs config to the stable alias
      config = config.nixpkgs.config;
    };
  };

  # Create an alias for the *unstable* channel, make sure to add the said channel
  packageOverridesUnstable = pkgs: {
    unstable = import <nixos-unstable> {            # pass the nixpkgs config to the stable alias
      config = config.nixpkgs.config;
    };
  };
};

...

  environment.systemPackages = with pkgs; [
    wget                     # stable channel 23.05
    unstable.curl        # nixos-unstable
    stable.restic         # nixos-22.11
    ...
  ];

I’ve added and updated the necessary channels:

$sudo nix-channel --list
home-manager https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz
nixos https://nixos.org/channels/nixos-23.05
nixos-22.11 https://nixos.org/channels/nixos-22.11
nixos-hardware https://github.com/NixOS/nixos-hardware/archive/master.tar.gz
nixos-unstable https://nixos.org/channels/nixos-unstable

I get the following error msg:

$ sudo nixos-rebuild switch
building Nix...
building the system configuration...
error: undefined variable 'unstable'

       at /home/usr/Dotfiles/CommonDotfiles/nixos/common.nix:331:5:

          330|     ## Gnome Apps
          331|     unstable.evince                           # GNOME's document viewer
             |     ^
          332|     gnome.gnome-terminal
(use '--show-trace' to show detailed location information)

thank you in advance for your answer!

You used packageOverridesUnstable instead of packageOverrides there, you need to include both in packageOverrides:

  # Create an alias for the *22.11* channel, make sure to add the said channel
  packageOverrides = pkgs: {
    stable = import <nixos-22.11> {                 # pass the nixpkgs config to the stable alias
      config = config.nixpkgs.config;
    };
    unstable = import <nixos-unstable> {            # pass the nixpkgs config to the stable alias
      config = config.nixpkgs.config;
    };
  };
2 Likes

Thank you very much Infinisil

Will try it out tomorrow, for now I’m zmüed!

1 Like

Thank you for the solution Infinisil!

1 Like