builders: refactor

main
Zynh Ludwig 2024-08-01 00:46:04 -07:00
parent 69607cc38a
commit d7073b0472
1 changed files with 14 additions and 11 deletions

View File

@ -2,13 +2,18 @@
let let
lib = nixpkgs.lib.extend (import ../lib); lib = nixpkgs.lib.extend (import ../lib);
inherit (inputs.home-manager.lib) homeManagerConfiguration;
inherit (nixpkgs.lib) nixosSystem;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) nameValuePair;
in in
rec { rec {
toPartialNixosConfig = toPartialNixosConfig =
{ hostname, system }: { hostname, system }:
{ nameValuePair
name = hostname; hostname
value = nixpkgs.lib.nixosSystem { (nixosSystem {
inherit system; inherit system;
specialArgs = { inherit inputs lib; }; specialArgs = { inherit inputs lib; };
modules = [ modules = [
@ -16,8 +21,7 @@ rec {
../hosts/${hostname}/configuration.nix ../hosts/${hostname}/configuration.nix
inputs.home-manager.nixosModules.default inputs.home-manager.nixosModules.default
]; ];
}; });
};
compileSystems = compileSystems =
systems: systems:
lib.right lib.right
@ -29,12 +33,12 @@ rec {
{ user, system, hostname ? "", configHostname ? "" }: { user, system, hostname ? "", configHostname ? "" }:
let let
configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname; configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname;
hostStr = lib.strings.optionalString (builtins.stringLength hostname > 0) "@${hostname}"; hostStr = optionalString (builtins.stringLength hostname > 0) "@${hostname}";
in in
assert lib.assertMsg (builtins.stringLength configHost > 0) "either configHostname or hostname need to exist"; assert lib.assertMsg (builtins.stringLength configHost > 0) "either configHostname or hostname need to exist";
{ nameValuePair
name = "${user}${hostStr}"; "${user}${hostStr}"
value = inputs.home-manager.lib.homeManagerConfiguration { (homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages."${system}"; pkgs = nixpkgs.legacyPackages."${system}";
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs; inherit inputs;
@ -44,8 +48,7 @@ rec {
modules = [ modules = [
../hosts/${configHost}/home.nix ../hosts/${configHost}/home.nix
]; ];
}; });
};
compileHomes = compileHomes =
systems: systems:
lib.right lib.right