feat: lib.optionals

This commit is contained in:
Ryan Yin 2024-03-08 14:30:56 +08:00
parent 95e7833e71
commit 8cf2d8594a
2 changed files with 4 additions and 0 deletions

View File

@ -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. 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: Let's look at an example directly:
```nix ```nix

View File

@ -311,6 +311,8 @@ Nixpkgs 中的模块系统提供了一系列类似 `lib.mkIf` 的函数,用于
这种方式的主要好处是,它要比前面介绍的方法简单许多,不需要对模块内容做任何修改,只需要在 `imports` 中使用 `lib.optionals` 来决定是否导入某个模块即可。 这种方式的主要好处是,它要比前面介绍的方法简单许多,不需要对模块内容做任何修改,只需要在 `imports` 中使用 `lib.optionals` 来决定是否导入某个模块即可。
> `lib.optionals` 函数的详细文档: <https://noogle.dev/f/lib/optionals>
直接看例子: 直接看例子:
```nix ```nix