53 lines
1.6 KiB
Nix
53 lines
1.6 KiB
Nix
# AUTOMATICALLY GENERATED by clan
|
|
# TODO: move this code to a flakeModule in clan-core and import it via flake input
|
|
{ self, lib, inputs, ... }:
|
|
let
|
|
evalConfig = import (self.inputs.nixpkgs + /lib/eval-config.nix);
|
|
|
|
evalMachine = machineModule: evalConfig {
|
|
modules = [ machineModule ];
|
|
};
|
|
|
|
machinesDirs =
|
|
if builtins.pathExists ./machines
|
|
then builtins.readDir ./machines
|
|
else { };
|
|
|
|
machineSettings = machineName:
|
|
if builtins.pathExists ./machines/${machineName}/settings.json
|
|
then (builtins.fromJSON (builtins.readFile ./machines/${machineName}/settings.json))
|
|
else { };
|
|
|
|
# load all clan modules by default
|
|
machineModule = machineName: {
|
|
imports =
|
|
(lib.attrValues inputs.clan.clanModules)
|
|
++ [ (machineSettings machineName) ];
|
|
};
|
|
|
|
# autoamtically generate machine modules for all directories under ./machines
|
|
machineModulesGenerated =
|
|
lib.flip lib.mapAttrs' machinesDirs (name: _: {
|
|
name = "machine-${name}";
|
|
value = machineModule name;
|
|
});
|
|
|
|
# re-read the machine modules from the flake outputs, to allow amchines being
|
|
# defined by custom mechanisms
|
|
machineModules =
|
|
lib.filterAttrs (name: _: lib.hasPrefix "machine-" name) self.nixosModules;
|
|
|
|
in
|
|
{
|
|
imports =
|
|
let
|
|
relPaths = builtins.fromJSON (builtins.readFile ./imports.json);
|
|
paths = map (path: ./. + path) relPaths;
|
|
in
|
|
paths;
|
|
flake.nixosModules = machineModulesGenerated;
|
|
# generate nixosConfigurations for all machines under self.nixosModules.machines-{machine_name}
|
|
flake.nixosConfigurations =
|
|
lib.mapAttrs (_: mod: evalMachine mod) machineModules;
|
|
}
|