1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 09:49:36 +01:00

Merge pull request #14120 from lovesegfault/http-binary-cache-compression

feat(libstore/http-binary-cache-store): narinfo/ls/log compression
This commit is contained in:
Jörg Thalheim 2025-09-30 12:50:10 +02:00 committed by GitHub
commit bc66e131f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 246 additions and 76 deletions

View file

@ -4,6 +4,7 @@
#include "nix/store/nar-info-disk-cache.hh"
#include "nix/util/callback.hh"
#include "nix/store/store-registration.hh"
#include "nix/util/compression.hh"
namespace nix {
@ -142,8 +143,27 @@ protected:
const std::string & mimeType) override
{
auto req = makeRequest(path);
req.data = StreamToSourceAdapter(istream).drain();
auto data = StreamToSourceAdapter(istream).drain();
// Determine compression method based on file type
std::string compressionMethod;
if (hasSuffix(path, ".narinfo"))
compressionMethod = config->narinfoCompression;
else if (hasSuffix(path, ".ls"))
compressionMethod = config->lsCompression;
else if (hasPrefix(path, "log/"))
compressionMethod = config->logCompression;
// Apply compression if configured
if (!compressionMethod.empty()) {
data = compress(compressionMethod, data);
req.headers.emplace_back("Content-Encoding", compressionMethod);
}
req.data = std::move(data);
req.mimeType = mimeType;
try {
getFileTransfer()->upload(req);
} catch (FileTransferError & e) {

View file

@ -59,6 +59,21 @@ struct BinaryCacheStoreConfig : virtual StoreConfig
The meaning and accepted values depend on the compression method selected.
`-1` specifies that the default compression level should be used.
)"};
const Setting<std::string> narinfoCompression{
this, "", "narinfo-compression", "Compression method for `.narinfo` files."};
const Setting<std::string> lsCompression{this, "", "ls-compression", "Compression method for `.ls` files."};
const Setting<std::string> logCompression{
this,
"",
"log-compression",
R"(
Compression method for `log/*` files. It is recommended to
use a compression method supported by most web browsers
(e.g. `brotli`).
)"};
};
/**