Skip to content

Commit 1d46099

Browse files
committed
1 parent e0b5df3 commit 1d46099

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

doc/functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The Nixpkgs repository has several utility functions to manipulate Nix expressio
44

55
```{=include=} sections
66
functions/library.md
7+
functions/newer-builtins.section.md
78
functions/generators.section.md
89
functions/debug.section.md
910
functions/prefer-remote-fetch.section.md
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
-->

doc/redirects.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@
472472
"chap-overlays": [
473473
"index.html#chap-overlays"
474474
],
475+
"sec-newer-builtins": [
476+
"index.html#sec-newer-builtins"
477+
],
475478
"sec-nixpkgs-release-26.11": [
476479
"release-notes.html#sec-nixpkgs-release-26.11"
477480
],

0 commit comments

Comments
 (0)