Skip to content

Use CompressionAlgo enum throughout #15020

Merged
Ericson2314 merged 3 commits intoNixOS:masterfrom
xokdvium:more-enum-compression
Jan 20, 2026
Merged

Use CompressionAlgo enum throughout #15020
Ericson2314 merged 3 commits intoNixOS:masterfrom
xokdvium:more-enum-compression

Conversation

@xokdvium
Copy link
Contributor

Motivation

Instead of the stringly typed code we should use an enum class, this is
more clear and less error-prone. Also adds settings implementations for
CompressionAlgo and std::optional. The first is used
for NAR compression, since we never accepted empty strings there:

error: unknown compression method ''

The other one is used for optional .narinfo, .ls, and log/ compression.
Those treated empty strings as compression being disabled. The same exact
semantics is kept.

This has the benefit of improving error messages for incorrect values:

error: option 'compression' has invalid value 'bz'
       Did you mean one of br, xz or lz4?

Also updates the documentation of the NAR compression to document that we actually support all algorithms natively supported by libarchive.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

… reality

The docs were out of date. Since 8a0c00b Nix
supports all compression algorithms exposed by libarchive (if it's built with
native support for them). Let's be honest about it in the docs.
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Jan 20, 2026
Instead of the stringly typed code we should use an enum class, this is
more clear and less error-prone. Also adds settings implementations for
CompressionAlgo and std::optional<CompressionAlgo>. The first is used
for NAR compression, since we never accepted empty strings there:

error: unknown compression method ''

The other one is used for optional .narinfo, .ls, and log/ compression.
Those treated empty strings as compression being disabled. The same exact
semantics is kept.

This has the benefit of improving error messages for incorrect values:

error: option 'compression' has invalid value 'bz'
       Did you mean one of br, xz or lz4?
@xokdvium xokdvium force-pushed the more-enum-compression branch from e70285d to 6ba0678 Compare January 20, 2026 01:36
auto info = mkInfo(narHashSink.finish());
auto narInfo = make_ref<NarInfo>(info);
narInfo->compression = config.compression;
narInfo->compression = config.compression.to_string(); // FIXME: Make NarInfo use CompressionAlgo
Copy link
Member

@Ericson2314 Ericson2314 Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
std::string url;
std::string compression;
std::string compression; // FIXME: Use CompressionAlgo
Copy link
Member

@Ericson2314 Ericson2314 Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ericson2314 Ericson2314 added this pull request to the merge queue Jan 20, 2026
Merged via the queue into NixOS:master with commit 67a99db Jan 20, 2026
13 checks passed
@xokdvium xokdvium deleted the more-enum-compression branch February 9, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants