feat(hm): add sharedModules, move configurations.nix to hosts.nix

This commit is contained in:
Mohammad Rafiq 2025-07-07 07:25:39 +08:00
parent 3cf6a49a2a
commit 253b46eee0
No known key found for this signature in database
2 changed files with 9 additions and 4 deletions

View file

@ -1,13 +1,18 @@
{ inputs, ... }:
{ inputs, config, ... }:
let
inherit (cfg.lib) flattenAttrs;
cfg = config.flake;
hm = inputs.home-manager;
globalCfg = {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [
(flattenAttrs (cfg.modules.homeManager or { }))
];
};
in
{
imports = [ hm.flakeModules.home-manager ];
flake.modules.nixos.default.imports = [ hm.nixosModules.home-manager ];
flake.modules.nixos.default.config = globalCfg;
flake.modules.nixos.default.config.home-manager = globalCfg;
}

34
nix/modules/hosts.nix Normal file
View file

@ -0,0 +1,34 @@
{
config,
lib,
inputs,
...
}:
let
inherit (lib) nixosSystem;
inherit (cfg.lib) flattenAttrs;
inherit (lib.attrsets) mapAttrs;
cfg = config.flake;
hosts = cfg.manifest.hosts or { };
mkConfigurations =
class: hosts:
mapAttrs (
name: value:
if class == "nixos" then
nixosSystem {
specialArgs = {
inherit inputs;
hostName = name;
};
modules = [
(flattenAttrs cfg.modules.nixos)
(value.extraCfg or { })
];
}
else
{ }
) hosts;
in
{
flake.nixosConfigurations = mkConfigurations "nixos" hosts.nixos;
}