Help Installing Home-Manager (NixOS Module)

After finishing the installation process (and used sudo nixos-rebuild switch (which built successfully)) according to NixOS module, I went to use nano ~/.config/home-manager/home.nix (according to Using Home Manager) and it wasn’t a pre-existing file.

I have provided the Home-Manager section of configuration.nix in the screenshot provided.

Assistance would be greatly appreciated <3

Yeah, the home-manager docs are structured in the most confusing way possible.

~/.config/home-manager/home.nix is the file used for standalone home-manager configurations. If you use home-manager on NixOS you should never create it.

Instead, the home-manager module entrypoint goes directly into the home-manager.users.<username> option. It however contains the exact same contents as the home.nix file would with a standalone setup.

The docs never really explain the difference between a home-manager or NixOS setup, and interleave the setup for the two different systems, and then only have a section explaining how to use the standalone configuration, never properly distinguishing the two. It’s not surprising that you would be confused.

If you want to, you can change your configuration to:

# /etc/nixos/configuration.nix
{ config, pkgs, lib, osConfig ...}: {
  # <snip>

  home-manager.users.parkerh = import ./home.nix;

  # <snap>
}
# /etc/nixos/home.nix
{ pkgs, ... }: {
  home.packages = [ pkgs.atool pkgs.httpie ];
  programs.bash.enable = true;
  home.stateVersion = "25.05";
}

That way you still have a file called home.nix, which might be a bit less confusing than an inline module.

Also, while we’re at it, don’t use builtins.fetchTarball without a hash. This breaks reproducibility and makes it so nix will just magically download a new home-manager every two hours, and spend the time doing that too, which slows everything down.

Anyone recommending new users use builtins.fetchTarball that way should be publicly shamed; Personally I would recommend either using channels (despite their flaws, all the docs are written for flakes…) or npins. Those two options lack this footgun entirely, though channels have a few other footguns.

Sigh, of course you’ve stumbled into two incredibly well-known footguns right off the bat. Why do we keep footguns lying around like this? I’m so sorry.

2 Likes

I would like to add that I prefer standalone home-manager over home-manager as a NixOS module as to me home-manager and NixOS are two completely separate things. One is to manage the device and OS, the other is to manage everything else.

nix run home-manager/master -- init
home-manager switch

Sure, and that’s why there are options. My opinion is the exact opposite of yours, though I understand what your reasoning likely is.

This is however unrelated to the question of how you make the module work, and I think half the problem is precisely that we keep confusing newcomers by just interleaving instructions for both, so if you want to discuss the merits of standalone vs NixOS module it’d be nice to do that in a separate thread. Hell, maybe the outcome could make it into a home-manager docs rework.

“Also, while we’re at it, don’t use builtins.fetchTarball without a hash.”

Is this the correct syntax?

let
  home-manager = # builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz;

Right, there’s an easy answer and a more nuanced answer. I don’t like hiding details, so I’ll try to give you as much nuance as I think is necessary.

What you’re asking for isn’t just a matter of syntax, but “how do I import a third party project into NixOS”. There are at least three (mostly) appropriate approaches to this, as well as many ways to do it that will lead to issues, or homebrew solutions you could invent.

The ones I’d suggest as reasonable off the top of my head are:

  • nix channels
  • nix flakes
  • npins

What your code is currently doing is one of the ways to do it that will lead to issues. I’ll keep to practical solutions for now, but if you have the time, you can see my full, unfiltered opinion here. I’ll recommend using channels for now.

Using channels means you can just follow the home-manager docs, which is pretty nice.

Repeating what those docs say, but tailored to your current configuration and question, the syntax you’re looking for is:

# /etc/nixos/configuration.nix
{
  config,
  pkgs,
  lib,
  # I think you have to remove `osConfig`, it should only work in home.nix
  ...
}: {
  imports = [ <home-manager/nixos> ];

  home-manager.users.parkerh = import ./home.nix;

  # <snip>
}

This is similar to your variant, except that:

  • We removed the redundant call to import (the imports NixOS module feature does that for us)
  • We’ve replaced the variable substitution with a lookup on the NIX_PATH

This uses the angle bracket (<>) syntax to look up files in the NIX_PATH variable. By default the NIX_PATH includes the /nix/var/nix/profiles/per-user/root/channels file, which causes nix to look up files according to your root user’s channel configuration.

Of course, by default <home-manager> is not in your channel configuration; the default config only contains the <nixos> channel. See the home-manager documentation I linked earlier for how to add a home-manager channel.

1 Like