1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

feat(libstore/http-binary-cache-store): narinfo/ls/log compression

This commit is contained in:
Bernardo Meurer Costa 2025-09-29 21:31:46 +00:00
parent b6f4788a8f
commit 689fa81dc9
No known key found for this signature in database
2 changed files with 36 additions and 1 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`).
)"};
};
/**