Skip to content

Commit 95c74ea

Browse files
committed
Allow dashes in identifiers
In Nixpkgs, the attribute in all-packages.nix corresponding to a package is usually equal to the package name. However, this doesn't work if the package contains a dash, which is fairly common. The convention is to replace the dash with an underscore (e.g. "dbus-lib" becomes "dbus_glib"), but that's annoying. So now dashes are valid in variable / attribute names, allowing you to write: dbus-glib = callPackage ../development/libraries/dbus-glib { }; and buildInputs = [ dbus-glib ]; Since we don't have a negation or subtraction operation in Nix, this is unambiguous.
1 parent f46612b commit 95c74ea

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

doc/manual/release-notes.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
<itemizedlist>
1616

17+
<listitem>
18+
<para>Dashes are now valid as part of identifiers and attribute
19+
names.</para>
20+
</listitem>
21+
1722
<listitem>
1823
<para>Nix no longer sets the immutable bit on files in the Nix
1924
store. Instead, the recommended way to guard the Nix store

misc/emacs/nix-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The hook `nix-mode-hook' is run when Nix mode is started.
7878
("\\<isNull\\>" . font-lock-builtin-face)
7979
("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
8080
. font-lock-constant-face)
81-
("\\<\\([a-zA-Z_][a-zA-Z0-9_'\.]*\\)[ \t]*="
81+
("\\<\\([a-zA-Z_][a-zA-Z0-9_'\-\.]*\\)[ \t]*="
8282
(1 font-lock-variable-name-face nil nil))
8383
("<[a-zA-Z0-9._\\+-]+\\(/[a-zA-Z0-9._\\+-]+\\)*>"
8484
. font-lock-constant-face)

src/libexpr/lexer.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s)
7878
%}
7979

8080

81-
ID [a-zA-Z\_][a-zA-Z0-9\_\']*
81+
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
8282
INT [0-9]+
8383
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
8484
SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\>

tests/lang/eval-okay-attrs5.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let
44

55
as = { x.y.z = 123; a.b.c = 456; };
66

7-
bs = { foo.bar = "foo"; };
7+
bs = { f-o-o.bar = "foo"; };
88

99
or = x: y: x || y;
1010

@@ -13,7 +13,7 @@ in
1313
as.foo or "foo"
1414
as.x.y.bla or as.a.b.c
1515
as.a.b.c or as.x.y.z
16-
as.x.y.bla or bs.foo.bar or "xyzzy"
16+
as.x.y.bla or bs.f-o-o.bar or "xyzzy"
1717
as.x.y.bla or bs.bar.foo or "xyzzy"
1818
123.bla or null.foo or "xyzzy"
1919
# Backwards compatibility test.

0 commit comments

Comments
 (0)