Merge pull request 'build-clan: expose Clan configuration as a module' (#3303) from push-lsoyznsukqyq into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3303
This commit is contained in:
Michael Hoang
2025-04-14 14:16:26 +00:00
3 changed files with 94 additions and 74 deletions

View File

@@ -0,0 +1,67 @@
{
system,
name,
pkgs,
extraConfig,
config,
clan-core,
}:
{
_class,
lib,
...
}:
let
inherit (config) directory machines pkgsForSystem;
inherit (config.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 = [
clan-core.nixosModules.clanCore
] ++ (inventoryClass.machines.${name}.machineImports or [ ]);
config = {
clan.core.settings = {
inherit (config.inventory.meta) name icon;
inherit directory;
machine = {
inherit name;
};
};
# Inherited from clan wide settings
# TODO: remove these
};
})
extraConfig
(machines.${name} or { })
(
{
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; }
)
];
}

View File

@@ -1,4 +1,3 @@
# NixOS module
{ {
config, config,
clan-core, clan-core,
@@ -10,7 +9,6 @@
let let
inherit (config) inherit (config)
directory directory
machines
pkgsForSystem pkgsForSystem
specialArgs specialArgs
; ;
@@ -62,51 +60,22 @@ let
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
modules = modules =
let let
hwConfig = "${directory}/machines/${name}/hardware-configuration.nix"; module = lib.modules.importApply ./inner-module.nix {
diskoConfig = "${directory}/machines/${name}/disko.nix"; inherit
system
name
pkgs
extraConfig
config
clan-core
;
};
in in
[ [
module
{ {
# Autoinclude configuration.nix and hardware-configuration.nix config.clan.core.module = module;
imports = builtins.filter builtins.pathExists [
"${directory}/machines/${name}/configuration.nix"
hwConfig
diskoConfig
];
} }
clan-core.nixosModules.clanCore
extraConfig
(machines.${name} or { })
{ imports = inventoryClass.machines.${name}.machineImports or [ ]; }
(
{
# Settings
clan.core.settings = {
inherit (config.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; }
)
]; ];
specialArgs = { specialArgs = {
@@ -123,37 +92,16 @@ let
}: }:
nix-darwin.lib.darwinSystem { nix-darwin.lib.darwinSystem {
modules = [ modules = [
{ (lib.modules.importApply ./inner-module.nix {
imports = builtins.filter builtins.pathExists [ inherit
"${directory}/machines/${name}/configuration.nix" system
]; name
} pkgs
( extraConfig
if !lib.hasAttrByPath [ "darwinModules" "clanCore" ] clan-core then config
{ } clan-core
else ;
throw "this should import clan-core.darwinModules.clanCore" })
)
extraConfig
(machines.${name} or { })
# TODO: import inventory when it has support for defining `nix-darwin` modules
(
{
# TODO: set clan-core settings when clan-core has support for `nix-darwin`
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; }
)
]; ];
specialArgs = { specialArgs = {

View File

@@ -12,4 +12,9 @@
] ]
) )
]; ];
options.clan.core.module = lib.mkOption {
internal = true;
type = lib.types.raw;
};
} }