toraritte
toraritte

Reputation: 8303

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

I'm aware of a similar question, but that refers to ? used in function definitions with a set pattern (pinned).

I looked up the implementation of lib.makeOverridable and came across this line:

  ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:

(Also learned that this kind of dynamic assignment is possible, so that's a bonus.)

Upvotes: 3

Views: 591

Answers (1)

toraritte
toraritte

Reputation: 8303

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

Upvotes: 4

Related Questions