Declarative way of nix-channel --add

Hi,

I would like to declare the channel for ‘home-manager’ in my /etc/nixos/configuration.nix, so how can I add channels in a declarative way?

4 Likes

Hi! I know it’s old thread but I was trying same thing and I want to share for someone that googled how to do.
I did this

    home-manager =
        let
            channel = builtins.fetchTarball {
                url = "https://github.com/rycee/home-manager/archive/release-20.03.tar.gz";
                sha256 = "0hgn85yl7gixw1adjfa9nx8axmlpw5y1883lzg3zigknx6ff5hsr";
            };
        in import channel { };

in my configuration.nix to try to install home-manager but gives me this error when I run sudo nixos-rebuild switch
This derivation is not buildable, instead run it using nix-shell.
Maybe I will give up now and try to find a way to automate nix-channel add.

2 Likes

the home-manager channel is largely there for the modules and the nix-env <home-manager> -iA install command.

I think Home Manager - NixOS Wiki is what you’re looking for, the relevant part being:

let
  home-manager = builtins.fetchTarball {
    ....
  };
in
{
    imports = [
      (import "${home-manager}/nixos")
    ];

    home-manager.users.my_username = { ... }
}
5 Likes

Now works. thanks!
I imported home-manager module with

(import "${builtins.fetchTarball https://github.com/rycee/home-manager/archive/release-20.03.tar.gz}/nixos")

and imported my home-manager file with

home-manager.users.btw = import ./nixpkgs/home.nix;

and now works without channel or anything. great!

3 Likes