How to use home-manager with NUR

I’m trying to migrate from nix-env to home-manager in managing user packages. I installed home-manager as a system package in /etc/nixos/configuration.nix. However, vanilla home-manager does not support NUR. That is, I cannot install NUR packages through home-manager. I’ve looked up NUR and home-manager documentations, but they seems only mentioning some services things without packages which I don’t quite understand:

Blockquote Integrating with Home Manager

Blockquote Integrating with Home Manager can be done by adding your modules to the imports attribute. You can then configure your services like usual.

let
  nur-no-pkgs = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {};
in
{
  imports = lib.attrValues nur-no-pkgs.repos.moredhel.hmModules.rawModules;

  services.unison = {
    enable = true;
    profiles = {
      org = {
        src = "/home/moredhel/org";
        dest = "/home/moredhel/org.backup";
        extraArgs = "-batch -watch -ui text -repeat 60 -fat";
      };
    };
  };
}

Now many people in the matrix chat are urging me to switch to home-manager. What should I do? Thanks.

Sorry, had a case of wrong button earlier.

The packages are usually intended to be added as an overlay, which you can do like so:

{pkgs, ...}:
let
  nurpkgs = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {};
in
{
  nixpkgs.overlays = [
    nurpkgs.repos.ben.overlays.bar
  ];

  home.packages = with pkgs.<whatever path the repo overlays>; [
    bens-awesome-package
  ];
}

It depends a bit on the repo you’re getting packages from though. You might not even need the overlay, in fact. Which packages are you getting this way?

Oh, I understood. I thought nurpkgs.repos.ben.overlays.bar was something similar to foo bar and was supposed to be replaced by some actual value. I think the documentation needs some enhancement. I’m getting clash-for-windows in this way.

I’m getting confused. it seems that ben and bar are indeed values to substitute. If I’m using linyinfeng.clash-for-windows, how should I configure the overlay?

Looking at their repository, looks like there is indeed no overlay. I think this is how you would import these packages, not 100% certain, not exactly sure what lib.makeScope does:

{pkgs, ...}:
let
  nurpkgs = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") { inherit pkgs; };
in
{
  home.packages = with nurpkgs.repos.linyinfeng; [
    clash-for-windows
  ];
}
1 Like

Thanks, that’s helpful! I think they should have put this in their documentation.

Probably! Keep in mind these are user repositories, though, and just exist because some person decided to add theirs to the set, in case it’s useful.

They have have even less time than the rest of the NixOS community to maintain or provide high quality documentation, and made no promise to do so at all; consumers shouldn’t expect it.

This discourse is a perfectly fine substitute for when you’re lost trying to understand a NUR repo :wink: