Jump to content

Overlays: Difference between revisions

683 bytes added ,  16 November 2022
Add two examples of how to manually apply overlays in a flake context
imported>Toraritte
(Move "Overlays" section from Alternative Package Sets article to here under "List of 3rd party overlays")
imported>Niols
(Add two examples of how to manually apply overlays in a flake context)
Line 50: Line 50:


==== In standalone nix code ====
==== In standalone nix code ====
===== In a shell.nix =====
When writing standalone nix code, for example a <code>shell.nix</code> for a project, one usually starts by importing nixpkgs: <code>let pkgs = import <nixpkgs> {}</code>. To use an overlay in this context, replace that by:
When writing standalone nix code, for example a <code>shell.nix</code> for a project, one usually starts by importing nixpkgs: <code>let pkgs = import <nixpkgs> {}</code>. To use an overlay in this context, replace that by:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }
import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }
</syntaxhighlight>
===== In a Nix flake =====
In a Nix flake, nixpkgs will be coming from the inputs. It is common to write something like
<syntaxhighlight lang="nix">
let pkgs = nixpkgs.legacyPackages.${system}
</syntaxhighlight>
where <code>system</code> is a variable containing eg. <code>"x86_64-linux"</code>. In order to apply overlays to this, one can do either of:
<syntaxhighlight lang="nix">
let pkgs = (nixpkgs.legacyPackages.${system}.extend overlay1).extend overlay2
</syntaxhighlight>
or, using the <code>import</code> function:
<syntaxhighlight lang="nix">
let pkgs = import nixpkgs { inherit system; overlays = [ overlay1 overlay2 ]; }
</syntaxhighlight>
</syntaxhighlight>


Anonymous user