Getting "unable to initialise bzip2 encoder" error installing nix in nix-user-chroot

Hi,

I’m attempting to install nix using nix-user-chroot on Scientific Linux 7.5. When I run:

./nix-user-chroot ~/.nix curl https://nixos.org/nix/install | sh

I get:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2399  100  2399    0     0   8926      0 --:--:-- --:--:-- --:--:--  8951
downloading Nix 2.3.2 binary tarball for x86_64-linux from 'https://nixos.org/releases/nix/nix-2.3.2/nix-2.3.2-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.NWWN4VyzDy'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15.1M  100 15.1M    0     0  11.5M      0  0:00:01  0:00:01 --:--:-- 11.5M
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
performing a single-user installation of Nix...
copying Nix to /nix/store................................
GC Warning: Marker thread creation failed, errno = 12
GC Warning: Marker thread creation failed, errno = 12
installing 'nix-2.3.2'
error: unable to initialise bzip2 encoder

A bit of googling yields the source code that likely causes this error (link: src/libutil/compression.cc · bc7e3a4dd62baa99dbd1985d329a2a806d59a422 · nix / nix · GitLab ).

So, I thought it would be worth a quick check to see if there is something fundamentally wrong with my bzip libraries, but the following C program executes just fine:

#include <zlib.h>
#include <stdio.h>
#include<bzlib.h>
#include <stdint.h>
#include <string.h>

#define BUFSIZE 10000

uint8_t outbuf[BUFSIZE];
bz_stream strm;

int main() {
        memset(&strm, 0, sizeof(strm));
        int ret = BZ2_bzCompressInit(&strm, 9, 0, 30);

        if (ret != Z_OK) {
                printf("Not OK");
        }
}

(With cc test.c -lbz2; ./a.out, it doesn’t print anything)

Has anyone come across this error before? Regardless, does anyone have any ideas how to fix it?

I have now fixed this error. In my case, it was due to the system running out of memory.

The return values of BZ2_bzCompressInit are:

BZ_CONFIG_ERROR
if the library has been mis-compiled
BZ_PARAM_ERROR
if strm is NULL
or blockSize < 1 or blockSize > 9
or verbosity < 0 or verbosity > 4
or workFactor < 0 or workFactor > 250
BZ_MEM_ERROR
if not enough memory is available
BZ_OK
otherwise

(bzip2 and libbzip2, version 1.0.8)

So, given that my test showed that libbz2 was correctly compiled, out of memory is the only option. Moving to a machine without a per-process memory limit (ulimit -v) fixed this problem for me.