refactor getHosts

This commit is contained in:
Sean Buckley 2021-08-22 20:42:09 -04:00
parent 5e186adc86
commit 773b17cf07
2 changed files with 12 additions and 8 deletions

View file

@ -3,7 +3,7 @@
inputs.unstable.url = "nixpkgs/nixos-unstable"; inputs.unstable.url = "nixpkgs/nixos-unstable";
inputs.impermanence.url = "github:nix-community/impermanence"; inputs.impermanence.url = "github:nix-community/impermanence";
outputs = { self, nixpkgs, impermanence, ... }@inputs: outputs = { self, nixpkgs, unstable, impermanence, ... }:
let let
mypkgs = pkgs: mypkgs = pkgs:
{ {
@ -42,7 +42,11 @@
nixpkgs.overlays = [ (_: mypkgs) ]; nixpkgs.overlays = [ (_: mypkgs) ];
}; };
nixosConfigurations = self.lib.getHosts inputs ./hosts; nixosConfigurations = self.lib.getHosts {
path = ./hosts;
inherit nixpkgs unstable;
inherit (self) nixosModule;
};
lib = { lib = {
getHosts = import lib/hosts.nix; getHosts = import lib/hosts.nix;

View file

@ -1,9 +1,9 @@
callerInputs: hostsPath: { path, nixosModule, unstable, ... }@inputs:
let let
hostMetadata = builtins.mapAttrs hostMetadata = builtins.mapAttrs
(name: _: import (hostsPath + "/${name}")) (name: _: import (path + "/${name}"))
(builtins.readDir hostsPath); (builtins.readDir path);
hardwareModules = hardwareModules =
{ {
@ -19,17 +19,17 @@ let
}; };
getHostConfig = hostName: hostMeta: getHostConfig = hostName: hostMeta:
callerInputs.${hostMeta.pkgs}.lib.nixosSystem inputs.${hostMeta.pkgs}.lib.nixosSystem
{ {
inherit (hostMeta) system; inherit (hostMeta) system;
modules = [ modules = [
(callerInputs.self.nixosModule) (nixosModule)
(hostMeta.module) (hostMeta.module)
(hardwareModules.${hostMeta.hardware}) (hardwareModules.${hostMeta.hardware})
(_: { networking.hostName = hostName; }) (_: { networking.hostName = hostName; })
(_: { (_: {
nixpkgs.overlays = [ nixpkgs.overlays = [
(_: _: { unstable = callerInputs.unstable.legacyPackages.${hostMeta.system}; }) (_: _: { unstable = unstable.legacyPackages.${hostMeta.system}; })
]; ];
}) })
]; ];