FAQ: Difference between revisions
m Wifi -> WiFi |
Add FAQ entry about infinite recursion and imports |
||
| Line 433: | Line 433: | ||
== What does it mean to say that NixOS is "immutable" == | == What does it mean to say that NixOS is "immutable" == | ||
Immutability is a property of data, in general, which means that the data cannot be modified after it is created. In the context of an operating system, it really means that certain parts of the system have this property. In the case of Nix and NixOS, that includes the Nix store, where files can be created but not modified after the time they are created. It does not apply to every part of the operating system, in that users can still modify their own files in their home directory, for example. | Immutability is a property of data, in general, which means that the data cannot be modified after it is created. In the context of an operating system, it really means that certain parts of the system have this property. In the case of Nix and NixOS, that includes the Nix store, where files can be created but not modified after the time they are created. It does not apply to every part of the operating system, in that users can still modify their own files in their home directory, for example. | ||
== I'm getting ‘infinite recursion’ errors when trying to do something clever with <code>imports</code> == | |||
Evaluating the <code>imports</code> attribute of a NixOS module (such as configuration.nix) is a prerequisite for evaluating just about everything else, so trying anything clever with <code>imports</code> is a common source of infinite recursion (because the evaluator can't determine the values of packages and options without knowing what is imported, and can't determine what is imported without knowing the values of packages or options). | |||
You should not try to conditionally import other modules based on other values. Make your imports unconditional, and make the modules that you're importing have conditional ''behavior'' based on the values of options. | |||
If it helps, think of <code>imports</code> as akin to an `#include` directive in C. | |||
(Note that none of this applies to the [https://nix.dev/manual/nix/stable/language/builtins#builtins-import <code>import</code> built-in Nix language function], which is its own thing.) | |||
{{:FAQ/Libraries}} | {{:FAQ/Libraries}} | ||