first commit
This commit is contained in:
commit
2a3ea31491
52 changed files with 2991 additions and 0 deletions
49
modules/model-downloads.nix
Normal file
49
modules/model-downloads.nix
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modelDownloads;
|
||||
|
||||
script = pkgs.writeShellScript "download-models" ''
|
||||
set -eu
|
||||
mkdir -p "${cfg.dir}"
|
||||
|
||||
for url in ${lib.concatStringsSep " " (map lib.escapeShellArg cfg.urls)}; do
|
||||
name="$(basename "$url")"
|
||||
out="${cfg.dir}/$name"
|
||||
|
||||
if [ -f "$out" ]; then
|
||||
echo "OK: $name already exists"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Downloading $name"
|
||||
tmp="$out.part"
|
||||
${pkgs.curl}/bin/curl -L --fail --retry 3 --retry-delay 2 -o "$tmp" "$url"
|
||||
mv -f "$tmp" "$out"
|
||||
done
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.modelDownloads = {
|
||||
enable = lib.mkEnableOption "Download model files into a persistent directory";
|
||||
|
||||
dir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/data/ai/models";
|
||||
};
|
||||
|
||||
urls = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
description = "List of direct download URLs (filenames are taken from the URL).";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home.packages = [ pkgs.curl ];
|
||||
|
||||
home.activation.modelDownloads = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
${script}
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue