Skip to main content
added 882 characters in body; edited title
Source Link
Charles Duffy
  • 1.9k
  • 18
  • 22

"bash: cannot execute binary file" during nix DockerdockerTools cross-build from MacOS host

 

How can I run this downIncidentally, the same thing also happens with the following one-liner, taken from an answer to StackOverflow question How to build a Docker container with Nix?, also using dockerTools:

$ nix-build -j 1 --system x86_64-linux -E 'with import <nixpkgs> {}; pkgs.dockerTools.buildImage { name = "nix-htop"; contents = pkgs.htop; config = { Cmd = [ "/bin/htop" ]; }; }'

...fails similarly:

building path(s) ‘/nix/store/gz4lrsjcmxbcmdfpmazwz0wqnb5pbw8k-nix-htop-config.json’
/nix/store/nkq0n2m4shlbdvdq0qijib5zyzgmn0vq-bash-4.4-p12/bin/bash: /nix/store/nkq0n2m4shlbdvdq0qijib5zyzgmn0vq-bash-4.4-p12/bin/bash: cannot execute binary file
builder for ‘/nix/store/487mmw8kql56q7h6iq4c7hfzh4k0gv50-nix-htop-config.json.drv’ failed with exit code 126

Is dockerTools the common thread here?

"bash: cannot execute binary file" during nix Docker cross-build from MacOS host

How can I run this down?

"bash: cannot execute binary file" during nix dockerTools cross-build from MacOS host

 

Incidentally, the same thing also happens with the following one-liner, taken from an answer to StackOverflow question How to build a Docker container with Nix?, also using dockerTools:

$ nix-build -j 1 --system x86_64-linux -E 'with import <nixpkgs> {}; pkgs.dockerTools.buildImage { name = "nix-htop"; contents = pkgs.htop; config = { Cmd = [ "/bin/htop" ]; }; }'

...fails similarly:

building path(s) ‘/nix/store/gz4lrsjcmxbcmdfpmazwz0wqnb5pbw8k-nix-htop-config.json’
/nix/store/nkq0n2m4shlbdvdq0qijib5zyzgmn0vq-bash-4.4-p12/bin/bash: /nix/store/nkq0n2m4shlbdvdq0qijib5zyzgmn0vq-bash-4.4-p12/bin/bash: cannot execute binary file
builder for ‘/nix/store/487mmw8kql56q7h6iq4c7hfzh4k0gv50-nix-htop-config.json.drv’ failed with exit code 126

Is dockerTools the common thread here?

deleted 1001 characters in body
Source Link
Charles Duffy
  • 1.9k
  • 18
  • 22
$ nix-build -j 1 --system x86_64-linux redis-small.nix
these derivations will be built:
  /nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv
  /nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv
  /nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv
  /nix/store/l0p201r6zjfzsznfb6ykca1l8n09lyb9-vm-run.drv
  /nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv
  /nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv
  /nix/store/12ahsincv8igv492gzjjvw9s8aaff65i-runtime-deps.drv
  /nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv
these paths will be fetched (1.08 MiB download, 6.95 MiB unpacked):
  /nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11
  /nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin
copying path '/nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11' from 'https://cache.nixos.org'...
building '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv'...
building '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-runjsydsrzs7h9pfnh8m6cxaysa9bafmp2z-asredis-root.sh.drv'..config.
building '/nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2json.drv'...
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
builder for '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv' failed with exit code 126
builder for '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-runjsydsrzs7h9pfnh8m6cxaysa9bafmp2z-asredis-rootconfig.shjson.drv' failed with exit code 126
cannot build derivation '/nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv': 1 dependencies couldn't be built
error: build of '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv' failed
$ nix-build --system x86_64-linux redis-small.nix
these derivations will be built:
  /nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv
  /nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv
  /nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv
  /nix/store/l0p201r6zjfzsznfb6ykca1l8n09lyb9-vm-run.drv
  /nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv
  /nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv
  /nix/store/12ahsincv8igv492gzjjvw9s8aaff65i-runtime-deps.drv
  /nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv
