Home Manager: Difference between revisions

From NixOS Wiki
imported>HoldenLucas
previous link to srid's config was broken
imported>Samuela
Line 71: Line 71:
</syntaxHighlight>
</syntaxHighlight>
to your system configuration. ( [https://old.reddit.com/r/NixOS/comments/b255k5/home_manager_cannot_set_gnome_themes/ Source] )
to your system configuration. ( [https://old.reddit.com/r/NixOS/comments/b255k5/home_manager_cannot_set_gnome_themes/ Source] )
=== installed apps don’t show up in Ubuntu's/GNOME's "Show Applications" ===
Consider some of the workarounds here: https://github.com/nix-community/home-manager/issues/1439.
== Alternatives ==
== Alternatives ==
* [[Wrappers vs. Dotfiles]] shows how (per-user) wrapper scripts can be used in place of dotfiles in the user's home directory
* [[Wrappers vs. Dotfiles]] shows how (per-user) wrapper scripts can be used in place of dotfiles in the user's home directory

Revision as of 04:20, 25 February 2021

Home Manager is a basic system for managing a user environment using the Nix package manager together with the Nix libraries found in Nixpkgs. Before attempting to use Home Manager please read the warning.

Configuration

Home Manager can be configured in ~/.config/nixpkgs/home.nix or inside configuration.nix.

For the latter, add the following to your config. Note: fetchTarball does not check the integrity of the downloaded package.

  imports = [
    ...
    (import "${builtins.fetchTarball https://github.com/rycee/home-manager/archive/master.tar.gz}/nixos")
  ];
  home-manager.users.my_username = { ... }

For a more secure version:

let
  home-manager = builtins.fetchGit {
    url = "https://github.com/rycee/home-manager.git";
    rev = "dd94a849df69fe62fe2cb23a74c2b9330f1189ed"; # CHANGEME 
    ref = "release-18.09";
  };
in
{
    imports = [
      (import "${home-manager}/nixos")
    ];

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


Builtins.fetch* are built-in functions, in our example, we are fetching either a github repository (fetchGit), or a tarball (fetchTarball). With fetchGit, we are fetching a specific commit of home-manager (the rev attribute). To get that, we can use nix-prefetch-github, which will return a hash (sha256), an owner, a repository, and a commit (rev attribute, that's what we want here). Here, we are pinning 18.09's release, but you may want to change that to the version of NixOS you're using. Use master if you are on unstable. Finally, in our example, we are fetching home-manager/nixos folder, that allows us to use more options from home-manager, which are options usable by NixOS only.

Managing your dotfiles

Home Manager has options to configure many common tools. As an example, adding the following

  programs.git = {
    enable = true;
    userName  = "my_git_username";
    userEmail = "my_git_username@gmail.com";
  };

will make Home Manager generate a .config/git/config file for you.

Even for programs for which Home Manager doesn't have configuration options, you can use it to manage your dotfiles, e.g.

  xdg.configFile."i3blocks/config".source = "${my-dotfile-dir}/i3blocks.conf"

This will create a symlink $XDG_CONFIG_HOME/i3blocks/config.

You have the whole list of the options available in home-manager here

Examples

FAQ

I cannot set GNOME themes via home-manager

You will have to add

programs.dconf.enable = true;

to your system configuration. ( Source )

installed apps don’t show up in Ubuntu's/GNOME's "Show Applications"

Consider some of the workarounds here: https://github.com/nix-community/home-manager/issues/1439.

Alternatives

  • Wrappers vs. Dotfiles shows how (per-user) wrapper scripts can be used in place of dotfiles in the user's home directory