Skip to content

Commit 02e3126

Browse files
RFC 137: Set Nix language version in magic comment
1 parent 553b132 commit 02e3126

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

rfcs/0137-nix-language-version.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
feature: nix-language-version
3+
start-date: 2022-12-12
4+
author: @fricklerhandwerk
5+
co-authors: @thufschmitt @Ericson2314
6+
shepherd-team:
7+
shepherd-leader:
8+
related-issues: https://github.com/NixOS/nix/issues/7255
9+
---
10+
11+
# Summary
12+
[summary]: #summary
13+
14+
Add a mechanism to determine which version of the Nix language grammar to use for parsing Nix files.
15+
16+
# Motivation
17+
[motivation]: #motivation
18+
19+
Currently it's impossible to introduce backwards-incompatible changes to the Nix language without breaking existing setups.
20+
This proposal is an attempt to overcome that limitation.
21+
22+
# Detailed design
23+
[design]: #detailed-design
24+
25+
Introduce a magic comment in the first line of a Nix file:
26+
27+
#? Nix <version>
28+
29+
where `<version>` is a released version of Nix the given file is known to work with.
30+
31+
It is left to the implementation how to use this information.
32+
33+
# Examples and Interactions
34+
[examples-and-interactions]: #examples-and-interactions
35+
36+
```nix
37+
#? Nix 2.12
38+
"nothing"
39+
```
40+
41+
# Advantages
42+
[advantages]: #advantages
43+
44+
- Backwards compatible
45+
- Visually unintrusive
46+
- Self-describing and human-readable
47+
- Opt-in until the feature is implemented in Nix *and* the first backwards-incompatible change to the language is introduced.
48+
- Follows a well-known convention of using [magic numbers in files](https://en.m.wikipedia.org/wiki/Magic_number_(programming)#In_files)
49+
- Encourages, but does not require the Nix evaluator to deal with backwards-incompatible changes in a principled manner.
50+
51+
# Drawbacks
52+
[drawbacks]: #drawbacks
53+
54+
- The syntax of the magic comment is arbitrary.
55+
- At least one form of comment is forever bound to begin with `#` to maintain compatibility.
56+
- There is a chance of abusing the magic comment for more metadata in the future.
57+
Let's avoid that.
58+
- It requires effort to implement an appropriate system to make use of the version information.
59+
60+
# Alternatives
61+
[alternatives]: #alternatives
62+
63+
- Never introduce backwards-incompatible changes to the language.
64+
65+
This is what has been happening so far, and required additions to be made very carefully.
66+
67+
- Use a different versioning scheme for the Nix language that is decoupled from the rest of Nix.
68+
69+
Although this can be done at any point in the future, because it's the evaluator that will read this information.
70+
71+
- Use a magic string that is incompatible with evaluators prior to the feature, e.g. `%? Nix <version>`.
72+
73+
This would make clear to users that the file is not intended to be used without explicit handling of compatibility.
74+
Such a breaking change could be reserved for later iterations of how Nix encodes language version information.
75+
76+
# Unresolved questions
77+
[unresolved]: #unresolved-questions
78+
79+
- Is the proposed magic number already in use in [other file formats](https://en.m.wikipedia.org/wiki/Magic_number_(programming)#In_files)?
80+
- Should we allow multiple known-good versions in one line?
81+
82+
# Future work
83+
[future]: #future-work
84+
85+
Determine what exaclty to do with the information given in the magic comment.

0 commit comments

Comments
 (0)