Include custom environment variable into wrapper

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 :frowning:

Best regards

The Wiki has detailed variants of a solution. Building on the answer I found on StackOverflow I suggest (without testing it or knowing anything about the packages in question):

{ config, pkgs, ...}:
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
  # 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 of the general problem with wrappers.

1 Like

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

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

cat $(which atom)

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