Emacs, exwm, home-manager and loading new [emacs] modules

I run Emacs at X startup with exwm, and manage my Emacs configuration/installation with home-manager.

I’m using emacsWithPackages to install additional Emacs modules, and generally this works well with one exception:
When I want to add a new module to Emacs, I add it to the emacsWithPackages list, and run home-manager switch. This sets up new emacs invocations with a load-path to find the new module, but my currently running Emacs is unaware of the new path. I’d rather not restart my whole desktop environment just to load one module.

What I currently do is identify the new ...emacs-packages-deps/ path in the nix store, find the path to the new module, and explicitly (require 'module $path). This works but is a bit tedious.

I’ve tried adding the new emacs-packages-deps path to the load-path variable in Emacs, but it seems the startup process recurses each load-path and adds subdirectories for all entries to the load-path variable. And I’m struggling to find a way to reproduce this component of the startup process.

Ideally I would be able to run home-manager switch, followed by some emacsclient command to update the load-path with all subdirs from the newly generated emacs-package-deps derivation.

Has anyone here had a similar desire and solution? If not I’ll try and hack something together that works for me.

Cheers!

I’m not aware of any solution to this problem.

I was able to get this working with the following home-manager configuration:

{ pkgs, home, config, ... }:
let
  cfg = config.programs.emacs;
in
{
...
  home.file.".emacs.d/load-path.el".source = pkgs.writeText "load-path.el" ''
    (let ((default-directory (file-name-as-directory
                         "${cfg.finalPackage.deps}/share/emacs/site-lisp/"))
          (normal-top-level-add-subdirs-inode-list nil))
    (normal-top-level-add-subdirs-to-load-path))
  '';
...
}

This lets me update my Emacs load-path with M-x load-file ~/.emacs.d/load-path.el after a home-manager switch, no Emacs restarts required :slight_smile: