This repository has no description
1.4 kB
56 lines
1{ lib, 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 =
29 package:
30 {
31 runtimeInputs ? [ ],
32 env ? { },
33 wrapper ? ''exec ${lib.getExe package} "$@"'',
34 }:
35 let
36 # Extract binary name from the exe path
37 exePath = lib.getExe package;
38 binName = baseNameOf exePath;
39 in
40 pkgs.symlinkJoin {
41 name = package.pname or package.name;
42 paths = [
43 (pkgs.writeShellApplication {
44 name = binName;
45 runtimeInputs = runtimeInputs;
46 text = ''
47 ${lib.concatStringsSep "\n" (
48 lib.mapAttrsToList (name: value: ''export ${name}="${toString value}"'') env
49 )}
50 ${wrapper}
51 '';
52 })
53 package
54 ];
55 };
56}