Skip to content

Commit 4366581

Browse files
authored
Merge pull request #58 from mzonski/feat/overlay-extension
lib/extensions: add overlay module
2 parents 02725fe + 340ec39 commit 4366581

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

docs/src/extensions/all-extensions.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,42 @@ This section describes all official Denix extensions.
135135

136136
## User {#user}
137137
WIP
138+
139+
## Overlays {#overlays}
140+
<table class="extension-table">
141+
<tbody>
142+
<tr>
143+
<th>Name</th>
144+
<td><code>overlays</code></td>
145+
</tr>
146+
<tr>
147+
<th>Description</th>
148+
<td>Simplified overlay configuration module</td>
149+
</tr>
150+
<tr>
151+
<th>Maintainers</th>
152+
<td>Zonni (<a href='https://github.com/mzonski'>GitHub</a>)</td>
153+
</tr>
154+
</tbody>
155+
</table>
156+
157+
### Settings {#overlays-settings}
158+
| Name | Default Value | Description |
159+
| - | - | - |
160+
| `defaultTargets` | `["nixos" "home"]` | Default targets to apply overlays |
161+
| `moduleNamePrefix` | `"overlays"` | Prefix added to module names when `withPrefix` is true |
162+
163+
### Library {#overlays-library}
164+
165+
#### `overlayModule` {#overlays-library-overlayModule}
166+
Creates a module that applies overlays for specified targets. If `withPrefix` is true, it creates the option `${moduleNamePrefix}.${name}.enable` with the value `delib.overlayModule :: enabled`; otherwise, it does the same but in `${name}.enable`.
167+
168+
**Arguments:**
169+
| Name | Type | Default Value | Description |
170+
| - | - | - | - |
171+
| `name` | string | *required* | Name of the overlay module |
172+
| `overlay` | overlay function | `null` | Single overlay function to apply |
173+
| `overlays` | list of overlay functions | `[]` | List of overlay functions to apply |
174+
| `targets` | list of strings | [`defaultTargets`](#overlays-settings) | Target systems to apply overlays to. Valid values: `"nixos"`, `"home"`, `"darwin"` |
175+
| `withPrefix` | boolean | `true` | Whether to add `moduleNamePrefix` to the module name |
176+
| `enabled` | boolean | `true` | Whether overlay should be enabled by default |

docs/src/ru/extensions/all-extensions.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,42 @@
135135

136136
## User {#user}
137137
WIP
138+
139+
## Overlays {#overlays}
140+
<table class="extension-table">
141+
<tbody>
142+
<tr>
143+
<th>Имя</th>
144+
<td><code>overlays</code></td>
145+
</tr>
146+
<tr>
147+
<th>Описание</th>
148+
<td>Модуль упрощённой конфигурация оверлеев</td>
149+
</tr>
150+
<tr>
151+
<th>Ответственные</th>
152+
<td>Zonni (<a href='https://github.com/mzonski'>GitHub</a>)</td>
153+
</tr>
154+
</tbody>
155+
</table>
156+
157+
### Настройки {#overlays-settings}
158+
| Имя | Значение по умолчанию | Описание |
159+
| - | - | - |
160+
| `defaultTargets` | `["nixos" "home"]` | Цели по умолчанию, к которым будут применяться оверлеи |
161+
| `moduleNamePrefix` | `"overlays"` | Префикс, добавляемый к именам модулей, когда `withPrefix` равняется true |
162+
163+
### Библиотека {#overlays-library}
164+
165+
#### `overlayModule` {#overlays-library-overlayModule}
166+
Создаёт модуль, который применяет оверлеи к указанным целям. Если `withPrefix` равен true, создаётся опция `${moduleNamePrefix}.${name}.enable` со значением `delib.overlayModule :: enabled`; в противном случае то же самое создаётся в `${name}.enable`.
167+
168+
**Аргументы:**
169+
| Имя | Тип | Значение по умолчанию | Описание |
170+
| - | - | - | - |
171+
| `name` | string | *обязательный* | Имя модуля этого оверлея |
172+
| `overlay` | overlay function | `null` | Применяемый оверлей |
173+
| `overlays` | list of overlay functions | `[]` | Список применяемых оверлеев |
174+
| `targets` | list of strings | [`defaultTargets`](#overlays-settings) | Целевые системы, к которым будут применены оверлеи. Разрешённые значения: `"nixos"`, `"home"`, `"darwin"` |
175+
| `withPrefix` | boolean | `true` | Добавлять ли `moduleNamePrefix` перед именем модуля этого оверлея |
176+
| `enabled` | boolean | `true` | Включать ли этот оверлей по умолчанию |

lib/extensions/overlays.nix

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{ lib, delib, ... }:
2+
let
3+
inherit (delib) extension singleEnableOption maintainers;
4+
inherit (lib) elem mkIf optional;
5+
in
6+
extension {
7+
name = "overlays";
8+
description = "Simplified overlay configuration module";
9+
maintainers = with maintainers; [ zonni ];
10+
11+
config = final: prev: {
12+
defaultTargets = [
13+
"nixos"
14+
"home"
15+
];
16+
moduleNamePrefix = "overlays";
17+
};
18+
19+
libExtension = config: final: _: {
20+
overlayModule =
21+
{
22+
name,
23+
overlay ? null,
24+
overlays ? [ ],
25+
targets ? config.defaultTargets,
26+
withPrefix ? true,
27+
enabled ? true,
28+
}:
29+
let
30+
finalOverlays = overlays ++ (optional (overlay != null) overlay);
31+
in
32+
final.module {
33+
name = if withPrefix then "${config.moduleNamePrefix}.${name}" else name;
34+
35+
options = singleEnableOption enabled;
36+
37+
nixos.ifEnabled = mkIf (elem "nixos" targets) {
38+
nixpkgs.overlays = finalOverlays;
39+
};
40+
41+
home.ifEnabled = mkIf (elem "home" targets) {
42+
nixpkgs.overlays = finalOverlays;
43+
};
44+
45+
darwin.ifEnabled = mkIf (elem "darwin" targets) {
46+
nixpkgs.overlays = finalOverlays;
47+
};
48+
};
49+
};
50+
}

lib/maintainers.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ in
2626
telegram = "yunfachi";
2727
telegramId = 1349897307;
2828
};
29+
zonni = maintainer {
30+
name = "Zonni";
31+
github = "mzonski";
32+
githubId = 20989477;
33+
};
2934
};
3035
}

0 commit comments

Comments
 (0)