-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Introduction to Denix Configurations (Flakes) {#introduction} | ||
The `delib.configurations` function is used to create lists of `nixosConfigurations` and `homeConfigurations` for flakes. | ||
|
||
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: | ||
|
||
```sh | ||
nixos-rebuild switch --flake .#desktop --use-remote-sudo | ||
``` | ||
|
||
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: | ||
|
||
```sh | ||
nixos-rebuild switch --flake .#desktop-dark --use-remote-sudo | ||
``` | ||
|
||
In this case, the host remains "desktop", but the rice changes to "dark". | ||
|
||
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. | ||
|
||
## Principle of Configuration List Generation {#principle} | ||
The configuration list is generated based on the following principle: | ||
|
||
- `{hostName}` - where `hostName` is the name of any host. | ||
- `{hostName}-{riceName}` - where `hostName` is the name of any host, and `riceName` is the name of any rice where `inheritanceOnly` is `false`. | ||
|
||
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. | ||
|
||
## Example {#example} | ||
An example of a flake's `outputs` for `nixosConfigurations` and `homeConfigurations`: | ||
|
||
```nix | ||
outputs = {denix, nixpkgs, ...} @ inputs: let | ||
mkConfigurations = isHomeManager: | ||
denix.lib.configurations rec { | ||
homeManagerNixpkgs = nixpkgs; | ||
homeManagerUser = "sjohn"; | ||
inherit isHomeManager; | ||
paths = [./hosts ./modules ./rices]; | ||
specialArgs = { | ||
inherit inputs isHomeManager homeManagerUser; | ||
}; | ||
}; | ||
in { | ||
nixosConfigurations = mkConfigurations false; | ||
homeConfigurations = mkConfigurations true; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Structure {#structure} | ||
|
||
## Function Arguments {#function-arguments} | ||
- `myconfigName` (string): the category for all Denix module options, hosts, and rices. Default is `myconfig`; changes are not recommended. | ||
- `denixLibName` (string): the name of the Denix library in `specialArgs` (`{denixLibName, ...}: denixLibName.module { ... }`). Default is `delib`; changes are not recommended. | ||
- `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. | ||
- `homeManagerUser` (string): the username, used in `home-manager.users.${homeManagerUser}` and for generating the Home Manager configuration list. | ||
- `isHomeManager` (boolean): indicates whether to create a configuration list for Home Manager or for NixOS. | ||
- `paths` (listOf string): paths to be imported; add hosts, rices, and modules here. Default is `[]`. | ||
- `exclude` (listOf string): paths to be excluded from importing. Default is `[]`. | ||
- `recursive` (boolean): determines whether to recursively search for paths to import. Default is `true`. | ||
- `specialArgs` (attrset): `specialArgs` to be passed to `lib.nixosSystem` and `home-manager.lib.homeManagerConfiguration`. Default is `{}`. | ||
- **EXPERIMENTAL** `extraModules` (list): default is `[]`. | ||
- **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";}`. | ||
|
||
## Pseudocode {#pseudocode} | ||
```nix | ||
delib.configurations { | ||
myconfigName = "myconfig"; | ||
denixLibName = "delib"; | ||
homeManagerNixpkgs = inputs.nixpkgs; | ||
homeManagerUser = ""; | ||
isHomeManager = true; | ||
paths = [./modules ./hosts ./rices]; | ||
exclude = [./modules/deprecated]; | ||
recursive = true; | ||
specialArgs = { | ||
inherit inputs; | ||
isHomeManager = true; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Введение в конфигурации Denix (флейки) {#introduction} | ||
Функция `delib.configurations` используется для создания списков `nixosConfigurations` и `homeConfigurations` для флейков. | ||
|
||
Помимо всех хостов, она также добавляет комбинации каждого хоста с каждым **не `inheritanceOnly`** райсом, что позволяет быстро переключаться между райсами без редактирования кода. Например, если у хоста "desktop" задан райс "light", то при выполнении следующей команды: | ||
|
||
```sh | ||
nixos-rebuild switch --flake .#desktop --use-remote-sudo | ||
``` | ||
|
||
будет использован хост "desktop" с райсом "light". Однако, если необходимо быстро переключиться на другой райс, например, на "dark", можно выполнить следующую команду: | ||
|
||
```sh | ||
nixos-rebuild switch --flake .#desktop-dark --use-remote-sudo | ||
``` | ||
|
||
В этом случае хост останется "desktop", но райс изменится на "dark". | ||
|
||
Важно отметить, что при смене райса таким образом меняется только значение опции `${myConfigName}.rice`, при этом значение `${myconfigName}.hosts.${hostName}.rice` остаётся прежним. | ||
|
||
## Принцип генерации списка конфигураций {#principle} | ||
Список конфигураций генерируется по следующему принципу: | ||
|
||
- `{hostName}` - где `hostName` - имя любого хоста. | ||
- `{hostName}-{riceName}` - где `hostName` - имя любого хоста, а `riceName` - имя любого райса, у которого `inheritanceOnly` равно `false`. | ||
|
||
Если `isHomeManager` из [аргументов функции](/ru/configurations/structure#function-arguments) равен `true`, то ко всем конфигурациям в списке добавляется префикс` {homeManagerUser}@`. | ||
|
||
## Пример {#example} | ||
Пример `outputs` флейка для `nixosConfigurations` и `homeConfigurations`: | ||
|
||
```nix | ||
outputs = {denix, nixpkgs, ...} @ inputs: let | ||
mkConfigurations = isHomeManager: | ||
denix.lib.configurations rec { | ||
homeManagerNixpkgs = nixpkgs; | ||
homeManagerUser = "sjohn"; | ||
inherit isHomeManager; | ||
paths = [./hosts ./modules ./rices]; | ||
specialArgs = { | ||
inherit inputs isHomeManager homeManagerUser; | ||
}; | ||
}; | ||
in { | ||
nixosConfigurations = mkConfigurations false; | ||
homeConfigurations = mkConfigurations true; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Структура {#structure} | ||
|
||
## Аргументы функции {#function-arguments} | ||
- `myconfigName` (string): категория для всех опций модулей Denix, хостов и райсов. По умолчанию `myconfig`; изменять не рекомендуется. | ||
- `denixLibName` (string): имя библиотеки Denix в `specialArgs` (`{denixLibName, ...}: denixLibName.module { ... }`). По умолчанию `delib`; изменять не рекомендуется. | ||
- `homeManagerNixpkgs` (nixpkgs): используется в атрибуте `pkgs` функции `home-manager.lib.homeManagerConfiguration` в формате: `homeManagerNixpkgs.legacyPackages.${host :: homeManagerSystem}`. По умолчанию берется `nixpkgs` из флейка. | ||
- `homeManagerUser` (string): имя пользователя, используется в `home-manager.users.${homeManagerUser}` и для генерации списка конфигураций Home Manager. | ||
- `isHomeManager` (boolean): указывает, создавать ли список конфигураций для Home Manager или для NixOS. | ||
- `paths` (listOf string): пути, которые будут импортированы; добавьте сюда хосты, райсы и модули. По умолчанию `[]`. | ||
- `exclude` (listOf string): пути, которые будут исключены из импортирования. По умолчанию `[]`. | ||
- `recursive` (boolean): определяет, следует ли рекурсивно искать пути для импортирования. По умолчанию `true`. | ||
- `specialArgs` (attrset): `specialArgs`, которые будут переданы в `lib.nixosSystem` и `home-manager.lib.homeManagerConfiguration`. По умолчанию `{}`. | ||
- **EXPERIMENTAL** `extraModules` (list): по умолчанию `[]`. | ||
- **EXPERIMENTAL** `mkConfigurationsSystemExtraModule` (attrset): модуль, используемый во внутренней конфигурации NixOS, который получает список хостов и райсов для генерации списка конфигураций. По умолчанию `{nixpkgs.hostPlatform = "x86_64-linux";}`. | ||
|
||
## Псевдокод {#pseudocode} | ||
```nix | ||
delib.configurations { | ||
myconfigName = "myconfig"; | ||
denixLibName = "delib"; | ||
homeManagerNixpkgs = inputs.nixpkgs; | ||
homeManagerUser = ""; | ||
isHomeManager = true; | ||
paths = [./modules ./hosts ./rices]; | ||
exclude = [./modules/deprecated]; | ||
recursive = true; | ||
specialArgs = { | ||
inherit inputs; | ||
isHomeManager = true; | ||
}; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters