# Include custom environment variable into wrapper

**URL:** https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229
**Category:** Help
**Created:** [July 20, 2020, 8:12pm UTC](https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229 "2020-07-20T20:12:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![onny](https://discourse.nixos.org/user_avatar/discourse.nixos.org/onny/32/2138_2.png) [@onny](https://discourse.nixos.org/u/onny)
#### Post date: [July 20, 2020, 8:12pm UTC](https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229/1 "2020-07-20T20:12:49Z")

</div>

Hey,  
I already searched a lot but most of the stuff I found looks too complicated. I want to place a custom environment variable into the wrapper of programs like “signal-desktop” and “atom”. For example GDK\_BACKEND=x11. I would like to put this “fix” into my configuration.nix file.  
I guess this is possible by using overlays or derivations, but I’m not sure how to use them ☹

Best regards  
Jonas

---

<div class="post-metadata">

### Author: ![fricklerhandwerk](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fricklerhandwerk/32/2029_2.png) [@fricklerhandwerk](https://discourse.nixos.org/u/fricklerhandwerk)
#### Post date: [July 20, 2020, 10:24pm UTC](https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229/2 "2020-07-20T22:24:47Z")

</div>

The Wiki has [detailed variants of a solution](https://nixos.wiki/wiki/Nix_Cookbook#Wrapping_packages). Building on the answer I [found on StackOverflow](https://stackoverflow.com/questions/39713096/nix-can-an-installed-package-set-a-user-environment-variable/39713383#39713383) I suggest (without testing it or knowing anything about the packages in question):

```nix
{ config, pkgs, ...}:
let
atom-overlay = self: super: {
  # override derivation attributes
  atom = super.atom.overrideAttrs (old: {
    # add `makeWrapper` to existing dependencies
    buildInputs = old.buildInputs ++ [pkgs.makeWrapper];
    # wrap the binary in a script where the appropriate env var is set
    postInstall = old.postInstall or "" + ''
      wrapProgram "$out/bin/atom" --set GDK_BACKEND x11
    '';
  })
};
in
{
  # add the overlay to your nixpkgs in the system configuration
  config.nixpkgs.overlays = [atom-overlay];
}

```

Rebuilding should not be a problem for GUI applications, as I would expect nothing to depend on them.

Just for reference, here is a [previous discussion](https://github.com/NixOS/nixpkgs/issues/60260) of the general problem with wrappers.

---

<div class="post-metadata">

### Author: ![onny](https://discourse.nixos.org/user_avatar/discourse.nixos.org/onny/32/2138_2.png) [@onny](https://discourse.nixos.org/u/onny)
#### Post date: [July 22, 2020, 11:01am UTC](https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229/3 "2020-07-22T11:01:10Z")

</div>

Somehow this doesn’t work for me. The command “atom” is still trying to find a X11 display on Wayland ☹

---

<div class="post-metadata">

### Author: ![fricklerhandwerk](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fricklerhandwerk/32/2029_2.png) [@fricklerhandwerk](https://discourse.nixos.org/u/fricklerhandwerk)
#### Post date: [July 22, 2020, 11:30am UTC](https://discourse.nixos.org/t/include-custom-environment-variable-into-wrapper/8229/4 "2020-07-22T11:30:13Z")

</div>

I cannot help at all with the actual software in question, but my take at debugging the configuration would be inspecting the output of

```sh
cat $(which atom)

```

That would tell you if the wrapper was constructed as intended.
