refactor(buildClan): move modules into 'forName' and import the correct core module depending on class
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
directory,
|
directory,
|
||||||
|
meta,
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
_class,
|
_class,
|
||||||
@@ -20,6 +21,15 @@
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
(lib.optionalAttrs (_class == "nixos") {
|
||||||
|
clan.core.settings = {
|
||||||
|
inherit (meta) name icon;
|
||||||
|
inherit directory;
|
||||||
|
machine = {
|
||||||
|
inherit name;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
# TODO: move into nixos modules
|
# TODO: move into nixos modules
|
||||||
({
|
({
|
||||||
networking.hostName = lib.mkDefault name;
|
networking.hostName = lib.mkDefault name;
|
||||||
|
|||||||
@@ -65,18 +65,10 @@ let
|
|||||||
system
|
system
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
staticModules = (
|
|
||||||
lib.modules.importApply ./machineModules/forName.nix {
|
|
||||||
inherit
|
|
||||||
name
|
|
||||||
directory
|
|
||||||
;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
(config.outputs.moduleForMachine.${name} or { })
|
(config.outputs.moduleForMachine.${name} or { })
|
||||||
staticModules
|
|
||||||
innerModule
|
innerModule
|
||||||
{
|
{
|
||||||
config.clan.core.module = innerModule;
|
config.clan.core.module = innerModule;
|
||||||
@@ -97,15 +89,6 @@ let
|
|||||||
nix-darwin.lib.darwinSystem {
|
nix-darwin.lib.darwinSystem {
|
||||||
modules = [
|
modules = [
|
||||||
(config.outputs.moduleForMachine.${name} or { })
|
(config.outputs.moduleForMachine.${name} or { })
|
||||||
# We split the modules to reduce the number of dependencies
|
|
||||||
# This module only depends on the machine name
|
|
||||||
# and the directory
|
|
||||||
(lib.modules.importApply ./machineModules/forName.nix {
|
|
||||||
inherit
|
|
||||||
name
|
|
||||||
directory
|
|
||||||
;
|
|
||||||
})
|
|
||||||
# This module depends on the system and pkgs
|
# This module depends on the system and pkgs
|
||||||
# It contains optional logic to override 'nixpkgs.pkgs' and 'nixpkgs.hostPlatform'
|
# It contains optional logic to override 'nixpkgs.pkgs' and 'nixpkgs.hostPlatform'
|
||||||
# and other 'system' related logic
|
# and other 'system' related logic
|
||||||
@@ -168,20 +151,7 @@ in
|
|||||||
imports = [
|
imports = [
|
||||||
{
|
{
|
||||||
options.outputs.moduleForMachine = lib.mkOption {
|
options.outputs.moduleForMachine = lib.mkOption {
|
||||||
type = lib.types.attrsOf (
|
type = lib.types.attrsOf lib.types.deferredModule;
|
||||||
lib.types.deferredModuleWith {
|
|
||||||
staticModules = [
|
|
||||||
(
|
|
||||||
{ _class, ... }:
|
|
||||||
{
|
|
||||||
imports = lib.optionals (_class == "nixos") [
|
|
||||||
clan-core.nixosModules.clanCore
|
|
||||||
];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
config.outputs.moduleForMachine = lib.mkMerge [
|
config.outputs.moduleForMachine = lib.mkMerge [
|
||||||
# Create one empty module for each machine such that there is a default for each machine
|
# Create one empty module for each machine such that there is a default for each machine
|
||||||
@@ -193,18 +163,20 @@ in
|
|||||||
(
|
(
|
||||||
{ _class, ... }:
|
{ _class, ... }:
|
||||||
{
|
{
|
||||||
imports = (v.machineImports or [ ]);
|
imports = (v.machineImports or [ ]) ++ [
|
||||||
config = lib.optionalAttrs (_class == "nixos") {
|
(lib.modules.importApply ./machineModules/forName.nix {
|
||||||
clan.core.settings = {
|
inherit (config.inventory) meta;
|
||||||
inherit (config.inventory.meta) name icon;
|
inherit
|
||||||
|
name
|
||||||
inherit directory;
|
directory
|
||||||
machine = {
|
;
|
||||||
inherit name;
|
})
|
||||||
};
|
# Import the correct 'core' module
|
||||||
};
|
# We assume either:
|
||||||
};
|
# - nixosModules (_class = nixos)
|
||||||
|
# - darwinModules (_class = darwin)
|
||||||
|
(lib.optionalAttrs (clan-core."${_class}Modules" ? clanCore) clan-core."${_class}Modules".clanCore)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
) inventoryClass.machines)
|
) inventoryClass.machines)
|
||||||
|
|||||||
Reference in New Issue
Block a user