Overlays: Difference between revisions
imported>Tmillr m grammar |
Adisbladis (talk | contribs) Separate python overlay args from nixpkgs overlay args |
||
(8 intermediate revisions by 8 users not shown) | |||
Line 18: | Line 18: | ||
== Data flow of overlays == | == Data flow of overlays == | ||
The data flow | The data flow of overlays, especially regarding <tt>prev</tt> and <tt>final</tt> arguments can be a bit confusing if you are not familiar with how overlays work. This graph shows the data flow: | ||
[[File:Dram-overlay-final-prev.png]] | [[File:Dram-overlay-final-prev.png]] | ||
Line 43: | Line 43: | ||
And <syntaxhighlight lang="nix">final: prev: firefox = final.firefox.override { ... };</syntaxhighlight> would cause infinite recursion. | And <syntaxhighlight lang="nix">final: prev: { firefox = final.firefox.override { ... }; }</syntaxhighlight> would cause infinite recursion. | ||
== Using overlays == | == Using overlays == | ||
Line 148: | Line 148: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Then, add the following contents to <tt>/etc/nixos/overlays-compat/overlays.nix</tt><ref>Based on [https://gitlab.com/samueldr/nixos-configuration/blob/3febd83b15210282d6435932944d426cd0a9e0ca/modules/overlays-compat/overlays.nix [[User: | Then, add the following contents to <tt>/etc/nixos/overlays-compat/overlays.nix</tt><ref>Based on [https://gitlab.com/samueldr/nixos-configuration/blob/3febd83b15210282d6435932944d426cd0a9e0ca/modules/overlays-compat/overlays.nix][[User:Samueldr|@samueldr]]<span>'s configuration: overlays-compat</span></ref>: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 225: | Line 225: | ||
final: prev: { | final: prev: { | ||
# elements of pkgs.gnome must be taken from gfinal and gprev | # elements of pkgs.gnome must be taken from gfinal and gprev | ||
gnome = prev.gnome.overrideScope | gnome = prev.gnome.overrideScope (gfinal: gprev: { | ||
mutter = gprev.mutter.overrideAttrs (oldAttrs: { | mutter = gprev.mutter.overrideAttrs (oldAttrs: { | ||
patches = oldAttrs.patches ++ [ | patches = oldAttrs.patches ++ [ | ||
Line 253: | Line 253: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Overriding a package inside an attribute set === | === Overriding a package inside an extensible attribute set === | ||
Here is an example of adding plugins to `vimPlugins`. | Here is an example of adding plugins to `vimPlugins`. | ||
Line 262: | Line 262: | ||
}); | }); | ||
} | } | ||
</syntaxhighlight> | |||
=== Overrding a package inside a plain attribute set === | |||
Here's an example of overriding the source of <code>obs-studio-plugins.obs-backgroundremoval</code>. | |||
<syntaxhighlight lang="nix"> | |||
final: prev: { | |||
obs-studio-plugins = prev.obs-studio-plugins // { | |||
obs-backgroundremoval = | |||
prev.obs-studio-plugins.obs-backgroundremoval.overrideAttrs (old: { | |||
version = "0.5.17"; | |||
src = prev.fetchFromGitHub { | |||
owner = "royshil"; | |||
repo = "obs-backgroundremoval"; | |||
rev = "v0.5.17"; | |||
hash = ""; | |||
}; | |||
}); | |||
}; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 274: | Line 295: | ||
final: prev: | final: prev: | ||
# Within the overlay we use a recursive set, though I think we can use `final` as well. | # Within the overlay we use a recursive set, though I think we can use `final` as well. | ||
{ | |||
# nix-shell -p python.pkgs.my_stuff | # nix-shell -p python.pkgs.my_stuff | ||
python = prev.python.override { | python = prev.python.override { | ||
# Careful, we're using a different final and prev here! | # Careful, we're using a different final and prev here! | ||
packageOverrides = | packageOverrides = pyfinal: pyprev: { | ||
my_stuff = | my_stuff = pyprev.buildPythonPackage rec { | ||
pname = "pyaes"; | pname = "pyaes"; | ||
version = "1.6.0"; | version = "1.6.0"; | ||
src = | src = pyprev.fetchPypi { | ||
inherit pname version; | inherit pname version; | ||
hash = "0bp9bjqy1n6ij1zb86wz9lqa1dhla8qr1d7w2kxyn7jbj56sbmcw"; | hash = "0bp9bjqy1n6ij1zb86wz9lqa1dhla8qr1d7w2kxyn7jbj56sbmcw"; | ||
Line 290: | Line 311: | ||
}; | }; | ||
# nix-shell -p pythonPackages.my_stuff | # nix-shell -p pythonPackages.my_stuff | ||
pythonPackages = python.pkgs; | pythonPackages = final.python.pkgs; | ||
# nix-shell -p my_stuff | # nix-shell -p my_stuff | ||
my_stuff = pythonPackages.buildPythonPackage rec { | my_stuff = final.pythonPackages.buildPythonPackage rec { | ||
pname = "pyaes"; | pname = "pyaes"; | ||
version = "1.6.0"; | version = "1.6.0"; | ||
Line 307: | Line 328: | ||
=== R Packages Overlay === | === R Packages Overlay === | ||
Here is an example of an R packages overlay, in which it can be seen how to provide different versions of packages then those available in the current R version. It should be noted that in the case of R and Python the argument to <code>override</code> is named differently. Names of these can be | Here is an example of an R packages overlay, in which it can be seen how to provide different versions of packages then those available in the current R version. It should be noted that in the case of R and Python the argument to <code>override</code> is named differently. Names of these can be found using <code>nix repl</code> and evaluating e.g. <code>python.override.__functionArgs</code>. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 376: | Line 397: | ||
* [https://nixos.org/manual/nixpkgs/unstable/#using-community-maintained-rust-toolchains Details in the Nixpkgs manual for using Rust overlays] | * [https://nixos.org/manual/nixpkgs/unstable/#using-community-maintained-rust-toolchains Details in the Nixpkgs manual for using Rust overlays] | ||
* [https://github.com/peter-sa/nixos-rocm Overlay for Radeon Open-Compute packages] | * [https://github.com/peter-sa/nixos-rocm Overlay for Radeon Open-Compute packages] | ||
* [https://github.com/garbas/nixpkgs-python Overlay by Rok Garbas for a set of python packages built by pypi2nix] | * [https://github.com/garbas/nixpkgs-python Overlay by Rok Garbas for a set of python packages built by pypi2nix (archived)] | ||
== See also == | == See also == | ||
Line 382: | Line 403: | ||
* [https://nixos.org/nixpkgs/manual/#chap-overlays Overlays in nixpkgs manual] | * [https://nixos.org/nixpkgs/manual/#chap-overlays Overlays in nixpkgs manual] | ||
* [https://blog.flyingcircus.io/2017/11/07/nixos-the-dos-and-donts-of-nixpkgs-overlays/ Blog post "The DOs and DON’Ts of nixpkgs overlays"] | * [https://blog.flyingcircus.io/2017/11/07/nixos-the-dos-and-donts-of-nixpkgs-overlays/ Blog post "The DOs and DON’Ts of nixpkgs overlays"] | ||
* [https://www.youtube.com/watch?v=s2fkgkN55vk&list=PLgknCdxP89ReD6gxl755B6G_CI65z4J2e Nixpkgs Overlays – A place for all excluded packages] - Talk by Nicolas B. Pierron at NixCon 2017 | |||
==== References ==== | ==== References ==== |