Overriding package with environment variable wrap

I have a NixOS configuration using a Nix Flake. My configuration is split into different modules that add packages and settings.

Right now my configuration imports a file that includes all my packages, and another that configures Hyprland. I am on a HiDPI display so I am using environment variables tohttps://nixos.wiki/wiki/Nix_Cookbook#Wrapping_packages scale xwayland apps at 2x, but setting this globally causes some issues, so I am wrapping the packages.

The issue I’m running into is that if the apps that are wrapped are also included in my packages, the wrap will not work, as the standard package seems to be first in my path.

For example

    (pkgs.symlinkJoin {
      name = "discord-canary";
      paths = [ pkgs.discord-canary];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = ''
        wrapProgram $out/opt/DiscordCanary/DiscordCanary --set GDK_SCALE 2 --set XCURSOR_SIZE 64
      '';
    })

does not work if discord-canary is installed in another file.

I wanted to use overlays, as I assume that would make the declaration in the other file install the overlay. I tried this:

    (self: super: {
      discord-canary = pkgs.symlinkJoin {
        name = "discord-canary";
        paths = [ pkgs.discord-canary];
        buildInputs = [ pkgs.makeWrapper ];
        postBuild = ''
          wrapProgram $out/opt/DiscordCanary/DiscordCanary --set GDK_SCALE 2 --set XCURSOR_SIZE 64
        '';
      };
    })

However, because this refers to discord-canary in the package declaration, it gives an infinite recursion error.

Is there any way to declaratively wrap packages that are installed in another file?

In the overlay’s version, you need to ask nix to use the previously defined discord-canary (before applying the overlay) as dependency.
You should replace paths = [ pkgs.discord-canary]; with paths = [ super.discord-canary];.

1 Like

Damn I could’ve sworn I had tried that, but now that I think about it I may have typed, super.pkgs.discord-canary instead of super.discord-canary. Thank you!

I have a follow-up question if you don’t mind and happen to know. In my packages file, I have discord declared as (discord-canary.override { nss = nss_latest; withOpenASAR = true; }) to use openASAR. Do you know if there’s a way to keep this declaration so that other hosts use it, while also using the wrap override when using Hyprland? Right now I get error: attribute 'override' missing which makes sense.

I’d like to be able to have discord using that override in that file, but also allow the hyprland module to override it witth the wrap. I understand if that isn’t possible though.

I’ve found a way to do this, but it could probably be made much less convoluted. In my packages file I created an overlay:

  nixpkgs.overlays = [
    (self: super: {
      discord-canary-overlay = super.discord-canary.override { 
        nss = pkgs.nss_latest; withOpenASAR = true; };
    })
  ];

Then I changed the Hyprland modules overlay to overlay the other overlay:

    (self: super: {
      discord-canary-overlay = pkgs.symlinkJoin {
        name = "discord-canary-overlay";
        paths = [ super.discord-canary-overlay ];
        buildInputs = [ pkgs.makeWrapper ];
        postBuild = ''
          wrapProgram $out/opt/DiscordCanary/DiscordCanary --set GDK_SCALE 2 --set XCURSOR_SIZE 64
        '';
      };
    })

And as hacked together as this is, it seems to work as I’d want it to.