Nix Cookbook: Difference between revisions

new recipe
Line 126: Line 126:
</syntaxHighlight>
</syntaxHighlight>


== Deprecating input parameters in mkDerivation-style packages ==
== Deprecating a specific input parameter in mkDerivation-style packages ==


Sometimes we want to rename an input parameter.
Sometimes we want to rename some input parameter in .


E.G. an option `withX` that enables the X11 GUI for a certain app:
E.G. an option `withX` that enables the X11 GUI for a certain app:
Line 137: Line 137:
   withX ? true,
   withX ? true,
   /*. . .*/
   /*. . .*/
}
}:
 
stdenv.mkDerivation { /* . . . */}
</syntaxHighlight>
</syntaxHighlight>


Suppose that a new version of this package features a more agnostic GUI that can be linked to X11, GTK, Qt etc.
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.
Because of it, `withX` is no longer a descriptive name for this functionality.


Renaming the parameter is dangerous, because other functions that call this function expect this parameter.
However, 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 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:
The solution is, roughly, to emit a warning about the old parameter being used, reporting the user to the new parameter:


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">