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 {
name = h.name; inherit (v) system;
value = pkgs.lib.nixosSystem {
system = h.system;
modules = [ modules = [
(sconfig) (sconfig)
(./. + "/${h.name}/configuration.nix") (./. + "/${n}/configuration.nix")
(hardwareModule { inherit pkgs; inherit (h) hardware; }) (hardwareModule v.hardware)
({ ... }: { ({ ... }: {
networking.hostName = h.name; networking.hostName = n;
sconfig.flakes.enable = true; sconfig.flakes.enable = true;
sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; sconfig.flakes.rebuildPath = "github:buckley310/nixos-config";
}) })
]; ];
};
} }
) )
hostMetadata hostMetadata
)