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