Overlays: Difference between revisions

imported>Mickours
Add python package override
imported>Netvl
There is no need to manually evaluate nixos-config; it is sufficient to load <nixpkgs/nixos> which will evaluate the config object automatically
Line 55: Line 55:
===== Using <tt>nixpkgs.overlays</tt> from <tt>configuration.nix</tt> as <tt><nixpkgs-overlays></tt> in your NIX_PATH =====
===== Using <tt>nixpkgs.overlays</tt> from <tt>configuration.nix</tt> as <tt><nixpkgs-overlays></tt> in your NIX_PATH =====


This will allow all the Nix tools to see the exact same overlay as is defined in your <tt>configuration.nix</tt> in the {{nixos:option|nixpkgs.overlays}} option.
Configuration below will allow all of the Nix tools to see the exact same overlay as is defined in your <tt>configuration.nix</tt> in the {{nixos:option|nixpkgs.overlays}} option.


In <tt>configuration.nix</tt>, depending on whether your <tt>configuration.nix</tt> already defines <code>nix.nixPath</code>, add one of those definitions:
The core of the idea here is to point the <code>nixpkgs-overlays</code> element of <code>NIX_PATH</code> to a "compatibility" overlay, which will load all of the overlays defined in your NixOS system configuration and apply them to its own input. Thus, when various Nix tools attempt to load the overlays from the <code>nixpkgs-overlays</code> element of <code>NIX_PATH</code>, they will get contents of overlays defined in your NixOS system config.
 
First, in the <tt>configuration.nix</tt> file, depending on whether your <tt>configuration.nix</tt> already defines <code>nix.nixPath</code>, add one of these definitions:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, options, ... }: {
{ config, pkgs, options, ... }: {
   # With existing `nix.nixPath` entry:
   # With an existing `nix.nixPath` entry:
   nix.nixPath = [
   nix.nixPath = [
     # Add the following to existing entries.
     # Add the following to existing entries.
     "nixpkgs-overlays=/etc/nixos/overlays-compat/"
     "nixpkgs-overlays=/etc/nixos/overlays-compat/"
   ];
   ];
   # Without any `nix.nixPath` entry:
   # Without any `nix.nixPath` entry:
   nix.nixPath =
   nix.nixPath =
Line 76: Line 79:
</syntaxhighlight>
</syntaxhighlight>


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>:
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]]'s configuration: overlays-compat]</ref>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 82: Line 85:
with super.lib;
with super.lib;
let
let
   # Using the nixos plumbing that's used to evaluate the config...
   # Load the system config and get the `nixpkgs.overlays` option
   eval = import <nixpkgs/nixos/lib/eval-config.nix>;
   overlays = (import <nixpkgs/nixos> { }).config.nixpkgs.overlays;
  # Evaluate the config,
  paths = (eval {modules = [(import <nixos-config>)];})
    # then get the `nixpkgs.overlays` option.
    .config.nixpkgs.overlays
  ;
in
in
foldl' (flip extends) (_: super) paths self
  # Apply all overlays to the input of the current "main" overlay
  foldl' (flip extends) (_: super) overlays self
</syntaxhighlight>
</syntaxhighlight>
The <tt>/etc/nixos/overlays-compat</tt> directory should contain a single <tt>overlays.nix</tt> file to be understood by the Nix tooling, but the location of this directory can be arbitrary, as long as it is set correctly in the <code>nix.nixPath</code> option.


== External Documentation ==
== External Documentation ==