refactor hosts/default.nix

This commit is contained in:
Sean Buckley 2021-04-11 16:41:49 -04:00
parent 818011e3e8
commit 01851cb48e

View file

@ -3,43 +3,38 @@ let
hostMetadata = hostMetadata =
let let
inherit (builtins) readDir concatMap attrNames; fs = builtins.readDir ./.;
fs = readDir ./.; inherit (builtins) concatMap attrNames;
hostNames = concatMap (x: if fs.${x} == "directory" then [ x ] else [ ]) (attrNames fs); hostNames = concatMap (x: if fs.${x} == "directory" then [ x ] else [ ]) (attrNames fs);
in in
map builtins.listToAttrs (map
(hn: { name = hn; inherit (import (./. + "/${hn}")) hardware pkgs system; }) (hn: { name = hn; value = import (./. + "/${hn}"); })
hostNames; hostNames);
hardwareModule = { pkgs, hardware }: ( hardwareModule = hardware: (
{ {
qemu = (x: { imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; }); qemu = (x: { imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; });
physical = pkgs.nixosModules.notDetected; physical = (x: { imports = [ "${x.modulesPath}/installer/scan/not-detected.nix" ]; });
} }
).${hardware}; ).${hardware};
in in
builtins.listToAttrs ( builtins.mapAttrs
map (n: v:
(h: let pkgs = { inherit unstable stable2009; }.${v.pkgs};
let pkgs = { inherit unstable stable2009; }.${h.pkgs}; in
in pkgs.lib.nixosSystem {
{ inherit (v) system;
name = h.name; modules = [
value = pkgs.lib.nixosSystem { (sconfig)
system = h.system; (./. + "/${n}/configuration.nix")
modules = [ (hardwareModule v.hardware)
(sconfig) ({ ... }: {
(./. + "/${h.name}/configuration.nix") networking.hostName = n;
(hardwareModule { inherit pkgs; inherit (h) hardware; }) sconfig.flakes.enable = true;
({ ... }: { sconfig.flakes.rebuildPath = "github:buckley310/nixos-config";
networking.hostName = h.name; })
sconfig.flakes.enable = true; ];
sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; }
}) )
]; hostMetadata
};
}
)
hostMetadata
)