Unverified Commit 6ea4ff60 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

mkBinaryCache: support zstd and none as compression methods (#376365)

parents 9fdbbc56 00a218ab
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -11,6 +11,14 @@ It can also be a convenient way to make some Nix packages available inside a con
`rootPaths` must be a list of derivations.
The transitive closure of these derivations' outputs will be copied into the cache.

## Optional arguments {#sec-pkgs-binary-cache-arguments}

`compression` (`"none"` or `"xz"` or `"zstd"`; _optional_)

: The compression algorithm to use.

  _Default value:_ `zstd`.

::: {.note}
This function is meant for advanced use cases.
The more idiomatic way to work with flat-file binary caches is via the [nix-copy-closure](https://nixos.org/manual/nix/stable/command-ref/nix-copy-closure.html) command.
+3 −0
Original line number Diff line number Diff line
@@ -1971,6 +1971,9 @@
  "sec-pkgs-binary-cache": [
    "index.html#sec-pkgs-binary-cache"
  ],
  "sec-pkgs-binary-cache-arguments": [
    "index.html#sec-pkgs-binary-cache-arguments"
  ],
  "sec-pkgs-binary-cache-example": [
    "index.html#sec-pkgs-binary-cache-example"
  ],
+3 −1
Original line number Diff line number Diff line
@@ -196,7 +196,9 @@ in {
  beanstalkd = handleTest ./beanstalkd.nix {};
  bees = handleTest ./bees.nix {};
  benchexec = handleTest ./benchexec.nix {};
  binary-cache = handleTest ./binary-cache.nix {};
  binary-cache = handleTest ./binary-cache.nix { compression = "zstd"; };
  binary-cache-no-compression = handleTest ./binary-cache.nix { compression = "none"; };
  binary-cache-xz = handleTest ./binary-cache.nix { compression = "xz"; };
  bind = handleTest ./bind.nix {};
  bird = handleTest ./bird.nix {};
  birdwatcher = handleTest ./birdwatcher.nix {};
+10 −3
Original line number Diff line number Diff line
{ compression, ... }@args:

import ./make-test-python.nix (
  { lib, pkgs, ... }:

  {
    name = "binary-cache";
    name = "binary-cache-" + compression;
    meta.maintainers = with lib.maintainers; [ thomasjm ];

    nodes.machine =
@@ -24,7 +26,12 @@ import ./make-test-python.nix (
              nativeBuildInputs = [ openssl ];
            }
            ''
              tar -czf tmp.tar.gz -C "${mkBinaryCache { rootPaths = [ hello ]; }}" .
              tar -czf tmp.tar.gz -C "${
                mkBinaryCache {
                  rootPaths = [ hello ];
                  inherit compression;
                }
              }" .
              openssl enc -aes-256-cbc -salt -in tmp.tar.gz -out $out -k mysecretpassword
            '';

@@ -78,4 +85,4 @@ import ./make-test-python.nix (
      machine.succeed("[ -d %s ] || exit 1" % storePath)
    '';
  }
)
) args
+18 −8
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
  python3,
  nix,
  xz,
  zstd,
}:

# This function is for creating a flat-file binary cache, i.e. the kind created by
@@ -16,9 +17,16 @@

{
  name ? "binary-cache",
  compression ? "zstd", # one of ["none" "xz" "zstd"]
  rootPaths,
}:

assert lib.elem compression [
  "none"
  "xz"
  "zstd"
];

stdenv.mkDerivation {
  inherit name;

@@ -28,18 +36,20 @@ stdenv.mkDerivation {

  preferLocalBuild = true;

  nativeBuildInputs = [
  nativeBuildInputs =
    [
      coreutils
      jq
      python3
      nix
    xz
  ];
    ]
    ++ lib.optional (compression == "xz") xz
    ++ lib.optional (compression == "zstd") zstd;

  buildCommand = ''
    mkdir -p $out/nar

    python ${./make-binary-cache.py}
    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
Loading