2 channels in 1 system, is it possible?

hi guys…
i want to use stable channel for my base system and i would like it to stay stable and only update for next release stable channel…but i also want to use latest app for my work…can i setup different channel inside 1 machine…1 stable channel for base system…1 unstable channel for working…if it posssible please show me how to make it?? thanks… :slightly_smiling_face:

Yes you can.

There are multiple ways to do it. As you talk about channels, I won’t introduce flakes but it is one solution exactly for it.

Using channels, you can register different name:

nix-channel --add unstable https://nixos.org/channels/nixpkgs-unstable

This way, you keep nixpkgs to, for example nixos-20.09 and you get a second one for unstable packages.

You can refer to them using <nixpkgs> and <unstable> in your nix files:

let
  stable = import <nixpkgs> {};
  unstable = import <unstable> {};
in
mkShell {
  name = "amazing-shell";
  buildInputs = [ stable.gcc unstable.vscode ];
}

If you mix a lot of programs and often, you can use an overlay.

Place the following file in .config/nixpkgs/overlay.nix:

final: prev:

let
  unstable = import <unstable> {};
in
{
  vscode = unstable.vscode;
}

From now vscode will refer to the unstable one.

(Just using vscode as an example because stable releases usually lag behind programs like this that are frequently updating)

4 Likes