mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-11-25 01:23:08 +01:00
feat: lib.optionals
This commit is contained in:
parent
95e7833e71
commit
8cf2d8594a
@ -300,6 +300,8 @@ The disadvantage of this method is that all Nix modules that require conditional
|
||||
|
||||
The main advantage of this method is that it is much simpler than the methods previously introduced, requiring no modification to the module content, just using `lib.optionals` in `imports` to decide whether to import a module or not.
|
||||
|
||||
> Details about how `lib.optionals` works: <https://noogle.dev/f/lib/optionals>
|
||||
|
||||
Let's look at an example directly:
|
||||
|
||||
```nix
|
||||
|
@ -311,6 +311,8 @@ Nixpkgs 中的模块系统提供了一系列类似 `lib.mkIf` 的函数,用于
|
||||
|
||||
这种方式的主要好处是,它要比前面介绍的方法简单许多,不需要对模块内容做任何修改,只需要在 `imports` 中使用 `lib.optionals` 来决定是否导入某个模块即可。
|
||||
|
||||
> `lib.optionals` 函数的详细文档: <https://noogle.dev/f/lib/optionals>
|
||||
|
||||
直接看例子:
|
||||
|
||||
```nix
|
||||
|
Loading…
Reference in New Issue
Block a user