This repository has no description
1.4 kB
54 lines
1{ lib, superlib, pkgs, ... }:
2{
3 /**
4 Create a wrapped application that preserves all original outputs (man pages, completions, etc.)
5
6 # Arguments
7
8 - `package`: The package to wrap
9 - `runtimeInputs`: List of packages to add to PATH (optional)
10 - `env`: Attribute set of environment variables to export (optional)
11 - `wrapper`: Custom wrapper script (optional, defaults to exec'ing the original binary)
12
13 # Example
14
15 ```nix
16 makeWrapper pkgs.curl {
17 runtimeInputs = [ pkgs.jq ];
18 env = {
19 CURL_CA_BUNDLE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
20 };
21 wrapper = ''
22 echo "Making request..." >&2
23 exec ${lib.getExe pkgs.curl} "$@"
24 '';
25 }
26 ```
27 */
28 makeWrapper = package: args@{
29 runtimeInputs ? [],
30 env ? {},
31 wrapper ? ''exec ${lib.getExe package} "$@"''
32 }:
33 let
34 # Extract binary name from the exe path
35 exePath = lib.getExe package;
36 binName = baseNameOf exePath;
37 in
38 pkgs.symlinkJoin {
39 name = package.pname or package.name;
40 paths = [
41 (pkgs.writeShellApplication {
42 name = binName;
43 runtimeInputs = runtimeInputs;
44 text = ''
45 ${lib.concatStringsSep "\n" (
46 lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env
47 )}
48 ${wrapper}
49 '';
50 })
51 package
52 ];
53 };
54}