restructure hosts directory

This commit is contained in:
Sean Buckley 2021-10-28 15:01:50 -04:00
parent c7aef83e9f
commit 37d4634ee0
9 changed files with 28 additions and 30 deletions

View file

@ -1,4 +0,0 @@
{
system = "x86_64-linux";
module = ./configuration.nix;
}

View file

@ -1,4 +0,0 @@
{
system = "x86_64-linux";
module = ./configuration.nix;
}

View file

@ -1,4 +0,0 @@
{
system = "x86_64-linux";
module = ./configuration.nix;
}

View file

@ -1,4 +0,0 @@
{
system = "x86_64-linux";
module = ./configuration.nix;
}

View file

@ -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;
# 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 = <nixosConfiguration>; host2 = <nixosConfiguration>; }
hostToConfig = mapAttrs
(hostName: system: nixpkgs.lib.nixosSystem {
inherit system;
modules = [
(nixosModule)
(hostMeta.module)
("${path}/${system}/${hostName}")
(_: { networking.hostName = hostName; })
];
};
})
hostToSys;
in
builtins.mapAttrs getHostConfig hostMetadata
hostToConfig