fixup(buildClan): split up the inner-module into: {forSystem, forName}
I am preparing this such that we can move the forName modules into the defaults for the deferred module outputs and the forSystem modules are added later and only for the 'configsPerSystem' where we actually need the system modules
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
{
|
||||
system,
|
||||
name,
|
||||
pkgs,
|
||||
clanConfiguration,
|
||||
}:
|
||||
{
|
||||
_class,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (clanConfiguration) directory machines pkgsForSystem;
|
||||
inherit (clanConfiguration.clanInternals) inventoryClass;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
{
|
||||
imports = builtins.filter builtins.pathExists (
|
||||
[
|
||||
"${directory}/machines/${name}/configuration.nix"
|
||||
]
|
||||
++ lib.optionals (_class == "nixos") [
|
||||
"${directory}/machines/${name}/hardware-configuration.nix"
|
||||
"${directory}/machines/${name}/disko.nix"
|
||||
]
|
||||
);
|
||||
}
|
||||
(lib.optionalAttrs (_class == "nixos") {
|
||||
imports = (inventoryClass.machines.${name}.machineImports or [ ]);
|
||||
|
||||
config = {
|
||||
clan.core.settings = {
|
||||
inherit (clanConfiguration.inventory.meta) name icon;
|
||||
|
||||
inherit directory;
|
||||
machine = {
|
||||
inherit name;
|
||||
};
|
||||
};
|
||||
# Inherited from clan wide settings
|
||||
# TODO: remove these
|
||||
};
|
||||
})
|
||||
(
|
||||
{
|
||||
networking.hostName = lib.mkDefault name;
|
||||
|
||||
# For vars we need to override the system so we run vars
|
||||
# generators on the machine that runs `clan vars generate`. If a
|
||||
# users is using the `pkgsForSystem`, we don't set
|
||||
# nixpkgs.hostPlatform it would conflict with the `nixpkgs.pkgs`
|
||||
# option.
|
||||
nixpkgs.hostPlatform = lib.mkIf (system != null && (pkgsForSystem system) != null) (
|
||||
lib.mkForce system
|
||||
);
|
||||
}
|
||||
// lib.optionalAttrs (pkgs != null) { nixpkgs.pkgs = lib.mkForce pkgs; }
|
||||
)
|
||||
];
|
||||
}
|
||||
28
lib/build-clan/machineModules/forName.nix
Normal file
28
lib/build-clan/machineModules/forName.nix
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
name,
|
||||
directory,
|
||||
}:
|
||||
{
|
||||
_class,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [
|
||||
{
|
||||
imports = builtins.filter builtins.pathExists (
|
||||
[
|
||||
"${directory}/machines/${name}/configuration.nix"
|
||||
]
|
||||
++ lib.optionals (_class == "nixos") [
|
||||
"${directory}/machines/${name}/hardware-configuration.nix"
|
||||
"${directory}/machines/${name}/disko.nix"
|
||||
]
|
||||
);
|
||||
}
|
||||
# TODO: move into nixos modules
|
||||
({
|
||||
networking.hostName = lib.mkDefault name;
|
||||
})
|
||||
];
|
||||
}
|
||||
26
lib/build-clan/machineModules/forSystem.nix
Normal file
26
lib/build-clan/machineModules/forSystem.nix
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
pkgs,
|
||||
pkgsForSystem,
|
||||
system,
|
||||
}:
|
||||
{
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [
|
||||
(
|
||||
{
|
||||
# For vars we need to override the system so we run vars
|
||||
# generators on the machine that runs `clan vars generate`. If a
|
||||
# users is using the `pkgsForSystem`, we don't set
|
||||
# nixpkgs.hostPlatform it would conflict with the `nixpkgs.pkgs`
|
||||
# option.
|
||||
nixpkgs.hostPlatform = lib.mkIf (system != null && (pkgsForSystem system) != null) (
|
||||
lib.mkForce system
|
||||
);
|
||||
}
|
||||
// lib.optionalAttrs (pkgs != null) { nixpkgs.pkgs = lib.mkForce pkgs; }
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -59,17 +59,25 @@ let
|
||||
nixpkgs.lib.nixosSystem {
|
||||
modules =
|
||||
let
|
||||
innerModule = lib.modules.importApply ./inner-module.nix {
|
||||
innerModule = lib.modules.importApply ./machineModules/forSystem.nix {
|
||||
inherit
|
||||
system
|
||||
name
|
||||
pkgs
|
||||
pkgsForSystem
|
||||
system
|
||||
;
|
||||
clanConfiguration = config;
|
||||
};
|
||||
staticModules = (
|
||||
lib.modules.importApply ./machineModules/forName.nix {
|
||||
inherit
|
||||
name
|
||||
directory
|
||||
;
|
||||
}
|
||||
);
|
||||
in
|
||||
[
|
||||
(config.outputs.moduleForMachine.${name} or { })
|
||||
staticModules
|
||||
innerModule
|
||||
{
|
||||
config.clan.core.module = innerModule;
|
||||
@@ -90,13 +98,24 @@ let
|
||||
nix-darwin.lib.darwinSystem {
|
||||
modules = [
|
||||
(config.outputs.moduleForMachine.${name} or { })
|
||||
(lib.modules.importApply ./inner-module.nix {
|
||||
# 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
|
||||
system
|
||||
name
|
||||
pkgs
|
||||
directory
|
||||
;
|
||||
})
|
||||
# This module depends on the system and pkgs
|
||||
# It contains optional logic to override 'nixpkgs.pkgs' and 'nixpkgs.hostPlatform'
|
||||
# and other 'system' related logic
|
||||
(lib.modules.importApply ./machineModules/forSystem.nix {
|
||||
inherit
|
||||
pkgs
|
||||
pkgsForSystem
|
||||
system
|
||||
;
|
||||
clanConfiguration = config;
|
||||
})
|
||||
];
|
||||
|
||||
@@ -170,7 +189,26 @@ in
|
||||
# See: 'staticModules' in the moduleForMachine option
|
||||
# This is only necessary because clan.machines doesn't include all machines
|
||||
# There can other sources: i.e. inventory
|
||||
(lib.mapAttrs (_: _: { }) config.inventory.machines)
|
||||
(lib.mapAttrs (
|
||||
name: v:
|
||||
(
|
||||
{ _class, ... }:
|
||||
{
|
||||
imports = (v.machineImports or [ ]);
|
||||
config = lib.optionalAttrs (_class == "nixos") {
|
||||
clan.core.settings = {
|
||||
inherit (config.inventory.meta) name icon;
|
||||
|
||||
inherit directory;
|
||||
machine = {
|
||||
inherit name;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
)
|
||||
) inventoryClass.machines)
|
||||
|
||||
# The user can define some machine config here
|
||||
# i.e. 'clan.machines.jon = ...'
|
||||
|
||||
Reference in New Issue
Block a user