What does a question mark mean in Nix when not used in a function definition?

Viewed 122
1 Answers

According to the table at 15.3. Operators (pinned) in the Nix manual:

Table 15.1. Operators

| Name          | Syntax       | Description                     |
+---------------+--------------+---------------------------------+
|               |              | Test whether set e contains the |
| Has Attribute | e ? attrpath | attribute denoted by attrpath;  |
|               |              | return true or false.           |
+---------------+--------------+---------------------------------+

Examples:

$ nix repl
Welcome to Nix version 2.3.10. Type :? for help.

nix-repl> set = { a = 27; b = "lofa"; }

nix-repl> set ? a
true

nix-repl> set ? lofa
false

nix-repl> supset = { c = set; d = 7; }

nix-repl> supset ? c.a
true
Related