Over in another post, I mentioned that I did not understand the concept of Overlays.
Thanks @Birdee, for your reply:
Overlays just cause a new pkgs object to be returned and used instead which contains whichever things the overlay adds to it.
(self: super: { jq = super.jq; })
This overlay, for example, would replace jq with itself lol
…
the two arguments for overlays are either called self: super: or final: prev: by convention and are the new and old pkgs sets before and after the overlay is called.
Still though, I am struggling to grasp it as I am lacking a lot for basic knowledge. I will try to break it down below. I might very well be wrong in my assumptions, so please correct me.
Overlays just cause a new pkgs object to be returned and used instead which contains whichever things the overlay adds to it.
A package object is what is found here. So, Overlays somehow alters existing package object, like parameters for a program.
Let’s take the example above:
(self: super: { jq = super.jq; })
or, using the new convention:
(final: prev: { jq = prev.jq; })
It does not help I am new to functional programming as well. So, I even find the code confusing. However, it is a function with final
and prev
as input parameters. All Overlay functions are defined like this. It is seemingly a part of the Nix language.
In the above example an Overlay is created for the JSON processor jq. As stated in the documentation: “prev comes from only the stage before”. So, you are replacing jq
with jq
. I think I got that.
But, one overlay I have seen several places is the following one, for waybar:
# fix waybar not displaying hyprland workspaces
(self: super: {
waybar = super.waybar.overrideAttrs (oldAttrs: {
mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
});
})
I see that overrideAttrs is a part of Nix.
When I look at the code, as a non-functional programmer, it looks like the entire waybar package object is replaced with “super.waybar.overrideAttrs” with this code:
waybar = super.waybar.overrideAttrs
…
But, I guess that is not the case. It should only be the mesonFlags
that is altered, and the string -Dexperimental=true"
that has been added to it, I guess. I just do not understand that the assignment above will not overwrite the entire waybar package. Or, maybe overrideAttrs
returns the waybar package itself, with the changed attributes? That would make sense.
In the documentation, the following example is listed:
helloBar = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: {
pname = previousAttrs.pname + "-bar";
});
I guess previousAttrs
in the example equals oldAttrs
from the waybar Overlay. But, would it work to add finalAttrs
as well, like this:
# fix waybar not displaying hyprland workspaces
(self: super: {
waybar = super.waybar.overrideAttrs (finalAttrs: oldAttrs: {
mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
});
})
How do one find out what attributes are accessible in a package? Like, waybar’s mesonFlags
. Is the solution to check the source code of the package you want to alter?