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 ===== | ||
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. | |||
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> | ||
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 | ||
# | # Load the system config and get the `nixpkgs.overlays` option | ||
overlays = (import <nixpkgs/nixos> { }).config.nixpkgs.overlays; | |||
in | in | ||
foldl' (flip extends) (_: super) | # 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 == |