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 }: { path, nixpkgs, nixosModule }:
let let
hostMetadata = builtins.mapAttrs inherit (builtins) mapAttrs attrValues attrNames readDir foldl' listToAttrs;
(name: _: import (path + "/${name}"))
(builtins.readDir path);
getHostConfig = hostName: hostMeta: # grab a list of systems, with associated hostnames
nixpkgs.lib.nixosSystem # { x86_64-linux = [ "host1" "host2" ]; }
{ sysToHosts = mapAttrs
inherit (hostMeta) system; (system: _: attrNames (readDir "${path}/${system}"))
modules = [ (readDir path);
(nixosModule)
(hostMeta.module) # invert the attrset, from {sys=[name]} to {name=sys}
(_: { networking.hostName = hostName; }) # { 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)
("${path}/${system}/${hostName}")
(_: { networking.hostName = hostName; })
];
})
hostToSys;
in in
builtins.mapAttrs getHostConfig hostMetadata hostToConfig