1{
2 lib,
3 stdenv,
4 coreutils,
5 jq,
6 python3,
7 nix,
8 xz,
9}:
10
11# This function is for creating a flat-file binary cache, i.e. the kind created by
12# nix copy --to file:///some/path and usable as a substituter (with the file:// prefix).
13
14# For example, in the Nixpkgs repo:
15# nix-build -E 'with import ./. {}; mkBinaryCache { rootPaths = [hello]; }'
16
17{
18 name ? "binary-cache",
19 rootPaths,
20}:
21
22stdenv.mkDerivation {
23 inherit name;
24
25 __structuredAttrs = true;
26
27 exportReferencesGraph.closure = rootPaths;
28
29 preferLocalBuild = true;
30
31 nativeBuildInputs = [
32 coreutils
33 jq
34 python3
35 nix
36 xz
37 ];
38
39 buildCommand = ''
40 mkdir -p $out/nar
41
42 python ${./make-binary-cache.py}
43
44 # These directories must exist, or Nix might try to create them in LocalBinaryCacheStore::init(),
45 # which fails if mounted read-only
46 mkdir $out/realisations
47 mkdir $out/debuginfo
48 mkdir $out/log
49 '';
50}