Home-Manager flake does not provide attribute

I am trying to rebuild/(install?) home-manager in macOS but am encoutering the error in the subject of this post (detailed below).

How I broke home-manager: I changed my home-manager flake.nix by moving the home-manager config from home.nix into the flake within modules (you can see the commented out reference to home.nix in my flake below), which built via:

home-manager switch --flake .

without any visible errors, but now I can nolonger use home-manager from the cli - the command is no longer found by zsh.

Before building, I removed home.nix and flake.nix from git and added the updated flake.nix,

Now, rightly or wrongly(?), I am trying to rebuild/install(?) home-manager via:

nix build .#homeManagerConfigurations.me.activationPackage

with the error output:

warning: Git tree '/Users/me/.config/nixpkgs' is dirty
error: flake 'git+file:///Users/me/.config/nixpkgs' does not provide attribute 'packages.x86_64-darwin.homeManagerConfigurations.me.activationPackage', 'legacyPackages.x86_64-darwin.homeManagerConfigurations.me.activationPackage' or 'homeManagerConfigurations.me.activationPackage'

OS: macOS, 10.15.7 (Catalina)
Nix: 2.12.0
Home-Manager: 22.11

Directories & Files:

/nix:
store/
var/

~/.config/nix/nix.conf:

build-users-group = nixbld

extra-experimental-features = nix-command flakes

~/.config/nixpkgs/flake.nix

{
  description = "Home Manager configuration of me";

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

  outputs = { nixpkgs, home-manager, ... }:
    let
      username = "me";
      system = "x86_64-darwin";
    in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        defaultPackage.${system} = home-manager.defaultPackage.${system};
        modules = [
          {
            home = {
            inherit username;
            homeDirectory = "/Users/${username}";
            stateVersion = "22.11";
            programs.home-manager.enable = true;
            };
          }
#           ./home.nix
        ];

        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
      };
    };
}

Just like nix is telling you, the output you’re specifying does not exist.

homeConfigurations is the default place the home-manager cli tool looks, so that’s right. Try nix building that.

Thank you for your help, but being a nix newb I am struggling to understand your solution (as obvious as it may be to most people).

Can you please provide the exact nix build(?) command for me?

Hopefully then I will understand your explananation I am replying to.

Many thanks!

nix build .#homeConfigurations.me.activationPackage

Thanks(!), that built - but only after I removed:

programs.home-manager.enable = true;

I can still nolonger use home-manager from the cli, which I guess is because I have removed the above line?

I am trying to move it around within the homeConfigurations and modules blocks but so far am getting the following error when building with it in any of those blocks:

called with unexpected argument 'programs'.

This suggests you probably put it outside the modules section.

Your indentation threw me the first time I looked at this, but this is wrong. You’re setting home.programs.home-manager.enable, which is a non-existent option. You need to move that setting outside the home = { block.

Thanks!

I have again learned from you, but after moving programs.home-manager.enable = true; outside the home = { block, and the flake being built, I am still having no joy getting home-manager to run as a command from zsh (after originally having it working as described above).

Here is where I put programs.home-manager.enable = true; - the only place where nix would allow the flake to be built:

in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        modules = [
          {
            home = {
            inherit username;
            homeDirectory = "/Users/${username}";
            stateVersion = "22.11";
            };
          }
#           ./home.nix
        ];
        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
      };
        programs.home-manager.enable = true;
    };

Side question: If this is the correct place (I’m guessing not because home-manager command is still not available in the cli) - is this where I would add the following if not putting them in separate modules (like home.nix, emacs.nix, etc)?

programs = {
    fzf.enable = true;
    jq.enable = true;
    bat.enable = true;
    htop.enable = true;
    exa.enable = true;

    direnv = {
      enable = true;
      nix-direnv = {
        enable = true;
        enableFlakes = true;
      };
    };

No, not there.

in {
      homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        modules = [
          {
            home = {
              inherit username;
              homeDirectory = "/Users/${username}";
              stateVersion = "22.11";
            };
            programs.home-manager.enable = true;
          }
#           ./home.nix
        ];
        # Optionally use extraSpecialArgs
        # to pass through arguments to home.nix
      };
    };

There. (I also fixed your indentation.)

Thank you!

That builds, but I am still not able to use the home-manager command from the cli, which (obviously) means I cannot use home-manager switch to rebuild the flake after modifying it eg adding a module/program.

Any thoughts on how to debug this and what could be wrong with my setup eg a path issue?

All I can find (so far) to debug is:

nix flake show

that returns:

warning: Git tree '/Users/me/.config/nixpkgs' is dirty
git+file:///Users/me/.config/nixpkgs
└───homeConfigurations: unknown

and unknown appears to be normal (not an error) due to the experimental status of flakes.

Does the activation succeed as well?

After the build, you need to run the activation script in result…

Thanks, I did not know of that step!

Here’s the results directory:

% cd result
% ls -la

total 32
dr-xr-xr-x     9 root  wheel      288  1 Jan  1970 .
drwxrwxr-t  6784 root  nixbld  217088 25 Jan 16:53 ..
lrwxr-xr-x     1 root  wheel       63  1 Jan  1970 LaunchAgents -> /nix/store/chvw8531wrfmzgn8xgdrjx84zv40m3lh-home-manager-agents
-r-xr-xr-x     1 root  wheel    10899  1 Jan  1970 activate
dr-xr-xr-x     3 root  wheel       96  1 Jan  1970 bin


-r--r--r--     1 root  wheel        6  1 Jan  1970 hm-version
lrwxr-xr-x     1 root  wheel       62  1 Jan  1970 home-files -> /nix/store/gwfil846mwbmxbrbs4nxhbc1pg70b6vl-home-manager-files
lrwxr-xr-x     1 root  wheel       61  1 Jan  1970 home-path -> /nix/store/fwjnv42hg6kxall2h86m4zkdg88cci0s-home-manager-path
dr-xr-xr-x     3 root  wheel       96  1 Jan  1970 lib

I see activate uses a hash bang to bash inside nix store. Do I use nix activate or nix bash activate?

Just run result/activate. I don’t believe it takes any arguments, and there’s no need to involve nix in this part.

1 Like

That worked!

Many many many thanks!!!