Overlays: Difference between revisions
imported>Symphorien example of .override with a flag |
imported>Symphorien explain how to use the nixpkgs.overlay option |
||
Line 29: | Line 29: | ||
=== Applying overlays manually === | === Applying overlays manually === | ||
==== In standalone nix code ==== | |||
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> | </syntaxhighlight> | ||
==== In NixOS ==== | |||
In <code>/etc/nixos/configuration.nix</code>, use the <code>nixpkgs.overlays</code> option: | |||
<syntaxhighlight lang="nix"> | |||
{ config, pkgs, lib, ... }: | |||
{ | |||
# [...] | |||
nixpkgs.overlays = [ (self: super: /* overlay goes here */) ]; | |||
} | |||
</syntaxhighlight> | |||
{{Evaluate}} | |||
Note that this does not impact the usage of nix on the command line, only your NixOS configuration. | |||
==== In [[Home Manager]] ==== | |||
In <code>~/.config/nixpkgs/home.conf</code>, use the <code>nixpkgs.overlays</code> option: | |||
<syntaxhighlight lang="nix"> | |||
{ config, pkgs, lib, ... }: | |||
{ | |||
# [...] | |||
nixpkgs.overlays = [ (self: super: /* overlay goes here */) ]; | |||
} | |||
</syntaxhighlight> | |||
Note that this does not impact the usage of nix on the command line or in your your NixOS configuration, only your home-manager configuration. | |||
=== Applying overlays automatically === | === Applying overlays automatically === | ||
Line 37: | Line 68: | ||
==== On the user level ==== | ==== On the user level ==== | ||
A list of overlays placed into <code>~/.config/nixpkgs/overlays.nix</code> will be automatically loaded by all nix tools. | A list of overlays placed into <code>~/.config/nixpkgs/overlays.nix</code> will be automatically loaded by all nix tools run as your user (hence not nixos-rebuild). | ||
Alternatively, you can put each overlay in its own .nix file under your <code>~/.config/nixpkgs/overlays</code> directory. | Alternatively, you can put each overlay in its own .nix file under your <code>~/.config/nixpkgs/overlays</code> directory. |