Wrapping a program & symlinking at same time

I am going through the motions trying to setup a minimal home-manager replacement after having read Wrappers vs. Dotfiles - NixOS Wiki

My goal is simple:
Can I replace all my home utilities with wrapped versions that directly reference their required config?

I now need a quick way to wrap common utilities while still symlinking all the outputs in their derivation.
Nix Cookbook - NixOS Wiki has a good overview of different possible solutions, however I found it to be tedious writing each one.

Here is a small helper function I have been using which has been doing the job:

  writeShellScriptBinAndSymlink = name: text: super.symlinkJoin {
    name = name;
    paths = [
      super."${name}"
      (super.writeShellScriptBin name text)
    ];
  };

I then use it in my overlay.nix file like so:

self: super: {

  writeShellScriptBinAndSymlink = name: text: super.symlinkJoin {
    name = name;
    paths = [
      super."${name}"
      (super.writeShellScriptBin name text)
    ];
  };

  man = self.writeShellScriptBinAndSymlink "man" ''
    export LOCALE_ARCHIVE=${super.glibcLocales}/lib/locale/locale-archive
    ${super.man}/bin/man --manpath=$HOME/.nix-profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man "$@"
  '';
}
1 Like

Thanks for exploring this! It would be very cool if we had a standard way to specify wrapper-based configuration in nixpkgs at some point. It could possibly reduce some of the overlap between nixos and home-manager.