Using home-manager-generated packages as dependencies

Hello all,

Let’s say I want to create a very simple derivation, which has, as a dependency, a program that I’m using home-manager to configure:

let
  pkgs = import <nixpkgs> {};
  wrapper = { stdenv, writeShellScriptBin, bash, kakoune }:
    writeShellScriptBin "wrapkak"
    ''
      #! ${bash}/bin/bash
      echo "stay calm this is a wrapper"
      exec ${kakoune}/bin/kak $@
    '';
in
  with pkgs; callPackage wrapper {}

In this case, the home-manager-configured program is kakoune. Unfortunately, when I build this thing, I discover that it’s using (quite understandably, since I’ve not told it not to) kakoune straight from nixpkgs, rather than from home-manager:

$ cat ~/.nix-profile/bin/wrapkak
#!/nix/store/wadmyilr414n7bimxysbny876i2vlm5r-bash-5.1-p8/bin/bash
#! /nix/store/wadmyilr414n7bimxysbny876i2vlm5r-bash-5.1-p8/bin/bash
echo "stay calm this is a wrapper"
exec /nix/store/5w0bb165sxp0k7ddbalh4ibz0xpirp3s-kakoune-2021.10.28/bin/kak $@

versus the home-manager-generated one:

$ ls -l $(which kak)
lrwxrwxrwx 1 root root 69 Jan  1  1970 /home/chris/.nix-profile/bin/kak -> /nix/store/s0crf1jwrv4ll5l78kxscq3lg7kyz38w-home-manager-path/bin/kak

I presume I need to make my derivation into an overlay and import it into home.nix somehow, but I’m not quite clear how. There is eg this Example how to use newer version of a package configured by home-manager · Issue #1107 · nix-community/home-manager · GitHub, but it’s describing how to use an overlay to change inputs into home-manager, not how to apply an overlay to home-manager’s outputs.

Any help gratefully received.

1 Like

In this case you can’t, the kakoune module does not expose the configured package in any way.

You best bet is to rely on the PATH in the wrapper.

Alternatively ask upstream for a read-only option, similar to how it’s done with Emacs:

programs.emacs.finalPackage

1 Like

Thanks for this response. I can roughly guess what you mean by the expression, but when you say ‘expose the configured package’, I can’t really imagine what that would look like. I think I will read the home-manager source code a little and see if I can figure out what it’s doing behind the scenes.

Basically it would have to look exactly as the linked Emacs module

Hello - I am now getting round to this and think I have set up kakoune.nix in home-manager correctly, with a programs.kakoune.finalPackage attribute (I am testing locally). Having done that, how would I go about referring to that finalPackage-d version of kakoune in a derivation, rather than the upstream nixpkgs.kakoune? Is there a special way to import a derivation input from home-manager rather than nixpkgs? Or should I add an overlay to nixpkgs in my home-manager configuration files?

If you build the derivation as part of your configuration in a module then use config.programs.kakoune.finalPackage.

If you build it somewhere else, there is no way to make it aware of your configuration.