Using an external flake in home-manager

I gave set up home-manager in a “flake” style. I have two files that are located in ~/.config/home-manger:

flake.nix:

{
  description = "Home Manager configuration";

  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      homeConfigurations."username" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;

        # Specify your home configuration modules here, for example,
        # the path to your home.nix.
        modules = [ ./home.nix ];

        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
      };
    };
}

And obviously the home.nix:

{ config, pkgs, ... }@inputs:
let darwin = pkgs.system == "x86_64-darwin";
in
let my_imports = [
    ./nixpkgs.nix
    ./alacritty.nix
    ./zsh.nix
    ./starship.nix
    ./tmux.nix
];
in
let my_packages = with pkgs; [
      # # Adds the 'hello' command to your environment. It prints a friendly
      # # "Hello, world!" when run.

      # c compilers
      gcc

      # applications
      neovim

      # ...
];
in
{
    imports = my_imports;
    # ... more basic configuration.


   programs.home-manager.enable = true;
}

This all works fine for me with the basic nixpkgs. My question, as someone who is new to nix and home-manager, how can I use an external flake (such as GitHub - MarceColl/zen-browser-flake: Nix Flake for the Zen Browser) to download packages from here.

I was able to add this flake as an input to my “home-manager flake” and when I ran home-manager switch I saw that it successfully added it to my flake. Thing is, I can’t for the life of me find how to actually use it and install the package it comes with.

Looking for some guidance from a more experienced nix user.

If I’m understanding you correctly, you would:

  1. To flake.nix, add:
inputs = {
  zen-browser.url = "github:MarceColl/zen-browser-flake";
  ...
};
  outputs = { nixpkgs, home-manager, zen-browser, ... }:
  1. To home.nix:
{ config, pkgs, inputs, ... }@inputs:
let my_imports = [
    ./nixpkgs.nix
    ./alacritty.nix
    ./zsh.nix
    ./starship.nix
    ./tmux.nix
    inputs.zen-browser.packages."${system}".default
];
let my_packages = with pkgs; [
    zen-browser
...
];

Your config is a little weird to me so I might be a bit off here, but I think it’ll work.

That probably won’t work since inputs.zen-browser.packages."${system}".default is a package, not a module.

After adding the zen-browser to the flake’s inputs, you could reference the provided package in one of three ways:

  1. Inline the zen-browser input reference in flake.nix:
# flake.nix
# ...
      homeConfigurations."username" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;

        # Specify your home configuration modules here, for example,
        # the path to your home.nix.
-       modules = [ ./home.nix ];
+       modules = [
+          ./home.nix
+          { home.packages = [ zen-browser.packages."${system}".default ]; }
+       ];

        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
      };

This approach is quick and allows using the input reference in the flake.nix file only. It works by creating an inline module.

  1. (alternative approach) Use specialArgs to pass the reference to zen-browser input
# flake.nix
# ...
      homeConfigurations."username" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;

        # Specify your home configuration modules here, for example,
        # the path to your home.nix.
        modules = [ ./home.nix ];

        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
        extraSpecialArgs = { inherit zen-browser; };
      };

extraSpecialArgs passes “zen-browser” as a reference to the input to all modules imported by home manager. So now you could do:

# home.nix
-{ config, pkgs,  ... }@inputs:
+{ config, pkgs, zen-browser, ... }@inputs:
# ...
let my_packages = with pkgs; [
...
- ];
+ ]  ++ [ zen-browser.packages.packages.${pkgs.system}.default ];

This approach passes a reference to the zen-browser around and makes it available to all modules. It’s useful if you want to reference other outputs of the zen-browser flake (like a module or something) in multiple separate places.

  1. Use an overlay. When creating the home-manager.lib.homeManagerConfiguration you can specify an overlay in the pkgs argument. This will allow you to reference this package as pkgs.zen-browser. Useful when you only care about one or more packages from the flake you are referencing.