From 37d4634ee0a7d9d6fca45a9ea6035fa50ae8fea3 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Thu, 28 Oct 2021 15:01:50 -0400 Subject: [PATCH] restructure hosts directory --- hosts/cube/default.nix | 4 -- hosts/hp/default.nix | 4 -- hosts/nixdev/default.nix | 4 -- hosts/slate/default.nix | 4 -- .../cube/default.nix} | 0 .../hp/default.nix} | 0 .../nixdev/default.nix} | 0 .../slate/default.nix} | 0 lib/hosts.nix | 42 ++++++++++++------- 9 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 hosts/cube/default.nix delete mode 100644 hosts/hp/default.nix delete mode 100644 hosts/nixdev/default.nix delete mode 100644 hosts/slate/default.nix rename hosts/{cube/configuration.nix => x86_64-linux/cube/default.nix} (100%) rename hosts/{hp/configuration.nix => x86_64-linux/hp/default.nix} (100%) rename hosts/{nixdev/configuration.nix => x86_64-linux/nixdev/default.nix} (100%) rename hosts/{slate/configuration.nix => x86_64-linux/slate/default.nix} (100%) diff --git a/hosts/cube/default.nix b/hosts/cube/default.nix deleted file mode 100644 index cb764cd..0000000 --- a/hosts/cube/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ - system = "x86_64-linux"; - module = ./configuration.nix; -} diff --git a/hosts/hp/default.nix b/hosts/hp/default.nix deleted file mode 100644 index cb764cd..0000000 --- a/hosts/hp/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ - system = "x86_64-linux"; - module = ./configuration.nix; -} diff --git a/hosts/nixdev/default.nix b/hosts/nixdev/default.nix deleted file mode 100644 index cb764cd..0000000 --- a/hosts/nixdev/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ - system = "x86_64-linux"; - module = ./configuration.nix; -} diff --git a/hosts/slate/default.nix b/hosts/slate/default.nix deleted file mode 100644 index cb764cd..0000000 --- a/hosts/slate/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ - system = "x86_64-linux"; - module = ./configuration.nix; -} diff --git a/hosts/cube/configuration.nix b/hosts/x86_64-linux/cube/default.nix similarity index 100% rename from hosts/cube/configuration.nix rename to hosts/x86_64-linux/cube/default.nix diff --git a/hosts/hp/configuration.nix b/hosts/x86_64-linux/hp/default.nix similarity index 100% rename from hosts/hp/configuration.nix rename to hosts/x86_64-linux/hp/default.nix diff --git a/hosts/nixdev/configuration.nix b/hosts/x86_64-linux/nixdev/default.nix similarity index 100% rename from hosts/nixdev/configuration.nix rename to hosts/x86_64-linux/nixdev/default.nix diff --git a/hosts/slate/configuration.nix b/hosts/x86_64-linux/slate/default.nix similarity index 100% rename from hosts/slate/configuration.nix rename to hosts/x86_64-linux/slate/default.nix diff --git a/lib/hosts.nix b/lib/hosts.nix index 96cb1a3..2db90eb 100644 --- a/lib/hosts.nix +++ b/lib/hosts.nix @@ -1,20 +1,34 @@ { path, nixpkgs, nixosModule }: let - hostMetadata = builtins.mapAttrs - (name: _: import (path + "/${name}")) - (builtins.readDir path); + inherit (builtins) mapAttrs attrValues attrNames readDir foldl' listToAttrs; - getHostConfig = hostName: hostMeta: - nixpkgs.lib.nixosSystem - { - inherit (hostMeta) system; - modules = [ - (nixosModule) - (hostMeta.module) - (_: { networking.hostName = hostName; }) - ]; - }; + # grab a list of systems, with associated hostnames + # { x86_64-linux = [ "host1" "host2" ]; } + sysToHosts = mapAttrs + (system: _: attrNames (readDir "${path}/${system}")) + (readDir path); + + # invert the attrset, from {sys=[name]} to {name=sys} + # { host1 = "x86_64-linux"; host2 = "x86_64-linux"; } + hostToSys = foldl' (a: b: a // b) { } + (attrValues + (mapAttrs + (system: hosts: listToAttrs (map (name: { inherit name; value = system; }) hosts)) + sysToHosts)); + + # build system configurations + # { host1 = ; host2 = ; } + hostToConfig = mapAttrs + (hostName: system: nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + (nixosModule) + ("${path}/${system}/${hostName}") + (_: { networking.hostName = hostName; }) + ]; + }) + hostToSys; in -builtins.mapAttrs getHostConfig hostMetadata +hostToConfig