Module: make overlay-changed pkgs available to home-manager

I want to install a package from pkgs defined in a overlay and propagate the change in pkgs to a home-manager.services call.

Here’s what I have. A module installing emacsGit from a overlay and then using home-manager to install a emacs.service file. But home-manager uses the original pkgs.emacs package, not the “alias”/overlay emacs = emacsGit.

{ config, pkgs, inputs, ... }:
let cfg = config.modules.emacs;
in options.modules.emacs = {
    enable = mkBoolOpt false;
  };
  config = mkIf cfg.enable {
    nixpkgs.overlays = [
      inputs.emacs-overlay.overlay
      (final: previous: {
        emacs = pkgs.emacsGit;
      })
    ];
     user.packages = with pkgs; [
      emacs;
    ];
    home-manager.users.${config.user.name}.services.emacs.enable = true;
}

The home-manager service is using the pkgs.emacs=nixpkgs.emacs not the pkgs.emacs=emacsGit.

emacs --version
  GNU Emacs 30.0.50
systemctl --user cat emacs.service | grep ExecStart
  ExecStart=/nix/store/k32c6vzr9g1nln6v0gypz6ar6lqjb63l-bash-5.2-p15/bin/bash -l -c "/nix/store/0m2axb8lbpj9sqfiy4ys6pgyxmafb64b-emacs-28.2/bin/emacs --fg-daemon "

How do I define pkgs.emacs in such a way that the change is propagated to home-manager?[1]

[1]
I am aware I can do something like this, but I ask out of curiosity so I can learn a bit more.

{ config, lib, pkgs, inputs, ... }:
let
   emacs = pkgs.emacsGit
in {
    user.packages =  [ emacs ];
    services.emacs.package = emacs;
    services.emacs.enable = true;
}
1 Like

Do you use home-manager.useGlobalPkgs?

Without that the overlay is “local” to the system configuration and you have to configure it for each user again.

If though you use the global packages option mentioned above, you will see all systems overlays applied to the individual users as well, though they won’t be able to add their own then.

Do you use home-manager.useGlobalPkgs ?

No. I was not aware that home-manager uses a private pkgs instance. Thanks!

Would it be possible to get home-manager to inherit the system pkgs in just this instance, ie. something like import <home-manager> { inherit pkgs ;}; somewhere in the module?