How to use Emacs packages installed via Home Manager?

I"ve the following snippet in ~/.config/nixpkgs/home.nix:

programs.emacs = {
  enable = true;
  extraPackages = epkgs: with epkgs; [
    use-package
  ];
};

And this at the beginning of ~/.emacs.d/init.el:

(eval-when-compile
  (require 'use-package))

But when I start Emacs I get the following error message

Warning (initialization): An error occurred while loading ‘/home/user/.emacs.d/init.el’:

File is missing: Cannot open load file, No such file or directory, use-package

I based this snippet on what I found in John Wiegley’s Emacs dotfiles and the documentation for use-package.

What should I do to get Emacs recognize packages installed with Home Manager?

I’m not exactly sure what’s wrong, but here are some suggestions:

  1. Make sure the emacs you are running was installed with home-manager
  2. Try (require 'package)(package-initialize) before requiring use-package.

I’m tempted to just delete this thread…

I forgot to run home-manager switch. Only built the derivation earlier.

4 Likes

(package-initialize) isn’t required because home-manager installs stuff in normal Lisp load path, AFAIK. package installs stuff into ~/.emacs.d/elpa or somewhere similar, and this directory is not on the default load-path.

2 Likes

@a12l Can you share your Emacs configuration and Nix config? I am trying to use Nix to manage Emacs packages, but fails.