5c370c0b2a
GitOrigin-RevId: 33d1e753c82ffc557b4a585c77de43d4c922ebb5
30 lines
1.1 KiB
Nix
30 lines
1.1 KiB
Nix
{ lib
|
|
, writers
|
|
, writeText
|
|
, linkFarmFromDrvs
|
|
}: {
|
|
genModels = configs:
|
|
let
|
|
name = lib.strings.sanitizeDerivationName
|
|
(builtins.concatStringsSep "_" ([ "local-ai-models" ] ++ (builtins.attrNames configs)));
|
|
|
|
genModelFiles = name: config:
|
|
let
|
|
templateName = type: name + "_" + type;
|
|
|
|
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;
|
|
});
|
|
in
|
|
[ (writers.writeYAML "${name}.yaml" config') ]
|
|
++ lib.optional (lib.isDerivation config.parameters.model)
|
|
config.parameters.model
|
|
++ lib.optionals (config ? template)
|
|
(lib.mapAttrsToList (n: writeText "${templateName n}.tmpl") config.template);
|
|
in
|
|
linkFarmFromDrvs name (lib.flatten (lib.mapAttrsToList genModelFiles configs));
|
|
}
|