mirror of
https://github.com/buckley310/nixos-config.git
synced 2024-11-09 18:47:02 +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}"))
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue