|
| 1 | +# Using Newer Builtins {#sec-newer-builtins} |
| 2 | + |
| 3 | +Newer versions of Nix sometimes create new builtin functions, which can add new functionality or be more efficient versions of existing functions in `lib`. |
| 4 | +However, these new builtins can only be used in limited ways for a significant period of time after they were added. |
| 5 | +This is because of Nixpkgs' compatibility promise with older versions of Nix. |
| 6 | + |
| 7 | +The oldest version of Nix that Nixpkgs supports is listed in `lib/minfeatures.nix`. |
| 8 | +Any evaluation of Nixpkgs with an older Nix will fail. |
| 9 | +There is no specific process for raising the minimum version. |
| 10 | + |
| 11 | +The usage of functions added in newer Nix versions has to be done with care. |
| 12 | +In general, packages must not use the newer builtin themselves. |
| 13 | +Instead, `lib` can utilize these functions to improve the efficiency of existing functions, while still providing a fallback implementation in Nix for older versions. |
| 14 | + |
| 15 | +```nix |
| 16 | + # In lib |
| 17 | + function = builtins.function or (/* implementation without new builtins */) |
| 18 | +``` |
| 19 | + |
| 20 | +Even when a builtin may be used directly, try to use the applicable `lib` function instead when available. |
| 21 | +Using `lib` functions makes it much easier to evolve their functionality over time, because they are not bound to Nix's strict backwards compatibility policy. |
| 22 | + |
| 23 | +<!--## Builtins From Nix Forks {#sec-nix-fork-builtins} |
| 24 | +
|
| 25 | +TODO: Fill in this section once the status of PRs like #498999 is determined. |
| 26 | +
|
| 27 | +Some forks of Nix provide additional language builtins that are not present in upstream Nix. |
| 28 | +While useful for improving performance for the users of the fork, usage of these can be problematic because they bind Nixpkgs to the (possibly varied) implementations of the fork(s). |
| 29 | +These builtins... |
| 30 | +
|
| 31 | +Depending on the outcome, some ideas: |
| 32 | +- may be used, provided their behavior matches the calling `lib` function exactly and a fallback implementation remains available indefinitely. They should never be called within packages. |
| 33 | +- must not be used, because we can't make guarantees about their behavior. |
| 34 | +- <omit the section entirely> |
| 35 | +
|
| 36 | +--> |
0 commit comments