Wrapping packages

I’m trying to wrap a number of packages up with Emacs to get an environment that contains all package executables as well as other things like man and info pages. I’ve gotten this working with executables, but can’t figure out how to get the share directory outputs as well (and potentially any other outputs I’d get from installing packages in the global environment). Here’s what I’ve got so far.

{ stdenv, pkgs }:

let
  # TODO how can I include man and info pages?
  # searchPath = stdenv.lib.makeSearchPath "share" (with pkgs; [
  #   # documentation
  #   clang-manpages
  #   llvm-manpages
  #   stdman # cppreference manpages
  #   stdmanpages
  #   posix_man_pages
  #   glibcInfo
  # ]);

  # perl-with-packages = pkgs.perl.withPackages(p: with p; [
  #   RPCEPCService
  #   DBI
  #   DBDPg
  # ]);

  binPath = stdenv.lib.makeBinPath (with pkgs; [
    gdb
    clang-tools
    clang-analyzer
    bear
    [...]

    # TODO doesn't work
    # needed for edbi
    # perl-with-packages

    # this doesn't either
    # perlPackages.RPCEPCService
    # perlPackages.DBI
    # perlPackages.DBDPg
  ]);

  emacs-wrapped-with-packages = (pkgs.emacsPackagesGen pkgs.emacs).emacsWithPackages (epkgs: (with epkgs.elpaPackages; [
      # all standard and works fine
      [...]
    ]) ++ (with epkgs.melpaPackages; [
      [...]
    ]) ++ (with epkgs.orgPackages; [
      [...]
    ]) ++ (with epkgs; [
      [...]
    ]));
in
pkgs.symlinkJoin {
  name = "emacs-wrapped";
  paths = with pkgs; [
    emacs-wrapped-with-packages
  ];
  buildInputs = [ pkgs.makeWrapper ];
  postBuild = ''
    wrapProgram "$out""/bin/emacs" \
      --suffix PATH : "${binPath}"
  '';
  inherit (pkgs.emacs) meta;
}

The makeSearchPath at the top was an attempt at the share directory, but couldn’t get it to work. Anyone know of a way to do this?

1 Like

Just ran into this exact same question, just that I wanted to bundle some fonts with a package without installing them system-wide. Did you ever find an answer, or maybe someone else knows?

Most programs support loading data (equivalent to /share directory) from XDG_DATA_DIRS environment variable. But not sure if more traditional programs like man or info support that.

Fonts require fontconfig to know about them so it is not as simple as passing paths to environment variable – you need to create a config file for that. Fortunately, nixpkgs has makeFontsConf function for that (example). Though, that is primarily aimed at testing environments and will probably make system fonts unavailable unless you include them as well. You might want to experiment with creating configuration directories and using other environment variables, see the Environment and Files sections of fonts.conf(5).

2 Likes