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;
}
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.
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:
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.
(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:
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.
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.