Overlays: Difference between revisions

From NixOS Wiki
imported>Samueldr
(Adds code to use nixos configured overlays as <nixpkgs-overlays>.)
imported>Samueldr
m (Fixes + <ref>)
Line 39: Line 39:
There is a configuration option <code>nixpkgs.overlays</code>. Overlays set here will '''not''' be automatically applied by nix tools.
There is a configuration option <code>nixpkgs.overlays</code>. Overlays set here will '''not''' be automatically applied by nix tools.


===== Using <code>nixpkgs.overlays</code> as <code><nixpkgs-overlays></code> =====
===== Using <tt>nixpkgs.overlays</tt> as <tt><nixpkgs-overlays></tt> =====


In <tt>configuration.nix</tt>, add to <code>nix.nixPath</code>.
In <tt>configuration.nix</tt>, add to <code>nix.nixPath</code>.
Line 49: Line 49:
</syntaxhighlight>
</syntaxhighlight>


And, add the file <tt>/etc/nixos/overlays-compat/default.nix</tt>:
And, add the file <tt>/etc/nixos/overlays-compat/overlays.nix</tt><ref>[https://gitlab.com/samueldr/nixos-configuration/blob/3febd83b15210282d6435932944d426cd0a9e0ca/modules/overlays-compat/overlays.nix [[User:samueldr|@samueldr]]'s configuration: overlays-compat]</ref>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 70: Line 70:
* [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"]
<references />

Revision as of 19:50, 29 April 2018

Overlays provide a method to extend and change nixpkgs. They replace constructs like packageOverride and overridePackages.

Consider a simple example of setting the default proxy in Google Chrome:

let overlay1 = self: super:
{
   google-chrome = super.google-chrome.override {
     commandLineArgs =
       "--proxy-server='https=127.0.0.1:3128;http=127.0.0.1:3128'";
   };
};

Applying overlays manually

import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }

Applying overlays automatically

On the user level

A list of overlays placed into ~/.config/nixpkgs/overlays.nix will be automatically loaded by all nix tools.

Alternatively, you can put each overlay in its own .nix file under your ~/.config/nixpkgs/overlays directory.

On the system level

If you want your overlays to be accessible by nix tools and also in the system-wide configuration, add nixpkgs-overlays to your NIX_PATH:

NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays"

Currently nixos-rebuild only works with a <nixpkgs-overlays> path that is a directory.

There is a configuration option nixpkgs.overlays. Overlays set here will not be automatically applied by nix tools.

Using nixpkgs.overlays as <nixpkgs-overlays>

In configuration.nix, add to nix.nixPath.

  nix.nixPath = [
    "nixpkgs-overlays=/etc/nixos/overlays-compat/"
  ];

And, add the file /etc/nixos/overlays-compat/overlays.nix[1]:

self: super:
with super.lib;
let
  # Using the nixos plumbing that's used to evaluate the config...
  eval = import <nixpkgs/nixos/lib/eval-config.nix>;
  # Evaluate the config,
  paths = (eval {modules = [(import <nixos-config>)];})
    # then get the `nixpkgs.overlays` option.
    .config.nixpkgs.overlays
  ;
in
foldl' (flip extends) (_: super) paths self

External Documentation

  1. @samueldr's configuration: overlays-compat