nixos-config/config/hosts.nix

17 lines
589 B
Nix

{ config, lib, pkgs, ... }:
with lib;
let
is-nix-file = filename: type: (builtins.match ".+\.nix$" filename) != null;
is-regular-file = filename: type: type == "regular" || type == "link";
hostname-from-file = filename: builtins.replaceStrings [".nix"] [""] filename;
host-files = attrNames (filterAttrs is-nix-file (filterAttrs is-regular-file (builtins.readDir ./hosts)));
hosts = map hostname-from-file host-files;
load-host-file = hostname: import (./. + "/hosts/${hostname}.nix");
in {
config.fudo.hosts = genAttrs hosts (hostname: load-host-file hostname);
}