Home Manager `home.activation` access to packages in `home.packages`

I’m working on a module for installing emacs + doom emacs. I am trying to use home.activation to clone the doom emacs repository into $XDG_CONFIG_HOME/emacs then just do the doom install manually, but I’m having trouble in the activation script accessing packages from home.packages.

I’ve figured out I can do the following to get it to find the path to git:

    home.activation.install-doom = hm.dag.entryAfter [ "writeBoundary" ] ''
      if ! [ -d "${config.xdg.configHome}/emacs" ]; then
        $DRY_RUN_CMD ${
          getExe pkgs.git
        } clone $VERBOSE_ARG --depth=1 --single-branch "https://github.com/doomemacs/doomemacs.git" "${config.xdg.configHome}/emacs"
      fi
    '';

However, I have the following in my git config:

[url "ssh://git@github.com/"]
    insteadOf = "https://github.com/"

Which causes the activation to fail because it then cannot find ssh:

Activating install-doom
Cloning into '/home/fortruce/.config/emacs'...
error: cannot run ssh: No such file or directory
fatal: unable to fork

Is it possible to run home.activation scripts such that they have access to all the packages of the config? Maybe there is a simple way to setup the PATH in the script itself to fix this that I’m missing.


EDIT: Tried adding to path temporarily in the script which gets me there as long as I have an active ssh-agent around with my key. Looks really hacky though, but maybe this is the solution?

PATH="${pkgs.git}/bin:${pkgs.openssh}/bin:$PATH" $DRY_RUN_CMD git clone $VERBOSE_ARG --depth=1 --single-branch "https://github.com/doomemacs/doomemacs.git" "${config.xdg.configHome}/emacs"

Two alternatives that you could try:

  1. Change hm.dag.entryAfter [ "writeBoundary" ] to hm.dag.entryAfter [ "installPackages" ] and simply run $DRY_RUN_CMD git … since Git should be available in the user’s PATH.

  2. Use PATH="${config.home.path}/bin:$PATH" $DRY_RUN_CMD git …. The home.path option is considered internal but should be reasonably stable for use.

2 Likes

Thanks, the installPackages route was what I was looking for. I also found a trick to avoid using ssh for certain repos I know to be public while keeping the url rewrite. I added another rewrite rule to my git config:

[url "https://github.com/"]
    insteadOf = "gh:"

Then I just change my clone in the home.activation to gh:doomemacs/doomemacs so it doesn’t try cloning via ssh and leading to having to have ssh and keys in an ssh-agent available.

Hey, and sorry to necropost this, but @rycee using point 1 doesn’t actually work. I used post-installPackages hook but still had to do point two’s PATH appending trick for the executable to be found (go in my case).

1 Like