NixOS modules: Difference between revisions
imported>Milahu clarify modulesPath |
imported>Milahu add section modulesPath |
||
Line 64: | Line 64: | ||
<dt><code>modulesPath</code></dt> | <dt><code>modulesPath</code></dt> | ||
<dd | <dd>The location of the <code>module</code> directory of NixOS.</dd> | ||
</dd> | |||
</dl> | </dl> | ||
==== modulesPath ==== | |||
Some modules use <code>modulesPath</code> to import nixos libraries | |||
For example <code>nixos/modules/virtualisation/digital-ocean-config.nix</code> | |||
<pre> | |||
{ config, pkgs, lib, modulesPath, ... }: | |||
imports = [ | |||
(modulesPath + "/profiles/qemu-guest.nix") | |||
(modulesPath + "/virtualisation/digital-ocean-init.nix") | |||
]; | |||
</pre> | |||
The Nix variable <code>modulesPath</code> is parsed from the environment variable <code>NIX_PATH</code> | |||
When <code>NIX_PATH</code> is empty, Nix can throw the error <code>undefined variable 'modulesPath'</code> | |||
<code>NIX_PATH</code> should look something like this: | |||
<pre> | |||
echo $NIX_PATH | tr : '\n' | |||
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos | |||
nixos-config=/etc/nixos/configuration.nix | |||
/nix/var/nix/profiles/per-user/root/channels | |||
</pre> | |||
Here, the <code>modulesPath</code> is <code>/nix/var/nix/profiles/per-user/root/channels</code> | |||
When a Nix expression calls <code>import <nixpkgs></code>,<br> | |||
then Nix will load <code>/nix/var/nix/profiles/per-user/root/channels/nixos</code> | |||
=== Imports === | === Imports === |