mirror of
https://github.com/buckley310/nixos-config.git
synced 2024-12-21 19:24:15 +00:00
restructure hosts directory
This commit is contained in:
parent
c7aef83e9f
commit
37d4634ee0
9 changed files with 28 additions and 30 deletions
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
system = "x86_64-linux";
|
|
||||||
module = ./configuration.nix;
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
system = "x86_64-linux";
|
|
||||||
module = ./configuration.nix;
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
system = "x86_64-linux";
|
|
||||||
module = ./configuration.nix;
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
system = "x86_64-linux";
|
|
||||||
module = ./configuration.nix;
|
|
||||||
}
|
|
|
@ -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}"))
|
||||||
|
(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 = [
|
modules = [
|
||||||
(nixosModule)
|
(nixosModule)
|
||||||
(hostMeta.module)
|
("${path}/${system}/${hostName}")
|
||||||
(_: { networking.hostName = hostName; })
|
(_: { networking.hostName = hostName; })
|
||||||
];
|
];
|
||||||
};
|
})
|
||||||
|
hostToSys;
|
||||||
|
|
||||||
in
|
in
|
||||||
builtins.mapAttrs getHostConfig hostMetadata
|
hostToConfig
|
||||||
|
|
Loading…
Reference in a new issue