Write me a nixos overlay that uses a specific mesa version
- User
Write me a nixos overlay that uses a specific mesa version
- 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
-
Create a directory for your overlay if you haven't already:
mkdir -p ~/nixos-overlays -
Create an overlay file, for example,
mesa-overlay.nixin that directory:touch ~/nixos-overlays/mesa-overlay.nix -
Open the
mesa-overlay.nixfile in your preferred text editor.
Step 2: Write the Overlay
Add the following content to the
mesa-overlay.nixfile, 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
hashattribute for thesrcmust 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.gzThis will output the hash you need.
Step 3: Enable the Overlay
To enable the overlay, you'll need to modify your
configuration.nixto 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 switchConclusion
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.
-