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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
{
lib,
stdenv,
coreutils,
jq,
python3,
nix,
xz,
zstd,
}:
# This function is for creating a flat-file binary cache, i.e. the kind created by
# nix copy --to file:///some/path and usable as a substituter (with the file:// prefix).
# For example, in the Nixpkgs repo:
# nix-build -E 'with import ./. {}; mkBinaryCache { rootPaths = [hello]; }'
{
name ? "binary-cache",
compression ? "zstd", # one of ["none" "xz" "zstd"]
rootPaths,
}:
assert lib.elem compression [
"none"
"xz"
"zstd"
];
stdenv.mkDerivation {
inherit name;
__structuredAttrs = true;
exportReferencesGraph.closure = rootPaths;
preferLocalBuild = true;
nativeBuildInputs = [
coreutils
jq
python3
nix
]
++ lib.optional (compression == "xz") xz
++ lib.optional (compression == "zstd") zstd;
buildCommand = ''
mkdir -p $out/nar
python ${./make-binary-cache.py} --compression "${compression}"
# These directories must exist, or Nix might try to create them in LocalBinaryCacheStore::init(),
# which fails if mounted read-only
mkdir $out/realisations
mkdir $out/debuginfo
mkdir $out/log
'';
}
|