builders: refactor

This commit is contained in:
Zynh Ludwig 2024-08-01 00:46:04 -07:00
parent 69607cc38a
commit d7073b0472

View file

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