fix: optional imports

This commit is contained in:
Ryan Yin 2024-03-08 14:28:05 +08:00
parent f3145b8143
commit 95e7833e71
2 changed files with 8 additions and 6 deletions

View File

@ -317,9 +317,10 @@ Let's look at an example directly:
({config, lib, enableFoo ? false, ...}: {
imports =
[
# Use lib.optionals to decide whether to import foo.nix
(lib.optionals (enableFoo) ./foo.nix)
];
# Other Modules
]
# Use lib.optionals to decide whether to import foo.nix
++ (lib.optionals (enableFoo) [./foo.nix]);
})
];
};

View File

@ -328,9 +328,10 @@ Nixpkgs 中的模块系统提供了一系列类似 `lib.mkIf` 的函数,用于
({config, lib, enableFoo ? false, ...}: {
imports =
[
# 通过 lib.optionals 来决定是否导入 foo.nix
(lib.optionals (enableFoo) ./foo.nix)
];
# 这里写其他模块
]
# 通过 lib.optionals 来决定是否foo.nix
++ (lib.optionals (enableFoo) [./foo.nix]);
})
];
};