nixpkgs/pkgs/by-name/lo/local-ai/lib.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Nix
Raw Normal View History

2024-08-23 21:06:08 +00:00
{
lib,
writers,
writeText,
linkFarmFromDrvs,
}:
{
genModels =
configs:
2024-04-26 17:40:55 +00:00
let
2024-08-23 21:06:08 +00:00
name = lib.strings.sanitizeDerivationName (
builtins.concatStringsSep "_" ([ "local-ai-models" ] ++ (builtins.attrNames configs))
);
2024-04-26 17:40:55 +00:00
2024-08-23 21:06:08 +00:00
genModelFiles =
name: config:
2024-04-26 17:40:55 +00:00
let
templateName = type: name + "_" + type;
2024-08-23 21:06:08 +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-04-26 17:40:55 +00:00
in
[ (writers.writeYAML "${name}.yaml" config') ]
2024-08-23 21:06:08 +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-04-26 17:40:55 +00:00
in
linkFarmFromDrvs name (lib.flatten (lib.mapAttrsToList genModelFiles configs));
}