2024-10-04 16:56:33 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
writers,
|
|
|
|
writeText,
|
|
|
|
linkFarmFromDrvs,
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
genModels =
|
|
|
|
configs:
|
2024-05-15 15:35:15 +00:00
|
|
|
let
|
2024-10-04 16:56:33 +00:00
|
|
|
name = lib.strings.sanitizeDerivationName (
|
|
|
|
builtins.concatStringsSep "_" ([ "local-ai-models" ] ++ (builtins.attrNames configs))
|
|
|
|
);
|
2024-05-15 15:35:15 +00:00
|
|
|
|
2024-10-04 16:56:33 +00:00
|
|
|
genModelFiles =
|
|
|
|
name: config:
|
2024-05-15 15:35:15 +00:00
|
|
|
let
|
|
|
|
templateName = type: name + "_" + type;
|
|
|
|
|
2024-10-04 16:56:33 +00:00
|
|
|
config' = lib.recursiveUpdate config (
|
|
|
|
{
|
|
|
|
inherit name;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (lib.isDerivation config.parameters.model) {
|
|
|
|
parameters.model = config.parameters.model.name;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (config ? template) {
|
|
|
|
template = builtins.mapAttrs (n: _: templateName n) config.template;
|
|
|
|
}
|
|
|
|
);
|
2024-05-15 15:35:15 +00:00
|
|
|
in
|
|
|
|
[ (writers.writeYAML "${name}.yaml" config') ]
|
2024-10-04 16:56:33 +00:00
|
|
|
++ lib.optional (lib.isDerivation config.parameters.model) config.parameters.model
|
|
|
|
++ lib.optionals (config ? template) (
|
|
|
|
lib.mapAttrsToList (n: writeText "${templateName n}.tmpl") config.template
|
|
|
|
);
|
2024-05-15 15:35:15 +00:00
|
|
|
in
|
|
|
|
linkFarmFromDrvs name (lib.flatten (lib.mapAttrsToList genModelFiles configs));
|
|
|
|
}
|