Skip to content

Commit 6c3fc4e

Browse files
committed
fix: typo, add missing Chinese translation
1 parent 2b48838 commit 6c3fc4e

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

docs/en/nixos-with-flakes/modularize-the-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ and `special-fonts-2.nix`. Both files are modules themselves and look similar to
8282

8383
```nix
8484
{ config, pkgs, ...}: {
85-
# Configuration stuff ...
85+
# Configuration stuff ...
8686
}
8787
```
8888

8989
Both import statements above are equivalent in the parameters they receive:
9090

9191
- Statement `(1)` imports the function in `special-fonts-1.nix` and calls it by passing
9292
`{config = config; pkgs = pkgs}`. Basically using the return value of the call (another
93-
partial configuration [attritbute set]) inside the `imports` list.
93+
partial configuration _attribute set_) inside the `imports` list.
9494

9595
- Statement `(2)` defines a path to a module, whose function Nix will load _automatically_
9696
when assembling the configuration `config`. It will pass all matching arguments from the

docs/en/other-usage-of-flakes/the-new-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ hello: command not found
2323
› hello
2424
Hello, world!
2525

26-
# ponysay is also available
26+
# cowsay is also available
2727
› cowsay "Hello, world!"
2828
_______
2929
< hello >

docs/zh/nixos-with-flakes/modularize-the-configuration.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,42 @@ set 也能被正确合并,具体行为各位看官可以自行探索。
4646
> 中找到一句关于 `imports`
4747
> 的描述:`A list of modules. These are merged together to form the final configuration.`,可以意会一下...(Nix 的文档真的一言难尽...这么核心的参数文档就这么一句...)
4848
49-
我们可以借助 `imports` 参数,将 `home.nix``configuration.nix` 拆分成多个 `.nix` 文件。
49+
借助 `imports`,我们可以把 `home.nix``configuration.nix` 拆成多个分散在不同 `.nix`
50+
文件里的 Nix 模块。先来看一个示例模块 `packages.nix`
51+
52+
```nix
53+
{
54+
config,
55+
pkgs,
56+
...
57+
}: {
58+
imports = [
59+
(import ./special-fonts-1.nix {inherit config pkgs;}) # (1)
60+
./special-fonts-2.nix # (2)
61+
];
62+
63+
fontconfig.enable = true;
64+
}
65+
```
66+
67+
这个模块在 `imports` 里加载了另外两个模块:`special-fonts-1.nix`
68+
`special-fonts-2.nix`。这两个文件本身也是模块,写法大致如下:
69+
70+
```nix
71+
{ config, pkgs, ... }: {
72+
# Configuration stuff ...
73+
}
74+
```
75+
76+
上面两条 import 语句在传入参数这件事上是等价的:
77+
78+
- 语句 `(1)``special-fonts-1.nix` 里的函数导入并立即调用,显式传入
79+
`{ config = config; pkgs = pkgs;}`。返回值(一个 _attribute set_)被放进 `imports`
80+
列表。
81+
82+
- 语句 `(2)` 只给出模块路径。Nix 在拼装最终 `config` 时会**自动**加载该文件,并把
83+
`packages.nix` 函数头里已有的同名参数自动传进去,效果等同于
84+
`import ./special-fonts-2.nix { config = config; pkgs = pkgs; }`
5085

5186
推荐一个非常好的模块化配置的例子,可以参考一下:
5287

0 commit comments

Comments
 (0)