Skip to content

Commit ee8861b

Browse files
authored
Merge pull request #46 from yunfachi/feat/system-option-base-extension
2 parents 73b676e + 3b50219 commit ee8861b

File tree

5 files changed

+95
-55
lines changed

5 files changed

+95
-55
lines changed

docs/src/extensions/all-extensions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ This section describes all official Denix extensions.
7575
| `enable` | [`args.enable`](#base-settings-args-enable) | Whether to create `host` and `hosts` arguments with the [`args`](#args) extension |
7676
| `path` | [`args.path`](#base-settings-args-path) | Path to options of the [`args`](#args) extension |
7777

78+
`hosts.system`
79+
| Name | Default Мalue | Description |
80+
| - | - | - |
81+
| `enable` | [`args.enable`](#base-settings-args-enable) | Whether to create a string option `system` in the host submodule, which sets the values for the `homeManagerSystem`, `nixos.nixpkgs.hostPlatform`, and `darwin.nixpkgs.hostPlatform` options |
82+
7883
`hosts.assertions`
7984
| Name | Default Value | Description |
8085
| - | - | - |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
| `enable` | [`args.enable`](#base-settings-args-enable) | Создавать ли аргументы `host` и `hosts` с расширением [`args`](#args) |
7676
| `path` | [`args.path`](#base-settings-args-path) | Путь к опциям расширения [`args`](#args) |
7777

78+
`hosts.system`
79+
| Название | Значение по умолчанию | Описание |
80+
| - | - | - |
81+
| `enable` | [`args.enable`](#base-settings-args-enable) | Создавать ли string-опцию `system` в подмодуле хоста, которая задает значения опциям `homeManagerSystem`, `nixos.nixpkgs.hostPlatform` и `darwin.nixpkgs.hostPlatform` |
82+
7883
`hosts.assertions`
7984
| Название | Значение по умолчанию | Описание |
8085
| - | - | - |

lib/extensions/base/hosts.nix

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ delib.extension {
2828
defaultByHostType = { };
2929
};
3030

31+
system = {
32+
enable = true;
33+
};
34+
3135
displays = {
3236
enable = true;
3337
# TODO: hyprland = {enable = false; moduleSystem = "home";}; ...
@@ -39,60 +43,65 @@ delib.extension {
3943

4044
libExtension =
4145
extensionConfig: final: prev: with final; {
42-
generateHostType =
46+
generateHostTypeSubmodule =
4347
{
44-
hostConfig,
4548
generateIsType ? extensionConfig.hosts.type.generateIsType,
4649
types ? extensionConfig.hosts.type.types,
4750
}:
51+
{ config, ... }:
4852
{
49-
type = noDefault (enumOption types null);
50-
}
51-
// lib.optionalAttrs generateIsType (
52-
builtins.listToAttrs (
53-
map (type: {
54-
name =
55-
let
56-
chars = lib.stringToCharacters type;
57-
in
58-
"is${lib.toUpper (lib.head chars) + lib.concatStrings (lib.tail chars)}";
59-
value = boolOption (hostConfig.type == type);
60-
}) types
61-
)
62-
);
63-
64-
generateHostFeatures =
53+
options = {
54+
type = noDefault (enumOption types null);
55+
}
56+
// lib.optionalAttrs generateIsType (
57+
builtins.listToAttrs (
58+
map (type: {
59+
name =
60+
let
61+
chars = lib.stringToCharacters type;
62+
in
63+
"is${lib.toUpper (lib.head chars) + lib.concatStrings (lib.tail chars)}";
64+
value = boolOption (config.type == type);
65+
}) types
66+
)
67+
);
68+
};
69+
70+
generateHostFeaturesSubmodule =
6571
{
66-
hostConfig,
6772
generateIsFeatured ? extensionConfig.hosts.features.generateIsFeatured,
6873
features ? extensionConfig.hosts.features.features,
6974
default ? extensionConfig.hosts.features.default,
7075
defaultByHostType ? extensionConfig.hosts.features.defaultByHostType,
7176
}:
77+
{ config, ... }:
7278
{
73-
defaultFeatures = listOfOption (enum features) (
74-
default ++ (defaultByHostType.${hostConfig.type} or [ ])
79+
options = {
80+
defaultFeatures = listOfOption (enum features) (
81+
default ++ (defaultByHostType.${config.type} or [ ])
82+
);
83+
features = listOfOption (enum features) [ ];
84+
}
85+
// lib.optionalAttrs generateIsFeatured (
86+
builtins.listToAttrs (
87+
map (feature: {
88+
name = "${feature}Featured";
89+
value = boolOption (builtins.elem feature (config.features ++ config.defaultFeatures));
90+
}) features
91+
)
7592
);
76-
features = listOfOption (enum features) [ ];
77-
}
78-
// lib.optionalAttrs generateIsFeatured (
79-
builtins.listToAttrs (
80-
map (feature: {
81-
name = "${feature}Featured";
82-
value = boolOption (builtins.elem feature (hostConfig.features ++ hostConfig.defaultFeatures));
83-
}) features
84-
)
85-
);
86-
87-
generateHostDisplays =
88-
{ hostConfig }:
93+
};
94+
95+
generateHostDisplaysSubmodule =
96+
_:
97+
{ config, ... }:
8998
{
90-
displays = listOfOption (submodule {
99+
options.displays = listOfOption (submodule {
91100
options = {
92101
enable = boolOption true;
93102

94103
name = noDefault (strOption null);
95-
primary = boolOption (builtins.length hostConfig.displays == 1);
104+
primary = boolOption (builtins.length config.displays == 1);
96105
touchscreen = boolOption false;
97106

98107
refreshRate = intOption 60;
@@ -103,13 +112,22 @@ delib.extension {
103112
};
104113
}) [ ];
105114
};
115+
116+
generateHostSystemSubmodule =
117+
_:
118+
{ config, lib, ... }:
119+
{
120+
options.system = allowNull (strOption null);
121+
122+
config.homeManagerSystem = lib.mkIf (config.system != null) config.system;
123+
};
106124
};
107125

108126
modules =
109127
extensionConfig:
110128
lib.optionals extensionConfig.hosts.enable [
111129
(
112-
{ delib, ... }:
130+
{ delib, lib, ... }:
113131
let
114132
assertionsConfig =
115133
{ myconfig, ... }:
@@ -131,24 +149,38 @@ delib.extension {
131149
options =
132150
with delib;
133151
let
134-
host =
135-
lib.singleton (
136-
{ config, ... }:
137-
{
138-
options =
139-
hostSubmoduleOptions
140-
// delib.generateHostType { hostConfig = config; }
141-
// delib.generateHostFeatures { hostConfig = config; }
142-
// delib.generateHostDisplays { hostConfig = config; };
143-
}
144-
)
145-
++ extensionConfig.hosts.extraSubmodules;
152+
host = [
153+
{ options = hostSubmoduleOptions; }
154+
]
155+
++ lib.optionals extensionConfig.hosts.type.enable [ (delib.generateHostTypeSubmodule { }) ]
156+
++ lib.optionals extensionConfig.hosts.features.enable [ (delib.generateHostFeaturesSubmodule { }) ]
157+
++ lib.optionals extensionConfig.hosts.displays.enable [ (delib.generateHostDisplaysSubmodule { }) ]
158+
++ lib.optionals extensionConfig.hosts.system.enable [ (delib.generateHostSystemSubmodule { }) ]
159+
++ extensionConfig.hosts.extraSubmodules;
146160
in
147161
{
148162
host = hostOption host;
149163
hosts = hostsOption host;
150164
};
151165

166+
nixos.always =
167+
{ myconfig, ... }:
168+
lib.optionalAttrs extensionConfig.hosts.system.enable {
169+
nixpkgs.hostPlatform = lib.mkIf (
170+
delib._callLibArgs.currentHostName != null
171+
&& myconfig.hosts.${delib._callLibArgs.currentHostName}.system != null
172+
) myconfig.hosts.${delib._callLibArgs.currentHostName}.system;
173+
};
174+
175+
darwin.always =
176+
{ myconfig, ... }:
177+
lib.optionalAttrs extensionConfig.hosts.system.enable {
178+
nixpkgs.hostPlatform = lib.mkIf (
179+
delib._callLibArgs.currentHostName != null
180+
&& myconfig.hosts.${delib._callLibArgs.currentHostName}.system != null
181+
) myconfig.hosts.${delib._callLibArgs.currentHostName}.system;
182+
};
183+
152184
myconfig.always =
153185
{ myconfig, ... }:
154186
lib.optionalAttrs extensionConfig.hosts.args.enable (

templates/minimal-no-rices/hosts/desktop/hardware.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
delib.host {
33
name = "desktop";
44

5+
system = "x86_64-linux"; # !!! REPLACEME
6+
57
# useHomeManagerModule = false;
6-
homeManagerSystem = "x86_64-linux"; # !!! REPLACEME
78
home.home.stateVersion = "24.05"; # !!! REPLACEME
89

910
# If you're not using NixOS, you can remove this entire block.
1011
nixos = {
11-
nixpkgs.hostPlatform = "x86_64-linux"; # !!! REPLACEME
1212
system.stateVersion = "24.05"; # !!! REPLACEME
1313

1414
# nixos-generate-config --show-hardware-config
@@ -17,7 +17,6 @@ delib.host {
1717

1818
# If you're not using Nix-Darwin, you can remove this entire block.
1919
darwin = {
20-
nixpkgs.hostPlatform = "aarch64-darwin"; # !!! REPLACEME
2120
system.stateVersion = 6; # !!! REPLACEME
2221
};
2322
}

templates/minimal/hosts/desktop/hardware.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
delib.host {
33
name = "desktop";
44

5+
system = "x86_64-linux"; # !!! REPLACEME
6+
57
# useHomeManagerModule = false;
6-
homeManagerSystem = "x86_64-linux"; # !!! REPLACEME
78
home.home.stateVersion = "24.05"; # !!! REPLACEME
89

910
# If you're not using NixOS, you can remove this entire block.
1011
nixos = {
11-
nixpkgs.hostPlatform = "x86_64-linux"; # !!! REPLACEME
1212
system.stateVersion = "24.05"; # !!! REPLACEME
1313

1414
# nixos-generate-config --show-hardware-config
@@ -17,7 +17,6 @@ delib.host {
1717

1818
# If you're not using Nix-Darwin, you can remove this entire block.
1919
darwin = {
20-
nixpkgs.hostPlatform = "aarch64-darwin"; # !!! REPLACEME
2120
system.stateVersion = 6; # !!! REPLACEME
2221
};
2322
}

0 commit comments

Comments
 (0)