-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-dvc-dir.nix
44 lines (43 loc) · 976 Bytes
/
fetch-dvc-dir.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{ callPackage, stdenv, writeShellScript, fetch-dvc-file, fetch-md5-file, lib }:
{ baseurl
, md5
, name
, hash ? null
}:
let
dir-md5 = lib.removeSuffix ".dir" md5;
output = fetch-dvc-file {
inherit baseurl name hash;
md5 = dir-md5;
extension = ".dir";
};
files = builtins.fromJSON (builtins.readFile output);
fetch-file = file: {
relpath = file.relpath;
md5 = file.md5;
content = fetch-dvc-file {
inherit baseurl hash;
md5 = file.md5;
name = file.md5;
};
};
fetched = map fetch-file files;
linkFiles = builtins.concatStringsSep "\n" (map
(output: ''
mkdir -p "$(dirname "$out/${output.relpath}")"
ln -s "${output.content}" "$out/${output.relpath}"
'')
fetched);
linkFilesScript = writeShellScript "fetch-dvc.sh" ''
set -e
${linkFiles}
'';
in
stdenv.mkDerivation {
name = name;
phases = [ "installPhase" ];
installPhase = ''
mkdir "$out"
${linkFilesScript}
'';
}