如何解决未在函数定义中使用时,问号在 Nix 中意味着什么?
我知道 a similar question,但它指的是 function definitions with a set pattern (pinned) 中使用的 ?
。
我查找了 lib.makeOverridable
的实现并发现了 this line:
${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:
(还了解到这种动态分配是可能的,所以这是一个奖励。)
解决方法
根据 15.3. Operators 中 pinned (Nix manual) 的表格:
表 15.1。运营商
| Name | Syntax | Description |
+---------------+--------------+---------------------------------+
| | | Test whether set e contains the |
| Has Attribute | e ? attrpath | attribute denoted by attrpath; |
| | | return true or false. |
+---------------+--------------+---------------------------------+
示例:
$ 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。