Nix Cookbook: Difference between revisions

Mth (talk | contribs)
No edit summary
new recipe
Line 126: Line 126:
</syntaxHighlight>
</syntaxHighlight>


== Deprecating input parameters in mkDerivation-style packages ==
Sometimes we want to rename an input parameter.
E.G. an option `withX` that enables the X11 GUI for a certain app:
<syntaxHighlight lang="nix">
{
  /*. . .*/
  withX ? true,
  /*. . .*/
}
</syntaxHighlight>
Suppose that a new version of this package features a more agnostic GUI that can be linked to X11, GTK, Qt etc.
Because of it, `withX` is no longer a well descriptive name for this functionality.
Renaming the parameter is dangerous, because other functions that call this function expect this parameter.
This problem becomes more pronounced when in conjunction with custom, third-party overlays.
The solution is, roughly, emit a warning about the old parameter being used, reporting the user to the new parameter:
<syntaxHighlight lang="nix">
{
  /*. . .*/
  withX ? null,
  withGui ?
  if (withX != null) then
    lib.warn "withX is deprecated and will be removed in the next release; use withGui instead." withX
  else
    true
  /*. . .*/
}
</syntaxHighlight>


== Wrapping packages ==
== Wrapping packages ==