From 1bdbed129efeb74dea708e793f24d3f8dc68f283 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Sat, 17 Aug 2024 23:38:53 +0200 Subject: [PATCH] Refactor host entrypoints again --- flake/hosts.nix | 56 +++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/flake/hosts.nix b/flake/hosts.nix index 7f307ca..6d50b23 100644 --- a/flake/hosts.nix +++ b/flake/hosts.nix @@ -1,30 +1,36 @@ -{ inputs, self, ... }: +{ + inputs, + self, + lib, + ... +}: let - specialArgs = { - inherit inputs self; + unstable = inputs.nixpkgs; + stable = inputs.nixpkgs-stable; + + mkHost = hostname: nixpkgs: { + ${hostname} = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs self; + }; + modules = + [ + { networking.hostName = hostname; } + "${self}/hosts/${hostname}" + ] + ++ builtins.filter (path: builtins.pathExists path) ( + map (user: "${self}/users/${user}/@${hostname}") ( + builtins.attrNames (lib.filterAttrs (_: v: v == "directory") (builtins.readDir "${self}/users")) + ) + ); + }; }; - modulesOf = hostname: [ - { networking.hostName = hostname; } - "${self}/hosts/${hostname}" - "${self}/users/seb/@${hostname}" - ]; + in { - flake.nixosConfigurations = { - north = inputs.nixpkgs.lib.nixosSystem { - inherit specialArgs; - modules = modulesOf "north"; - }; - inspiron = inputs.nixpkgs.lib.nixosSystem { - inherit specialArgs; - modules = modulesOf "inspiron"; - }; - installer = inputs.nixpkgs-stable.lib.nixosSystem { - inherit specialArgs; - modules = [ - { networking.hostName = "installer"; } - "${self}/hosts/installer" - ]; - }; - }; + flake.nixosConfigurations = lib.mkMerge [ + (mkHost "north" unstable) + (mkHost "inspiron" unstable) + (mkHost "installer" stable) + ]; }