Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

Write me a nixos overlay that uses a specific mesa version

  1. User

    Write me a nixos overlay that uses a specific mesa version

  2. Assistant

    Creating a NixOS overlay that specifies a particular version of Mesa involves editing the Nix expression files properly. Below is an example of how to create a NixOS overlay that specifies a custom version of Mesa.

    Step 1: Create the Overlay File

    1. Create a directory for your overlay if you haven't already:

      mkdir -p ~/nixos-overlays
      
    2. Create an overlay file, for example, mesa-overlay.nix in that directory:

      touch ~/nixos-overlays/mesa-overlay.nix
      
    3. Open the mesa-overlay.nix file in your preferred text editor.

    Step 2: Write the Overlay

    Add the following content to the mesa-overlay.nix file, replacing <desired-mesa-version> with the version of Mesa you want to use (for example, "21.2.5"):

    self: super:
    
    {
      mesa = super.mesa.overrideAttrs (oldAttrs: {
        version = "<desired-mesa-version>"; # e.g., "21.2.5"
        src = super.fetchFromGitHub {
          owner = "Mesa3D";
          repo = "mesa";
          rev = "mesa-<desired-mesa-version>"; # e.g., "mesa-21.2.5"
          hash = "sha256-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; # replace with actual hash
        };
      });
    }
    

    Note on Hashes

    The hash attribute for the src must be specified. You need to replace "sha256-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" with the actual hash of the source tarball. To get this hash, you may fetch the tarball manually and compute the hash using the Nix command below:

    nix-prefetch-url --unpack https://github.com/Mesa3D/mesa/archive/mesa-<desired-mesa-version>.tar.gz
    

    This will output the hash you need.

    Step 3: Enable the Overlay

    To enable the overlay, you'll need to modify your configuration.nix to include your overlay directory. Add the following line:

    nixpkgs.overlays = [
      (import ~/nixos-overlays/mesa-overlay.nix)
    ];
    

    Step 4: Rebuild NixOS

    After saving your changes, rebuild your NixOS system with:

    sudo nixos-rebuild switch
    

    Conclusion

    You should now have a system that uses the specified version of Mesa. Be sure to test your graphics applications to ensure they are functioning correctly with the new version. Adjust the overlay and dependencies as necessary based on your requirements.