From 01851cb48e1c20a38ed22c2fe0b55cd5c277cead Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Sun, 11 Apr 2021 16:41:49 -0400 Subject: [PATCH] refactor hosts/default.nix --- hosts/default.nix | 57 +++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/hosts/default.nix b/hosts/default.nix index ba63595..a41ec39 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -3,43 +3,38 @@ let hostMetadata = let - inherit (builtins) readDir concatMap attrNames; - fs = readDir ./.; + fs = builtins.readDir ./.; + inherit (builtins) concatMap attrNames; hostNames = concatMap (x: if fs.${x} == "directory" then [ x ] else [ ]) (attrNames fs); in - map - (hn: { name = hn; inherit (import (./. + "/${hn}")) hardware pkgs system; }) - hostNames; + builtins.listToAttrs (map + (hn: { name = hn; value = import (./. + "/${hn}"); }) + hostNames); - hardwareModule = { pkgs, hardware }: ( + hardwareModule = hardware: ( { qemu = (x: { imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; }); - physical = pkgs.nixosModules.notDetected; + physical = (x: { imports = [ "${x.modulesPath}/installer/scan/not-detected.nix" ]; }); } ).${hardware}; in -builtins.listToAttrs ( - map - (h: - let pkgs = { inherit unstable stable2009; }.${h.pkgs}; - in - { - name = h.name; - value = pkgs.lib.nixosSystem { - system = h.system; - modules = [ - (sconfig) - (./. + "/${h.name}/configuration.nix") - (hardwareModule { inherit pkgs; inherit (h) hardware; }) - ({ ... }: { - networking.hostName = h.name; - sconfig.flakes.enable = true; - sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; - }) - ]; - }; - } - ) - hostMetadata -) +builtins.mapAttrs + (n: v: + let pkgs = { inherit unstable stable2009; }.${v.pkgs}; + in + pkgs.lib.nixosSystem { + inherit (v) system; + modules = [ + (sconfig) + (./. + "/${n}/configuration.nix") + (hardwareModule v.hardware) + ({ ... }: { + networking.hostName = n; + sconfig.flakes.enable = true; + sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; + }) + ]; + } + ) + hostMetadata