Home-manager 22.11: homeManagerConfiguration pkgs parameter

I’ve been struggling to update my flake.nix for home-manager to use 22.11. It is complaining about not being called with the required argument “pkgs”. I’m trying to update my file based on the README, which starts with:

homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.${system};

but that leaves complains that ‘nixpkgs’ is undefined.

Any advice would be appreciated!

1 Like

Can you please show a more complete snippet of your configuration?

This is my flake.nix. It gets an error at pkgs = nixpkgs... because nixpkgs is undefined.

{
description = “Home Manager configuration of Mike 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 = “mike”;
in {
homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.${system};
configuration = {
imports = [
./home.nix
./dunst.nix
./xscreensaver.nix
];
nixpkgs.overlays = [ blender-bin.overlays.default ];
};

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

}

Then add it to the arguments of your outputs function.

What should that look like? I haven’t been able to get it to work. I’m still learning my way around Nix syntax.

outputs = {home-manager, blender-bin, nixpkgs, ...}:

Now I’m told that ‘homeManagerConfiguration’ is being called with unexpected argument ‘nixpkgs’.

Let me start by formatting the code into something more readable:

{
  description = "Home Manager configuration of Mike 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,
    nixpkgs,
    ...
  }: let
    system = "x86_64-linux";
    username = "mike";
  in {
    homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};
      configuration = {
        imports = [
          ./home.nix
          ./dunst.nix
          ./xscreensaver.nix
        ];
        nixpkgs.overlays = [blender-bin.overlays.default];
      };

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

Unless you changed the wrong thing, I can’t see how the cited error should happen.

Anyway, the way how homeManagerConfiguration is called here, is the old convention. The new way would look like this:

home-manager.lib.homeManagerConfiguration {
  pkgs = nixpkgs.legacyPackages.${system};
  modules = [
    ./home.nix
    ./dunst.nix
    ./xscreensaver.nix
    {
      nixpkgs.overlays = [blender-bin.overlays.default]
      home = {
        inherit system username;
        homeDirectory = "/home/${username}";
      };
      # Update the state version as needed.
      stateVersion = "22.05";
    };
  ];
};

Thanks for all your patient help. Is that the full contents of flake.nix? Where do I specify the repos to use (home-manager.url, nixpkgs.url, etc.)?

Thats only the relevant part, namey the homeManagerConfiguration call. You replace your current call with that snippet, the inputs remain where they are.

Now I have:

{
  description = "Home Manager configuration of Mike 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,
              nixpkgs,
              ... }:
    let
      system = "x86_64-linux";
      username = "mike";
    in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        modules = [
          ./home.nix
          ./dunst.nix
          ./xscreensaver.nix
          {
            nixpkgs.overlays = [blender-bin.overlays.default];
            home = {
              inherit system username;
              homeDirectory = "/home/${username}";
            };
            # Update the state version as needed.
            stateVersion = "22.05";
          }
        ];
      };
    };
}

Which yields:
error: The option `home.system' does not exist. Definition values: - In `<unknown-file>': "x86_64-linux"

Right, an oversight of mine.

system has to be passed at the same level as pkgs and modules are.

For details refer to the changelog of 22.11:

https://nix-community.github.io/home-manager/release-notes.html#sec-release-22.11

I’ve looked at the changelog, but I don’t see where system comes from. In the old version, it is specified explicitly, but the “change it to” version only mentions system when specifying pkgs. If I remove the system=... line, I get an undefined variable error. If I put it right before pkgs=..., I get an error for using an obsolete argument.

I just checked it again, you are right. There is no need to pass it.

HM will “know” the system to use from the pkgs that you passed in.

Finally got it–thanks for all your help. For the record, here’s what I’ve ended up with:

  description = "Home Manager configuration of Mike 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,
              nixpkgs,
              ... }:
    let
      system = "x86_64-linux";
      username = "mike";
    in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        modules = [
          ./home.nix
          ./dunst.nix
          ./xscreensaver.nix
          {
            nixpkgs.overlays = [blender-bin.overlays.default];
            home = {
              inherit username;
              homeDirectory = "/home/${username}";
              # Update the state version as needed.
              stateVersion = "22.05";
            };
          }
        ];
      };
    };
}```
Final changes were to remove `system` from the `home = {...}` block, and move `stateVersion=...` into it.
1 Like