Skip to content

Commit f0a61b4

Browse files
authored
Merge pull request #34 from yunfachi/feat/no-home-manager-module
lib/configurations: add useHomeManagerModule
2 parents 9f6b0cb + 025fdd7 commit f0a61b4

File tree

9 files changed

+83
-53
lines changed

9 files changed

+83
-53
lines changed

docs/src/hosts/introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ In simple terms, this allows you to separate the NixOS, Home Manager, Nix-Darwin
55

66
A host can also be compared to a module, because all hosts are imported regardless of which one is active, but the applied configurations depend on the active host.
77

8+
It is also worth mentioning that, by default, the Home Manager module is automatically included in the NixOS and Nix-Darwin configurations of each host. If you do not want to use the Home Manager module for a particular host, simply add `useHomeManagerModule = false;` to the arguments of the `delib.host` function.
9+
810
## Options {#options}
911
For hosts to work, the configuration must include the options `${myconfigName}.host` and `${myconfigName}.hosts`, which **you define yourself** in one of the modules.
1012

docs/src/hosts/structure.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Function Arguments {#function-arguments}
44
- `name`: a string representing the host name.
5+
- `useHomeManagerModule`: whether to include the Home Manager module in the NixOS and Nix-Darwin configurations of this host. Defaults to `true`.
56
- `homeManagerSystem`: a string used in the `pkgs` attribute of the `home-manager.lib.homeManagerConfiguration` function, which is used in the [`delib.configurations`](/configurations/introduction) function as `homeManagerNixpkgs.legacyPackages.${homeManagerSystem}`.
67
- `myconfig`: sets its value to `config.${myconfigName}` if `config.${myconfigName}.host` matches the current host.
78
- `nixos`: sets its value to `config` if `moduleSystem` is `nixos` and `config.${myconfigName}.host` matches the current host.
@@ -24,6 +25,8 @@ A list of arguments passed to `?(shared.)[myconfig|nixos|home|darwin]` if their
2425
delib.host {
2526
name = "";
2627
28+
useHomeManagerModule = true;
29+
2730
# homeManagerNixpkgs.legacyPackages.${homeManagerSystem}
2831
homeManagerSystem = "x86_64-linux";
2932

docs/src/ru/hosts/introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
Хост также можно сравнить с модулем, потому что все хосты импортируются независимо от того, какой из них активен, но применяемые конфигурации зависят от активного хоста.
77

8+
Также стоит упомянуть, что по умолчанию модуль Home Manager автоматически включён в конфигурации NixOS и Nix-Darwin каждого хоста. Если вы не хотите использовать модуль Home Manager для какого-либо хоста, просто добавьте `useHomeManagerModule = false;` в аргументы функции `delib.host`.
9+
810
## Опции {#options}
911
Для работы хостов конфигурация должна включать опции `${myconfigName}.host` и `${myconfigName}.hosts`, которые **вы задаете самостоятельно** в одном из модулей.
1012

docs/src/ru/hosts/structure.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Аргументы функции {#function-arguments}
44
- `name`: строка, представляющая имя хоста.
5+
- `useHomeManagerModule`: добавлять ли модуль Home Manager в конфигурации NixOS и Nix-Darwin этого хоста. По умолчанию `true`.
56
- `homeManagerSystem`: строка, используемая в атрибуте `pkgs` функции `home-manager.lib.homeManagerConfiguration`, которая используется в функции [`delib.configurations`](/ru/configurations/introduction) в виде `homeManagerNixpkgs.legacyPackages.${homeManagerSystem}`.
67
- `myconfig`: устанавливает её значение в `config.${myconfigName}`, если `config.${myconfigName}.host` соответствует текущему хосту.
78
- `nixos`: устанавливает её значение в `config`, если `moduleSystem` равен `nixos` и `config.${myconfigName}.host` соответствует текущему хосту.
@@ -24,6 +25,8 @@
2425
delib.host {
2526
name = "";
2627
28+
useHomeManagerModule = true;
29+
2730
# homeManagerNixpkgs.legacyPackages.${homeManagerSystem}
2831
homeManagerSystem = "x86_64-linux";
2932

lib/configurations/apply.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
useHomeManagerModule,
23
homeManagerUser,
34
moduleSystem,
45
myconfigName,
@@ -23,9 +24,15 @@
2324
};
2425
home = _home:
2526
configForModuleSystem {
26-
nixos.home-manager.users.${homeManagerUser} = _home;
27+
nixos =
28+
if useHomeManagerModule
29+
then {home-manager.users.${homeManagerUser} = _home;}
30+
else {};
2731
home = _home;
28-
darwin.home-manager.users.${homeManagerUser} = _home;
32+
darwin =
33+
if useHomeManagerModule
34+
then {home-manager.users.${homeManagerUser} = _home;}
35+
else {};
2936
};
3037
darwin = _darwin:
3138
configForModuleSystem {

lib/configurations/default.nix

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
home-manager ? args.home-manager,
1414
nix-darwin ? args.nix-darwin,
1515
homeManagerNixpkgs ? nixpkgs,
16-
homeManagerUser,
16+
homeManagerUser ? null, # not default value!
1717
moduleSystem ? null, # TODO: remove the default value once the deprecated isHomeManager is removed
1818
isHomeManager ? null, # TODO: DEPRECATED since 2025/05/05
1919
paths ? [],
@@ -43,14 +43,15 @@
4343

4444
files = delib.umport {inherit paths exclude recursive;};
4545

46-
mkApply = moduleSystem: import ./apply.nix {inherit lib homeManagerUser moduleSystem myconfigName;};
46+
mkApply = moduleSystem: useHomeManagerModule: import ./apply.nix {inherit useHomeManagerModule homeManagerUser moduleSystem myconfigName;};
4747
mkDenixLib = {
4848
config,
4949
moduleSystem,
50+
useHomeManagerModule,
5051
currentHostName ? null,
5152
}:
5253
delib.extend (delib: _: let
53-
apply = mkApply moduleSystem;
54+
apply = mkApply moduleSystem useHomeManagerModule;
5455
callLib = file: import file {inherit delib lib apply config myconfigName currentHostName;};
5556
in
5657
{
@@ -63,64 +64,72 @@
6364

6465
mkSystem = {
6566
moduleSystem,
67+
useHomeManagerModule,
6668
homeManagerSystem,
6769
currentHostName,
6870
internalExtraModules ? (moduleSystem_: []),
69-
}: let
70-
nixosSystem = nixpkgs.lib.nixosSystem {
71-
specialArgs =
72-
specialArgs
73-
// {
74-
${denixLibName} = mkDenixLib {
75-
config = nixosSystem.config;
76-
moduleSystem = "nixos";
77-
inherit currentHostName;
71+
}:
72+
if !topArgs ? homeManagerUser && useHomeManagerModule
73+
then abort "Please specify 'delib.configurations :: useHomeManagerModule'. Valid values are true and false."
74+
else let
75+
nixosSystem = nixpkgs.lib.nixosSystem {
76+
specialArgs =
77+
specialArgs
78+
// {
79+
${denixLibName} = mkDenixLib {
80+
config = nixosSystem.config;
81+
moduleSystem = "nixos";
82+
inherit currentHostName useHomeManagerModule;
83+
};
84+
inherit useHomeManagerModule; # otherwise it's impossible to make config.home-manager optional when not useHomeManagerModule.
7885
};
79-
};
80-
modules = (internalExtraModules "nixos") ++ extraModules ++ files ++ [home-manager.nixosModules.home-manager];
81-
};
82-
homeSystem = home-manager.lib.homeManagerConfiguration {
83-
extraSpecialArgs =
84-
specialArgs
85-
// {
86-
${denixLibName} = mkDenixLib {
87-
config = homeSystem.config;
88-
moduleSystem = "home";
89-
inherit currentHostName;
86+
modules = (internalExtraModules "nixos") ++ extraModules ++ files ++ (lib.optionals useHomeManagerModule [home-manager.nixosModules.home-manager]);
87+
};
88+
homeSystem = home-manager.lib.homeManagerConfiguration {
89+
extraSpecialArgs =
90+
specialArgs
91+
// {
92+
${denixLibName} = mkDenixLib {
93+
config = homeSystem.config;
94+
moduleSystem = "home";
95+
inherit currentHostName useHomeManagerModule;
96+
};
97+
inherit useHomeManagerModule; # otherwise it's impossible to make config.home-manager optional when not useHomeManagerModule.
9098
};
91-
};
92-
pkgs = homeManagerNixpkgs.legacyPackages.${homeManagerSystem};
93-
modules = (internalExtraModules "home") ++ extraModules ++ files;
94-
};
95-
darwinSystem = nix-darwin.lib.darwinSystem {
96-
specialArgs =
97-
specialArgs
98-
// {
99-
${denixLibName} = mkDenixLib {
100-
config = darwinSystem.config;
101-
moduleSystem = "darwin";
102-
inherit currentHostName;
99+
pkgs = homeManagerNixpkgs.legacyPackages.${homeManagerSystem};
100+
modules = (internalExtraModules "home") ++ extraModules ++ files;
101+
};
102+
darwinSystem = nix-darwin.lib.darwinSystem {
103+
specialArgs =
104+
specialArgs
105+
// {
106+
${denixLibName} = mkDenixLib {
107+
config = darwinSystem.config;
108+
moduleSystem = "darwin";
109+
inherit currentHostName useHomeManagerModule;
110+
};
111+
inherit useHomeManagerModule; # otherwise it's impossible to make config.home-manager optional when not useHomeManagerModule.
103112
};
104-
};
105-
# FIXME: is this really necessary?
106-
# pkgs = ...;
107-
modules = (internalExtraModules "darwin") ++ extraModules ++ files ++ [home-manager.darwinModules.home-manager];
108-
};
109-
in
110-
{
111-
nixos = nixosSystem;
112-
home = homeSystem;
113-
darwin = darwinSystem;
114-
}
115-
.${
116-
moduleSystem
117-
};
113+
# FIXME: is this really necessary?
114+
# pkgs = ...;
115+
modules = (internalExtraModules "darwin") ++ extraModules ++ files ++ (lib.optionals useHomeManagerModule [home-manager.darwinModules.home-manager]);
116+
};
117+
in
118+
{
119+
nixos = nixosSystem;
120+
home = homeSystem;
121+
darwin = darwinSystem;
122+
}
123+
.${
124+
moduleSystem
125+
};
118126

119127
inherit
120128
({rices = {};}
121129
// (mkSystem {
122130
# TODO: maybe add moduleSystem = "empty", which "apply" would skip entirely*?
123131
moduleSystem = "nixos";
132+
useHomeManagerModule = true; # FIXME
124133
homeManagerSystem = "x86_64-linux"; # just a plug; FIXME
125134
currentHostName = null;
126135
internalExtraModules = _: [mkConfigurationsSystemExtraModule];
@@ -141,10 +150,10 @@
141150

142151
system = mkSystem {
143152
inherit moduleSystem;
144-
inherit (host) homeManagerSystem;
153+
inherit (host) useHomeManagerModule homeManagerSystem;
145154
currentHostName = host.name;
146155
internalExtraModules = moduleSystem: let
147-
apply = mkApply moduleSystem;
156+
apply = mkApply moduleSystem host.useHomeManagerModule;
148157
in
149158
[
150159
({options, ...}: {config.${myconfigName} = {inherit host;} // lib.optionalAttrs (options.${myconfigName} ? rice) {inherit rice;};})

lib/configurations/host.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
darwin ? {},
1515
shared ? {},
1616
# to avoid overwriting
17+
# useHomeManagerModule ? true,
1718
# homeManagerSystem ? null,
1819
# rice ? null,
1920
...
@@ -68,6 +69,7 @@
6869
hostSubmoduleOptions = with delib.options; {
6970
name = noDefault (strOption null);
7071

72+
useHomeManagerModule = boolOption true;
7173
homeManagerSystem = description (noDefault (strOption null)) "Passed to the `homeManagerConfiguration` as `nixpkgs.legacyPackages.<homeManagerSystem>`";
7274

7375
myconfig = attrsOption {};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
delib.host {
33
name = "desktop";
44

5+
# useHomeManagerModule = false;
56
homeManagerSystem = "x86_64-linux"; #!!! REPLACEME
67
home.home.stateVersion = "24.05"; #!!! REPLACEME
78

templates/minimal/hosts/desktop/hardware.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
delib.host {
33
name = "desktop";
44

5+
# useHomeManagerModule = false;
56
homeManagerSystem = "x86_64-linux"; #!!! REPLACEME
67
home.home.stateVersion = "24.05"; #!!! REPLACEME
78

0 commit comments

Comments
 (0)