Skip to content

Commit e683133

Browse files
committed
docs/src/configurations: init
1 parent 60318ef commit e683133

File tree

11 files changed

+184
-9
lines changed

11 files changed

+184
-9
lines changed

Diff for: docs/.vitepress/config.mts

+17-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ function themeConfigEnglish() {return {
7373
{ text: "Examples", link: "/hosts/examples" }
7474
],
7575
},
76+
{
77+
text: "Configurations (flakes)",
78+
items: [
79+
{ text: "Introduction", link: "/configurations/introduction" },
80+
{ text: "Structure", link: "/configurations/structure" }
81+
],
82+
},
7683
{
7784
text: "Rices",
7885
items: [
@@ -115,7 +122,7 @@ function themeConfigRussian() {return {
115122
{ text: "Вступление в модули NixOS", link: "/ru/modules/introduction-nixos" },
116123
{ text: "Вступление", link: "/ru/modules/introduction" },
117124
{ text: "Структура", link: "/ru/modules/structure" },
118-
{ text: "Примеры", link: "/ru/modules/examples" }
125+
{ text: "Примеры", link: "/ru/modules/examples" },
119126
],
120127
},
121128
{
@@ -129,15 +136,22 @@ function themeConfigRussian() {return {
129136
items: [
130137
{ text: "Вступление", link: "/ru/hosts/introduction" },
131138
{ text: "Структура", link: "/ru/hosts/structure" },
132-
{ text: "Примеры", link: "/ru/hosts/examples" }
139+
{ text: "Примеры", link: "/ru/hosts/examples" },
140+
],
141+
},
142+
{
143+
text: "Конфигурации (флейки)",
144+
items: [
145+
{ text: "Вступление", link: "/ru/configurations/introduction" },
146+
{ text: "Структура", link: "/ru/configurations/structure" },
133147
],
134148
},
135149
{
136150
text: "Райсы",
137151
items: [
138152
{ text: "Вступление", link: "/ru/rices/introduction" },
139153
{ text: "Структура", link: "/ru/rices/structure" },
140-
{ text: "Примеры", link: "/ru/rices/examples" }
154+
{ text: "Примеры", link: "/ru/rices/examples" },
141155
],
142156
},
143157
{ text: "Реальные конфигурации", link: "/real-configurations" },

Diff for: docs/src/configurations/introduction.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Introduction to Denix Configurations (Flakes) {#introduction}
2+
The `delib.configurations` function is used to create lists of `nixosConfigurations` and `homeConfigurations` for flakes.
3+
4+
In addition to all hosts, it also adds combinations of each host with every **non-`inheritanceOnly`** rice, which allows for quickly switching between rice configurations without editing the code. For example, if the "desktop" host is set to use the "light" rice, executing the following command:
5+
6+
```sh
7+
nixos-rebuild switch --flake .#desktop --use-remote-sudo
8+
```
9+
10+
will use the "desktop" host with the "light" rice. However, if you need to quickly switch to another rice, for example, "dark" you can run the following command:
11+
12+
```sh
13+
nixos-rebuild switch --flake .#desktop-dark --use-remote-sudo
14+
```
15+
16+
In this case, the host remains "desktop", but the rice changes to "dark".
17+
18+
It is important to note that when switching rice in this way, only the value of the `${myConfigName}.rice` option changes, while the value of `${myConfigName}.hosts.${hostName}.rice` remains the same.
19+
20+
## Principle of Configuration List Generation {#principle}
21+
The configuration list is generated based on the following principle:
22+
23+
- `{hostName}` - where `hostName` is the name of any host.
24+
- `{hostName}-{riceName}` - where `hostName` is the name of any host, and `riceName` is the name of any rice where `inheritanceOnly` is `false`.
25+
26+
If `isHomeManager` from the [function arguments](/configurations/structure#function-arguments) is equal to `true`, then a prefix of `{homeManagerUser}@` is added to all configurations in the list.
27+
28+
## Example {#example}
29+
An example of a flake's `outputs` for `nixosConfigurations` and `homeConfigurations`:
30+
31+
```nix
32+
outputs = {denix, nixpkgs, ...} @ inputs: let
33+
mkConfigurations = isHomeManager:
34+
denix.lib.configurations rec {
35+
homeManagerNixpkgs = nixpkgs;
36+
homeManagerUser = "sjohn";
37+
inherit isHomeManager;
38+
39+
paths = [./hosts ./modules ./rices];
40+
41+
specialArgs = {
42+
inherit inputs isHomeManager homeManagerUser;
43+
};
44+
};
45+
in {
46+
nixosConfigurations = mkConfigurations false;
47+
homeConfigurations = mkConfigurations true;
48+
}
49+
```

Diff for: docs/src/configurations/structure.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Structure {#structure}
2+
3+
## Function Arguments {#function-arguments}
4+
- `myconfigName` (string): the category for all Denix module options, hosts, and rices. Default is `myconfig`; changes are not recommended.
5+
- `denixLibName` (string): the name of the Denix library in `specialArgs` (`{denixLibName, ...}: denixLibName.module { ... }`). Default is `delib`; changes are not recommended.
6+
- `homeManagerNixpkgs` (nixpkgs): used in the `pkgs` attribute of the `home-manager.lib.homeManagerConfiguration` function in the format: `homeManagerNixpkgs.legacyPackages.${host :: homeManagerSystem}`. By default, it takes `nixpkgs` from the flake.
7+
- `homeManagerUser` (string): the username, used in `home-manager.users.${homeManagerUser}` and for generating the Home Manager configuration list.
8+
- `isHomeManager` (boolean): indicates whether to create a configuration list for Home Manager or for NixOS.
9+
- `paths` (listOf string): paths to be imported; add hosts, rices, and modules here. Default is `[]`.
10+
- `exclude` (listOf string): paths to be excluded from importing. Default is `[]`.
11+
- `recursive` (boolean): determines whether to recursively search for paths to import. Default is `true`.
12+
- `specialArgs` (attrset): `specialArgs` to be passed to `lib.nixosSystem` and `home-manager.lib.homeManagerConfiguration`. Default is `{}`.
13+
- **EXPERIMENTAL** `extraModules` (list): default is `[]`.
14+
- **EXPERIMENTAL** `mkConfigurationsSystemExtraModule` (attrset): a module used in the internal NixOS configuration that receives the list of hosts and rices to generate the configuration list. Default is `{nixpkgs.hostPlatform = "x86_64-linux";}`.
15+
16+
## Pseudocode {#pseudocode}
17+
```nix
18+
delib.configurations {
19+
myconfigName = "myconfig";
20+
denixLibName = "delib";
21+
homeManagerNixpkgs = inputs.nixpkgs;
22+
homeManagerUser = "";
23+
isHomeManager = true;
24+
paths = [./modules ./hosts ./rices];
25+
exclude = [./modules/deprecated];
26+
recursive = true;
27+
specialArgs = {
28+
inherit inputs;
29+
isHomeManager = true;
30+
};
31+
}

Diff for: docs/src/modules/structure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Structure {#structure}
2-
This section uses the variables `myconfigName`, `isHomeManager`, and `homeManagerUser`, so it's recommended to first review the corresponding subsection: [delib.system Function Arguments](/TODO).
2+
This section uses the variables `myconfigName`, `isHomeManager`, and `homeManagerUser`, so it's recommended to first review the corresponding subsection: [delib.configurations Function Arguments](/configurations/structure#function-arguments).
33

44
## Function Arguments {#function-arguments}
55
- `name`{#function-arguments-name}: string. It is recommended that it matches the parent path of the module's `enable` option, such as `"programs.example"`, since the `cfg` argument depends on this path.

Diff for: docs/src/rices/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The term "rice" in slang refers to system settings, usually related to appearanc
66
However, rices are not mandatory: to avoid using them, simply do not add the options `${myconfigName}.rices` and `${myconfigName}.rice`, and do not use the `delib.rice` function.
77

88
## Inheritance {#inheritance}
9-
A rice can inherit all configurations of another rice via the `inherits` attribute. Additionally, you can set `inheritanceOnly = true;`, which will hide the rice from being generated in [`delib.system`](/TODO), leaving it only for inheritance.
9+
A rice can inherit all configurations of another rice via the `inherits` attribute. Additionally, you can set `inheritanceOnly = true;`, which will hide the rice from being generated in [`delib.configurations`](/configurations/introduction), leaving it only for inheritance.
1010

1111
Example of three rices, where the first two inherit all configurations from the "rounded" rice:
1212

Diff for: docs/src/rices/structure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Function Arguments {#function-arguments}
44
- `name`: a string representing the rice name.
55
- `inherits`: a list of strings - the names of rices whose configurations will be inherited by the current rice.
6-
- `inheritanceOnly`: a boolean value that determines whether this rice will be added to the [list of systems generated for each host and rice](/TODO), or if it is only used for inheritance.
6+
- `inheritanceOnly`: a boolean value that determines whether this rice will be added to the [list of systems generated for each host and rice](/configurations/introduction), or if it is only used for inheritance.
77
- `myconfig`: sets its value to `config.${myconfigName}` if `config.${myconfigName}.rice` matches the current rice.
88
- `nixos`: sets its value to `config` if `isHomeManager` is `false` and `config.${myconfigName}.rice` matches the current rice.
99
- `home`: sets its value to `config` if `isHomeManager` is `true` and `config.${myconfigName}.rice` matches the current rice. Otherwise, if `config.${myconfigName}.rice` matches the current rice, sets its value to `config.home-manager.users.${homeManagerUser}`.

Diff for: docs/src/ru/configurations/introduction.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Введение в конфигурации Denix (флейки) {#introduction}
2+
Функция `delib.configurations` используется для создания списков `nixosConfigurations` и `homeConfigurations` для флейков.
3+
4+
Помимо всех хостов, она также добавляет комбинации каждого хоста с каждым **не `inheritanceOnly`** райсом, что позволяет быстро переключаться между райсами без редактирования кода. Например, если у хоста "desktop" задан райс "light", то при выполнении следующей команды:
5+
6+
```sh
7+
nixos-rebuild switch --flake .#desktop --use-remote-sudo
8+
```
9+
10+
будет использован хост "desktop" с райсом "light". Однако, если необходимо быстро переключиться на другой райс, например, на "dark", можно выполнить следующую команду:
11+
12+
```sh
13+
nixos-rebuild switch --flake .#desktop-dark --use-remote-sudo
14+
```
15+
16+
В этом случае хост останется "desktop", но райс изменится на "dark".
17+
18+
Важно отметить, что при смене райса таким образом меняется только значение опции `${myConfigName}.rice`, при этом значение `${myconfigName}.hosts.${hostName}.rice` остаётся прежним.
19+
20+
## Принцип генерации списка конфигураций {#principle}
21+
Список конфигураций генерируется по следующему принципу:
22+
23+
- `{hostName}` - где `hostName` - имя любого хоста.
24+
- `{hostName}-{riceName}` - где `hostName` - имя любого хоста, а `riceName` - имя любого райса, у которого `inheritanceOnly` равно `false`.
25+
26+
Если `isHomeManager` из [аргументов функции](/ru/configurations/structure#function-arguments) равен `true`, то ко всем конфигурациям в списке добавляется префикс` {homeManagerUser}@`.
27+
28+
## Пример {#example}
29+
Пример `outputs` флейка для `nixosConfigurations` и `homeConfigurations`:
30+
31+
```nix
32+
outputs = {denix, nixpkgs, ...} @ inputs: let
33+
mkConfigurations = isHomeManager:
34+
denix.lib.configurations rec {
35+
homeManagerNixpkgs = nixpkgs;
36+
homeManagerUser = "sjohn";
37+
inherit isHomeManager;
38+
39+
paths = [./hosts ./modules ./rices];
40+
41+
specialArgs = {
42+
inherit inputs isHomeManager homeManagerUser;
43+
};
44+
};
45+
in {
46+
nixosConfigurations = mkConfigurations false;
47+
homeConfigurations = mkConfigurations true;
48+
}
49+
```

Diff for: docs/src/ru/configurations/structure.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Структура {#structure}
2+
3+
## Аргументы функции {#function-arguments}
4+
- `myconfigName` (string): категория для всех опций модулей Denix, хостов и райсов. По умолчанию `myconfig`; изменять не рекомендуется.
5+
- `denixLibName` (string): имя библиотеки Denix в `specialArgs` (`{denixLibName, ...}: denixLibName.module { ... }`). По умолчанию `delib`; изменять не рекомендуется.
6+
- `homeManagerNixpkgs` (nixpkgs): используется в атрибуте `pkgs` функции `home-manager.lib.homeManagerConfiguration` в формате: `homeManagerNixpkgs.legacyPackages.${host :: homeManagerSystem}`. По умолчанию берется `nixpkgs` из флейка.
7+
- `homeManagerUser` (string): имя пользователя, используется в `home-manager.users.${homeManagerUser}` и для генерации списка конфигураций Home Manager.
8+
- `isHomeManager` (boolean): указывает, создавать ли список конфигураций для Home Manager или для NixOS.
9+
- `paths` (listOf string): пути, которые будут импортированы; добавьте сюда хосты, райсы и модули. По умолчанию `[]`.
10+
- `exclude` (listOf string): пути, которые будут исключены из импортирования. По умолчанию `[]`.
11+
- `recursive` (boolean): определяет, следует ли рекурсивно искать пути для импортирования. По умолчанию `true`.
12+
- `specialArgs` (attrset): `specialArgs`, которые будут переданы в `lib.nixosSystem` и `home-manager.lib.homeManagerConfiguration`. По умолчанию `{}`.
13+
- **EXPERIMENTAL** `extraModules` (list): по умолчанию `[]`.
14+
- **EXPERIMENTAL** `mkConfigurationsSystemExtraModule` (attrset): модуль, используемый во внутренней конфигурации NixOS, который получает список хостов и райсов для генерации списка конфигураций. По умолчанию `{nixpkgs.hostPlatform = "x86_64-linux";}`.
15+
16+
## Псевдокод {#pseudocode}
17+
```nix
18+
delib.configurations {
19+
myconfigName = "myconfig";
20+
denixLibName = "delib";
21+
homeManagerNixpkgs = inputs.nixpkgs;
22+
homeManagerUser = "";
23+
isHomeManager = true;
24+
paths = [./modules ./hosts ./rices];
25+
exclude = [./modules/deprecated];
26+
recursive = true;
27+
specialArgs = {
28+
inherit inputs;
29+
isHomeManager = true;
30+
};
31+
}
32+
```

Diff for: docs/src/ru/modules/structure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Структура {#structure}
2-
В этом разделе будут использованы переменные `myconfigName`, `isHomeManager` и `homeManagerUser`, поэтому рекомендуется предварительно ознакомиться с соответствующим подразделом: [Аргументы delib.system](/TODO).
2+
В этом разделе будут использованы переменные `myconfigName`, `isHomeManager` и `homeManagerUser`, поэтому рекомендуется предварительно ознакомиться с соответствующим подразделом: [Аргументы delib.configurations](/ru/configurations/structure#function-arguments).
33

44
## Аргументы функции {#function-arguments}
55
- `name`{#function-arguments-name}: строка. Рекомендуется, чтобы она совпадала с родительским путём опции `enable` модуля, например, `"programs.example"`, так как передаваемый аргумент `cfg` зависит именно от этого пути.

Diff for: docs/src/ru/rices/introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
При этом райсы не являются обязательными - если вы не хотите их использовать, просто не добавляйте опции `${myconfigName}.rices` и `${myconfigName}.rice`, а также не вызывайте функцию `delib.rice`.
77

88
## Наследование {#inheritance}
9-
Райс может наследовать все конфигурации другого райса через атрибут `inherits`. Кроме того, можно установить `inheritanceOnly = true;`, чтобы скрыть райс от генерации в [`delib.system`](/TODO), оставив его только для наследования.
9+
Райс может наследовать все конфигурации другого райса через атрибут `inherits`. Кроме того, можно установить `inheritanceOnly = true;`, чтобы скрыть райс от генерации в [`delib.configurations`](/ru/configurations/introduction), оставив его только для наследования.
1010

1111
Пример трех райсов, где первые два наследуют все конфигурации райса "rounded":
1212

Diff for: docs/src/ru/rices/structure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Аргументы функции {#function-arguments}
44
- `name`: строка, представляющая имя райса.
55
- `inherits`: список строк - имена райсов, чьи конфигурации будут унаследованы текущим райсом.
6-
- `inheritanceOnly`: булевое значение (`true` или `false`), которое определяет, будет ли этот райс добавлен в [список систем, сгенерированный для каждого хоста и райса](/TODO), или же он используется только для наследования.
6+
- `inheritanceOnly`: булевое значение (`true` или `false`), которое определяет, будет ли этот райс добавлен в [список систем, сгенерированный для каждого хоста и райса](/ru/configurations/introduction), или же он используется только для наследования.
77
- `myconfig`: устанавливает её значение в `config.${myconfigName}`, если `config.${myconfigName}.rice` соответствует текущему райсу.
88
- `nixos`: устанавливает её значение в `config`, если `isHomeManager` равен `false` и `config.${myconfigName}.rice` соответствует текущему райсу.
99
- `home`: устанавливает её значение в `config`, если `isHomeManager` равен `true` и `config.${myconfigName}.rice` соответствует текущему райсу. В противном случае, если `config.${myconfigName}.rice` соответствует текущему райсу, устанавливает её значение в `config.home-manager.users.${homeManagerUser}`.

0 commit comments

Comments
 (0)