-
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.
docs/src/getting_started/{first_modules,transfer_to_denix}: init
- Loading branch information
Showing
5 changed files
with
218 additions
and
0 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,85 @@ | ||
# First Modules {#first-modules} | ||
In this section, we will create modules for some programs. To start, create the `programs` and `services` subdirectories in the `modules` directory. | ||
|
||
Creating your own modules is almost the same as creating regular NixOS modules, so you can look for NixOS options [here](https://search.nixos.org/options?). | ||
|
||
## Git {#git} | ||
Let's assume you already have a constants module. Create a file `modules/programs/git.nix` with the following content: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.git"; | ||
options = with delib; { | ||
enable = boolOption true; | ||
enableLFS = boolOption true; | ||
}; | ||
home.ifEnabled.programs.git = {myconfig, cfg, ...}: { | ||
enable = cfg.enable; | ||
lfs.enable = cfg.enableLFS; | ||
userName = myconfig.constants.username; | ||
userEmail = myconfig.constants.useremail; | ||
}; | ||
} | ||
``` | ||
|
||
### Code Explanation: | ||
- `enable` - an option to enable or disable the module entirely. | ||
- `enableLFS` - an option to enable [Git Large File Storage](https://github.com/git-lfs/git-lfs). | ||
|
||
## Hyprland {#hyprland} | ||
Assume that your host has the options `type` and `isDesktop`. Create a subdirectory `hyprland` in the `modules/programs/` directory, and in it, create a file `default.nix` with the following content: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
options = {myconfig, ...} @ args: delib.singleEnableOption myconfig.host.isDesktop args; | ||
nixos.ifEnabled.programs.hyprland.enable = true; | ||
home.ifEnabled.wayland.windowManager.hyprland.enable = true; | ||
} | ||
``` | ||
|
||
Also, create a file `settings.nix` in this directory: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
home.ifEnabled.wayland.windowManager.hyprland.settings = { | ||
"$mod" = "SUPER"; | ||
general = { | ||
gaps_in = 5; | ||
gaps_out = 10; | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
And finally, the file `binds.nix`: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
home.ifEnabled.wayland.windowManager.hyprland.settings = { | ||
bindm = [ | ||
"$mod, mouse:272, movewindow" | ||
"$mod, mouse:273, resizewindow" | ||
]; | ||
bind = [ | ||
"$mod, q, killactive," | ||
"CTRLALT, Delete, exit," | ||
"$mod, Return, exec, kitty" # your terminal | ||
]; | ||
}; | ||
} | ||
``` | ||
|
||
We have created a small configuration for Hyprland, which you can expand and add new options to as needed. |
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,22 @@ | ||
# Transfer to Denix {#transfer-to-denix} | ||
If you already have a NixOS or Home Manager configuration, you can transfer most of the code without significant changes and then adapt it for Denix. | ||
|
||
However, you will need to create the following from scratch: | ||
- Hosts | ||
- Rices (if you want) | ||
- Some initial modules | ||
|
||
The main part of the configuration can be fully reused from your old setup. The key is to separate the hardware configuration from the general configuration. See the section [How Does It Work?](#how-it-works). | ||
|
||
## How Does It Work? {#how-it-works} | ||
All Denix modules are standard Home Manager or NixOS modules but with additional logic for enabling and disabling configurations. | ||
|
||
This means that you can add code or files from the old configuration into the new one, so they are imported through [`delib.configurations`](/configurations/introduction). You can place this code in the `modules` directory or create a new one, for example, `modules_nixos_old` for older configurations. | ||
|
||
## Example of a Simple Configuration {#example-of-simple-configuration} | ||
Suppose you have an old configuration consisting of two files: `configuration.nix` and `hardware-configuration.nix`, and you've already created hosts and the `modules/config` directory following the instructions. The configuration for your host should include `hardware-configuration.nix`, so all that remains is to copy `configuration.nix` into the `modules` directory and remove unnecessary options, like `system.stateVersion`. | ||
|
||
## Example of a Complex Configuration {#example-of-complex-configuration} | ||
Suppose you have an old configuration with hosts and multiple modules split across files. Hosts are typically specific to your system, so you will need to transfer them manually, usually by just copying the code. | ||
|
||
Modules (e.g., for programs and services) can simply be copied into the `modules` directory or other files imported via [`delib.configurations`](/configurations/introduction). |
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,85 @@ | ||
# Первые модули {#first-modules} | ||
В этом разделе мы создадим модули для некоторых программ. Для начала создайте поддиректории `programs` и `services` в директории `modules`. | ||
|
||
Создание своих модулей практически не отличается от создания обычных модулей NixOS, поэтому опции NixOS можно искать [здесь](https://search.nixos.org/options?). | ||
|
||
## Git {#git} | ||
Предположим, что у вас уже есть модуль констант. Создайте файл `modules/programs/git.nix` со следующим содержанием: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.git"; | ||
options = with delib; { | ||
enable = boolOption true; | ||
enableLFS = boolOption true; | ||
}; | ||
home.ifEnabled.programs.git = {myconfig, cfg, ...}: { | ||
enable = cfg.enable; | ||
lfs.enable = cfg.enableLFS; | ||
userName = myconfig.constants.username; | ||
userEmail = myconfig.constants.useremail; | ||
}; | ||
} | ||
``` | ||
|
||
### Объяснение кода: | ||
- `enable` - опция для включения и отключения модуля полностью. | ||
- `enableLFS` - опция для включения [Git Large File Storage](https://github.com/git-lfs/git-lfs). | ||
|
||
## Hyprland {#hyprland} | ||
Предположим, что в вашем хосте есть опции `type` и `isDesktop`. Создайте поддиректорию `hyprland` в директории `modules/programs/`, а в ней - файл `default.nix` со следующим содержанием: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
options = {myconfig, ...} @ args: delib.singleEnableOption myconfig.host.isDesktop args; | ||
nixos.ifEnabled.programs.hyprland.enable = true; | ||
home.ifEnabled.wayland.windowManager.hyprland.enable = true; | ||
} | ||
``` | ||
|
||
Также в этой директории создайте файл `settings.nix`: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
home.ifEnabled.wayland.windowManager.hyprland.settings = { | ||
"$mod" = "SUPER"; | ||
general = { | ||
gaps_in = 5; | ||
gaps_out = 10; | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
И последний файл `binds.nix`: | ||
```nix | ||
{delib, ...}: | ||
delib.module { | ||
name = "programs.hyprland"; | ||
home.ifEnabled.wayland.windowManager.hyprland.settings = { | ||
bindm = [ | ||
"$mod, mouse:272, movewindow" | ||
"$mod, mouse:273, resizewindow" | ||
]; | ||
bind = [ | ||
"$mod, q, killactive," | ||
"CTRLALT, Delete, exit," | ||
"$mod, Return, exec, kitty" # ваш терминал | ||
]; | ||
}; | ||
} | ||
``` | ||
|
||
Мы создали небольшую конфигурацию Hyprland, которую можно расширить и добавить новые опции. |
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,22 @@ | ||
# Перенос на Denix {#transfer-to-denix} | ||
Если у вас уже есть конфигурация NixOS или Home Manager, вы можете перенести большинство кода без значительных изменений, а затем адаптировать его под Denix. | ||
|
||
Однако, вам потребуется создать с нуля: | ||
- Хосты | ||
- Райсы (если хотите) | ||
- Некоторые начальные модули | ||
|
||
Основную часть конфигурации можно полностью использовать из вашей старой конфигурации, главное - отделить аппаратные настройки (hardware configuration) от общей конфигурации. См. раздел [Как это работает?](#how-it-works). | ||
|
||
## Как это работает? {#how-it-works} | ||
Все модули Denix представляют собой обычные модули Home Manager или NixOS, но с дополнительной логикой включения и выключения конфигураций. | ||
|
||
Это означает, что вы можете добавить код или файлы из старой конфигурации в новую, чтобы они импортировались через [`delib.configurations`](/ru/configurations/introduction). Вы можете положить этот код в директорию `modules` или создать новую директорию, например, `modules_nixos_old` для старых конфигураций. | ||
|
||
## Пример простой конфигурации {#example-of-simple-configuration} | ||
Допустим, у вас есть старая конфигурация, состоящая из двух файлов: `configuration.nix` и `hardware-configuration.nix`, и вы уже создали хосты и директорию `modules/config` по инструкции. Конфигурация вашего хоста должна включать `hardware-configuration.nix`, поэтому остаётся лишь скопировать `configuration.nix` в директорию `modules` и удалить из неё ненужные опции, например, `system.stateVersion`. | ||
|
||
## Пример сложной конфигурации {#example-of-complex-configuration} | ||
Допустим, у вас есть старая конфигурация с хостами и множеством модулей, разделённых на файлы. Хосты, как правило, специфичны для вашей системы, поэтому их нужно будет перенести вручную, чаще всего просто скопировав код. | ||
|
||
Модули (например, для программ и сервисов) можно просто скопировать в директорию `modules` или другие файлы, импортируемые через [`delib.configurations`](/ru/configurations/introduction). |