Home-manager: get path to home-manager package

I’m trying to set up a home-manager hook which automatically writes the path of the home-manager package to a file in my home-directory. The purpose is to be able to more easily recover when I screw up my environment in such a way as to leave me without home-manager in my $PATH (as occasionally happens).

I have the following in my config:

    programs.home-manager.enable = true;
    home.activation.recordNixAndHMPaths = lib.hm.dag.entryAfter ["writeBoundary"] ''
      $DRY_RUN_CMD echo ${config.nix.package} > ${config.home.homeDirectory}/tmp/latest-nix
      $DRY_RUN_CMD echo ${pkgs.home-manager} > ${config.home.homeDirectory}/tmp/latest-home-manager

The one for the nix package is working correctly. However, it seems like pkgs.home-manager is not the same one in my user environment.

I’m using a flake for my config, so I assume programs.home-manager.enable is putting the version of home-manager from my flake inputs in my user environment. But how do I actually access this package to obtain its store path?

1 Like