Use specific pkg version in overlay

Hi,

added the first overlay to my NixOS configuration. It applies a patch to mutter so that I have fractional scaling in GNOME (X11). The patch does only work for mutter v42.2.

How can I add to my config that mutter only in that version is used? How can I detect if mutter is updated in nixpkgs to e.g. 42.3 and adjust the patch?

Many thanks!

nixpkgs.overlays = [
    (
      # Patched version of mutter 44.2

      # Elements of nixpkgs must be taken from final and prev.
      final: prev: {
        # Elements of pkgs.gnome must be taken from gfinal and gprev.
        gnome = prev.gnome.overrideScope' (gfinal: gprev: {
          mutter = gprev.mutter.overrideAttrs (oldAttrs: {
            patches = (oldAttrs.patches or []) ++ [
              (prev.fetchpatch {
                url = "https://salsa.debian.org/gnome-team/mutter/-/raw/ubuntu/44.2-3ubuntu1/debian/patches/ubuntu/x11-Add-support-for-fractional-scaling-using-Randr.patch";
                # Determining the hash: https://github.com/NixOS/nixpkgs/issues/191128#issuecomment-1246030431
                hash = "sha256-GCtz87C1NgxenYE5nbxcIIxqNhutmdngscnlK10fRyQ=";
              })
            ];
          });
        });
      }
    )
  ];

This is the part where I have enabled X11 and GNOME:

  # Enable the X11 windowing system.
  services.xserver.enable = true;

  # Enable the GNOME Desktop Environment.
  services.xserver.displayManager.gdm.enable = true;
  # Toggles, weather the Wayland or X11 GNOME session is started.
  services.xserver.displayManager.gdm.wayland = false;
  services.xserver.desktopManager.gnome.enable = true;

You can try:

# ...
       mutter = gprev.mutter.overrideAttrs (oldAttrs: {
            if oldAttrs.version == "44.2" then
                patches =  # ...
            else throw "Mutter version mismatch. Please update patch.";
          });
#...
1 Like

Awesome! That approach looks like the perfect solution.

However, I figured out that there is a small syntax error. Here is the corrected version:

#...
          mutter = gprev.mutter.overrideAttrs (oldAttrs:
            if oldAttrs.version == "44.2" then
              {
                patches = # ...
              }
            else throw "Mutter version mismatch. Please update patch."
          );
#...