Overlays: Difference between revisions
imported>Erikarvstedt m wording |
imported>Symphorien add an example of overlay to override a version |
||
| Line 98: | Line 98: | ||
* [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"] | ||
== Examples of overlays == | |||
Here are a few example usages of overlays. | |||
=== Overriding a version === | |||
Assume you want the original version of sl, not the fork that nixpkgs ships. First, you have to choose the exact revision you want nix to build. Here we will build revision 923e7d7ebc5c1f009755bdeb789ac25658ccce03. The core of the method is to override the attribute <code>src</code> of the derivation with an updated value. Here we use <code>fetchFromGitHub</code> because sl is hosted on github, but other locations need other functions. To see the original derivation, run <code>nix edit -f "<nixpkgs>" sl</code>. | |||
This method will fail if the build system changed or new dependencies are required. | |||
<syntaxhighlight lang="nix"> | |||
self: super: | |||
{ | |||
sl = super.sl.overrideAttrs (old: { | |||
src = super.fetchFromGitHub { | |||
owner = "mtoyoda"; | |||
repo = "sl"; | |||
rev = "923e7d7ebc5c1f009755bdeb789ac25658ccce03"; | |||
# If you don't know the hash, the first time, set: | |||
# sha256 = "0000000000000000000000000000000000000000000000000000"; | |||
# then nix will fail the build with such an error message: | |||
# hash mismatch in fixed-output derivation '/nix/store/m1ga09c0z1a6n7rj8ky3s31dpgalsn0n-source': | |||
# wanted: sha256:0000000000000000000000000000000000000000000000000000 | |||
# got: sha256:173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4 | |||
sha256 = "173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4"; | |||
}; | |||
}); | |||
} | |||
== Python Packages Overlay == | </syntaxhighlight> | ||
=== Python Packages Overlay === | |||
Here is an example of Python packages overlay. The trick is to also override python itself with `packageOverrides`. | Here is an example of Python packages overlay. The trick is to also override python itself with `packageOverrides`. | ||