Declaratively import nixos module from different channel

Hi,
I am trying to import a single module from nixos-unstable channel to my system configuration (currently on 20.09).

The following sequence works flawlessly:

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

then

{ config, pkgs, ... }:

imports = [ 
    <nixos-unstable/nixos/modules/services/cluster/kubernetes/pki.nix>
  ];

disabledModules = [ ''services/cluster/kubernetes/pki.nix'' ];

and finally doing nixos-rebuild.

However, I would like to set the unstable channel declaratively:

{ config, pkgs, ... }:

let
  unstable = import (
    fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz
    ){ config = { allowUnfree = true; }; };
in
{
  imports = [ 
    # TODO: How to import it declaratively (?)
    # <nixos-unstable/nixos/modules/services/cluster/kubernetes/pki.nix>
    # This won't work
    unstable.nixos.modules.services.cluster.kubernetes.pki
  ];

  disabledModules = [ ''services/cluster/kubernetes/pki.nix'' ];

Unfortunately, I am unable to figure out how to import the module from the variable - any help would be very appreciated!

Don’t import it, use the path fetchTarball gives you:

let
  unstable = fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz";
  #unstablePkgs = import unstable { config.allowUnfree = true; }; # if you do need pkgs
in
{
  imports = [ "${unstable}/nixos/modules/services/cluster/kubernetes/pki.nix" ];
  disabledModules = [ "services/cluster/kubernetes/pki.nix" ];
}
3 Likes

Embarrassingly simple, thanks!