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