Skip to content

Commit

Permalink
Add a way to wrap nix derivations with makeWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
voidus committed May 2, 2023
1 parent c917918 commit b34c49a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,47 @@ For Vulkan programs:
```bash
$ nixVulkanNvidia program args
$ nixVulkanIntel program args

## Wrapping applications
If you are using home-manager, you can use this approach to avoid having to add the wrapper call
each time:

```nix
let
nixGLWrap = drv: binary: pkgs.symlinkJoin {
name = "${drv.name}-nixglwrapped";
paths = [ drv ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
# This will break if wrapProgram is ever changed, so fingers crossed
makeShellWrapper() {
local original="$1"
local wrapper="$2"
cat << EOF > "$wrapper"
#! ${pkgs.bash}/bin/bash -e
exec "${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL" "$original"
EOF
chmod +x "$wrapper"
}
wrapProgram "$out/bin/${binary}"
'';
};
in {
home.packages = [
(nixGLWrap "glxinfo" glxinfo)
];
}
```
This generates a wrapper script that automatically adds the `nixGL` call so you won't have to
remember it.
This could be done simpler with
`writeShellScriptBin "glxinfo" "${..}/bin/nixGL ${glxinfo}/bin/glxinfo"`
but this way, only the binary will be available in your environment and you'll [lose manpages and
possibly important supporting files](https://nixos.wiki/wiki/Nix_Cookbook#Wrapping_packages).
# OpenGL - Hybrid Intel + Nvidia laptop
After installing `nixGLIntel` and `nixGLNvidiaBumblebee`.
Expand Down

0 comments on commit b34c49a

Please sign in to comment.