these paths will be fetched (1.08 MiB download, 6.95 MiB unpacked):
  /nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11
  /nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin
copying path '/nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11' from 'https://cache.nixos.org'...
building '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv'...
building '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv'...
building '/nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv'...
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
builder for '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv' failed with exit code 126
builder for '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv' failed with exit code 126
cannot build derivation '/nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv': 1 dependencies couldn't be built
error: build of '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv' failed
$ nix-build -j 1 --system x86_64-linux redis-small.nix
these derivations will be built:
  /nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv
  /nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv
  /nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv
  /nix/store/l0p201r6zjfzsznfb6ykca1l8n09lyb9-vm-run.drv
  /nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv
  /nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv
  /nix/store/12ahsincv8igv492gzjjvw9s8aaff65i-runtime-deps.drv
  /nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv
building '/nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv'...
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
builder for '/nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv' failed with exit code 126
cannot build derivation '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv': 1 dependencies couldn't be built
error: build of '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv' failed
Source Link
Charles Duffy
  • 1.9k
  • 18
  • 22

"bash: cannot execute binary file" during nix Docker cross-build from MacOS host

A great 2016 blog post described building minimal Docker images with Nix. The below is a simple example taken from that blog post, modified to support Nix 2.0:

{ pkgs ? import <nixpkgs> {} }:

with pkgs;
dockerTools.buildImage {
  name = "redis";
  runAsRoot = ''
    #!${stdenv.shell}
    ${dockerTools.shadowSetup}
    groupadd -r redis
    useradd -r -g redis -d /data -M redis
    mkdir /data
    chown redis:redis /data
  '';

  config = {
    Cmd = [ "${gosu.bin}/bin/gosu" "redis" "${redis}/bin/redis-server" ];
    ExposedPorts = {
      "6379/tcp" = {};
    };
    WorkingDir = "/data";
    Volumes = {
      "/data" = {};
    };
  };
}

Using nix-linuxkit to have an x86_64-linux builder, this fails with an error about a bash executable which can't be run:

$ nix-build --system x86_64-linux redis-small.nix
these derivations will be built:
  /nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv
  /nix/store/jsydsrzs7h9pfnh8m6cxaysa9bafmp2z-redis-config.json.drv
  /nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv
  /nix/store/l0p201r6zjfzsznfb6ykca1l8n09lyb9-vm-run.drv
  /nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv
  /nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv
  /nix/store/12ahsincv8igv492gzjjvw9s8aaff65i-runtime-deps.drv
  /nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv
these paths will be fetched (1.08 MiB download, 6.95 MiB unpacked):
  /nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11
  /nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin
copying path '/nix/store/lfvghb4aqj9h1ja1k1z0y669jfnb0mvp-gosu-2017-05-09-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/1cyg1n1rj1nm3ar6dpzlscqgrnqsh5z8-redis-4.0.11' from 'https://cache.nixos.org'...
building '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv'...
building '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv'...
building '/nix/store/csfmyw6va3b8dabshliqjkrrdr6n090w-vm-run-stage2.drv'...
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
/nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file
builder for '/nix/store/iixmgfhsczc71484vcwqwz2nzlg0rcv1-extra-commands.sh.drv' failed with exit code 126
builder for '/nix/store/s64kqfyggqm60l5j9wy6s1nz39iwkxiw-run-as-root.sh.drv' failed with exit code 126
cannot build derivation '/nix/store/zidg0xphc7yjc4n0w3k7wnifz6rlqgzh-docker-layer-redis.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv': 1 dependencies couldn't be built
error: build of '/nix/store/pyx4q2wln2shlnjdp5ng43aqd6iba80d-docker-image-redis.tar.gz.drv' failed

The key line here is /nix/store/6v88ick1cxnn5g91m8qrrqww0lrlr27x-bash-4.4-p23/bin/bash: cannot execute binary file. Using file to inspect that, it's genuinely a Linux ELF binary.

How can I run this down?