From 4edd18ad6cd4b6649fc4d9dae1de613c4d43bd55 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Sun, 21 Jul 2024 14:19:02 -0700 Subject: [PATCH] flake: compileHomes --- flake.nix | 43 +++++++++++++++++++------------------------ lib/builders.nix | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/flake.nix b/flake.nix index f7bfb03..4e78b41 100644 --- a/flake.nix +++ b/flake.nix @@ -57,29 +57,24 @@ system = "x86_64-linux"; } ]; - homeConfigurations."zynh@msiserver" = inputs.home-manager.lib.homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages."x86_64-linux"; - extraSpecialArgs = { inherit inputs; }; - - modules = [ - ./hosts/msiserver/home.nix - ]; - }; - homeConfigurations."val@caveserver" = inputs.home-manager.lib.homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages."x86_64-linux"; - extraSpecialArgs = { inherit inputs; }; - - modules = [ - ./hosts/caveserver/home.nix - ]; - }; - homeConfigurations."zynh@little-lightning" = inputs.home-manager.lib.homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages."aarch64-darwin"; - extraSpecialArgs = { inherit inputs; }; - - modules = [ - ./hosts/little-lightning/home.nix - ]; - }; + homeConfigurations = + builders.compileHomes + [ + { + user = "zynh"; + hostname = "msiserver"; + system = "x86_64-linux"; + } + { + user = "val"; + hostname = "caveserver"; + system = "x86_64-linux"; + } + { + user = "zynh"; + hostname = "little-lightning"; + system = "aarch64-darwin"; + } + ]; }; } diff --git a/lib/builders.nix b/lib/builders.nix index d35487e..0f69e95 100644 --- a/lib/builders.nix +++ b/lib/builders.nix @@ -24,4 +24,28 @@ rec { builtins.listToAttrs (map toPartialNixosConfig) systems; + + toPartialHomeManagerConfig = + { user, system, hostname ? "", configHostname ? "" }: + let + configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname; + hostStr = lib.strings.optionalString (builtins.stringLength hostname > 0) "@${hostname}"; + in + { + name = "${user}${hostStr}"; + value = inputs.home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages."${system}"; + extraSpecialArgs = { inherit inputs; }; + + modules = [ + ../hosts/${configHost}/home.nix + ]; + }; + }; + compileHomes = + systems: + lib.right + builtins.listToAttrs + (map toPartialHomeManagerConfig) + systems; }