mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-06-22 13:01:25 +02:00
fix: optional imports
This commit is contained in:
parent
f3145b8143
commit
95e7833e71
@ -317,9 +317,10 @@ Let's look at an example directly:
|
|||||||
({config, lib, enableFoo ? false, ...}: {
|
({config, lib, enableFoo ? false, ...}: {
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
|
# Other Modules
|
||||||
|
]
|
||||||
# Use lib.optionals to decide whether to import foo.nix
|
# Use lib.optionals to decide whether to import foo.nix
|
||||||
(lib.optionals (enableFoo) ./foo.nix)
|
++ (lib.optionals (enableFoo) [./foo.nix]);
|
||||||
];
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -328,9 +328,10 @@ Nixpkgs 中的模块系统提供了一系列类似 `lib.mkIf` 的函数,用于
|
|||||||
({config, lib, enableFoo ? false, ...}: {
|
({config, lib, enableFoo ? false, ...}: {
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
# 通过 lib.optionals 来决定是否导入 foo.nix
|
# 这里写其他模块
|
||||||
(lib.optionals (enableFoo) ./foo.nix)
|
]
|
||||||
];
|
# 通过 lib.optionals 来决定是否foo.nix
|
||||||
|
++ (lib.optionals (enableFoo) [./foo.nix]);
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user