Using a flake overlay with home-manager

I am trying to install blender from the blender-bin flake using home-manager, which I have working with my system configuration. My home-manager flake.nix is as follows

{
  description = "Home Manager configuration of Aidan Gauland";

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

  outputs = { home-manager,
              blender-bin,
              ... }:
    let
      system = "x86_64-linux";
      username = "aidan";
    in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        configuration = {
          imports = [ ./home.nix ];
          nixpkgs.overlays = [ blender-bin.overlay ];
        };

        inherit system username;
        homeDirectory = "/home/${username}";
        # Update the state version as needed.
        stateVersion = "22.05";
      };
    };
}

And then I have pkgs.blender_3_1 in the home.packages list in home.nix. Running home-manager switch --flake /path/to/flake#aidan produces the following error:

error: attribute 'overlay' missing

       at /nix/store/ncsf4qggpgahjbkfkm097lhzjxhfn62a-source/flake.nix:21:32:

           20|           imports = [ ./home.nix ];
           21|           nixpkgs.overlays = [ blender-bin.overlay ];
             |                                ^
           22|         };

My working NixOS flake.nix looks like this:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
  };
  outputs = { self,
              nixpkgs,
              blender-bin}: {
    nixosConfigurations.blah = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ config, pkgs, ... }:
          { nixpkgs.overlays = [ blender-bin.overlay ];
            environment.systemPackages = [ pkgs.blender_3_1 ];
          })
        ./configuration.nix
      ];
    };
  };
}

What would be the equivalent to this in home-manager?

1 Like

Try overlays.default, blender-bin changed to the new format 7 days ago: blender: use pname and version + pass nix check · edolstra/nix-warez@0b3312d · GitHub

I’m guessing you’ll need to do the same in your system flake when you update it.

1 Like

I’m going to piggyback on this thread: as of home-manager 22.11 (the current home-manager master branch) the arguments to homeManagerConfiguration have changed (see the release notes). We can no longer pass overlays via configuration.nixpkgs.overlays since configuration is no longer an argument. Instead we pass pkgs as an argument to homeManagerConfiguration.

Presumably we need apply the overlay ourselves to nixpkgs before passing pkgs.legacyPackages.${system}. Does anyone have an example of how to do this correctly?

configuration should be added to a list of modules instead now. I.e. your new config should look something like:

homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
  pkgs = nixpkgs.legacyPakcages.${system};
  modules = [
    ./home.nix
    ({
      nixpkgs.overlays = [ blender-bin.overlays.default ];
      home = {
        inherit username;
        homeDirectory = "/home/${username}";
        # Don't update this unless you know what you're doing
        stateVersion = "22.05";
      };
    })
  ];
};

The overlays config still exists: https://nix-community.github.io/home-manager/options.html#opt-nixpkgs.overlays

So, no need to pre-apply your overlays and pass a custom pkgs. You can still do so if you like, but it’s a bit slower to evaluate and doesn’t actually change anything.

Do please open a new thread next time. The title/date doesn’t really match this particular predicament, and it looks like we’ll have a lot of people searching 6 months from now.

2 Likes

Fantastic, thank you.

Do please open a new thread next time. The title/date doesn’t really match this particular predicament, and it looks like we’ll have a lot of people searching 6 months from now.

My mistake, noted. On the other hand, something that often confuses me is searching for a solution and finding out of date information, so it may be useful to have both the older and newer solutions standing in contrast in one place.

I think it’s more helpful to link the old post in such situations :slight_smile:

3 Likes