abstracted host definitions in flake.nix

This commit is contained in:
2025-07-29 13:56:25 -04:00
parent bd1851f706
commit 44062a87b4
6 changed files with 150 additions and 391 deletions

17
lib/default.nix Normal file
View File

@@ -0,0 +1,17 @@
{ inputs, username, nixpkgsConfig ? { allowUnfree = true; } }:
let
mkHost = import ./mk_host.nix;
in
{
inherit mkHost;
foldHosts = hosts: inputs.nixpkgs.lib.foldl'
(acc: host:
let result = mkHost ({ inherit inputs username nixpkgsConfig; } // host);
in {
nixosConfigurations = acc.nixosConfigurations // result.nixosConfigurations;
homeConfigurations = acc.homeConfigurations // result.homeConfigurations;
})
{ nixosConfigurations = {}; homeConfigurations = {}; }
hosts;
}

60
lib/mk_host.nix Normal file
View File

@@ -0,0 +1,60 @@
{
inputs,
username,
nixpkgsConfig ? { allowUnfree = true; },
host,
hostDir,
system ? "x86_64-linux",
kind,
extraNixosModules ? [],
extraHomeModules ? [],
overlay ? true
}:
let
nixosModules = [
../hosts/${hostDir}/config.nix
../modules/sys
inputs.stylix.nixosModules.stylix
] ++ extraNixosModules;
homeModules = [
../hosts/${hostDir}/home.nix
../modules/home
inputs.stylix.homeModules.stylix
inputs.nixvim.homeManagerModules.nixvim
] ++ extraHomeModules;
pkgs = import inputs.nixpkgs {
inherit system;
config = nixpkgsConfig;
overlays = if overlay then [
(import ../overlay/overlay.nix { inherit host; root = inputs.self; })
] else [];
};
specialArgs = {
inherit inputs username host;
self = inputs.self;
};
nixosCfg =
if kind == "nixos" || kind == "both" then
inputs.nixpkgs.lib.nixosSystem {
inherit system pkgs specialArgs;
modules = nixosModules;
}
else
null;
homeCfg =
if kind == "home" || kind == "both" then
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = specialArgs;
modules = homeModules;
}
else
null;
in
{
nixosConfigurations = if kind == "nixos" || kind == "both" then { ${host} = nixosCfg; } else {};
homeConfigurations = if kind == "home" || kind == "both" then { ${host + "Home"} = homeCfg; } else {};
}