Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockertools.buildLayeredImage fails with jq: Argument list too long #140908

Closed
koenw opened this issue Oct 8, 2021 · 6 comments · Fixed by #141050
Closed

dockertools.buildLayeredImage fails with jq: Argument list too long #140908

koenw opened this issue Oct 8, 2021 · 6 comments · Fixed by #141050
Labels
0.kind: bug Something is broken 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: docker tools

Comments

@koenw
Copy link
Contributor

koenw commented Oct 8, 2021

Describe the bug

dockertools.buildLayeredImage fails with /build/.attr-0: line 63: /nix/store/8v1x4xai13lj3q43b6ixgwgpvs66zmm3-jq-1.6-bin/bin/jq: Argument list too long when building an image with many layers. jq is used to build a JSON containing the image layers, and those layers are passed to jq through the command line. At some point we're passing the max allowed argument list length resulting in the error.

Steps To Reproduce

Steps to reproduce the behavior:
1.

cat > docker.nix <<EOF
{ pkgs ? import <nixpkgs> {} }:

pkgs.dockerTools.buildLayeredImage {
  name = "dockertools-test";
  tag = "latest";
  contents = [
    pkgs.texlive.combined.scheme-full
  ];
}
EOF
  1. nix-build docker.nix

Expected behavior

A docker image is build successfully.

Notify maintainers

@utdemir

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.63, NixOS, 21.05.3509.7daf35532d2 (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.15`
 - channels(root): `"nixos-21.05.3509.7daf35532d2, nixpkgs-21.05, unstable-21.11pre321003.14aef06d9b3"`
 - nixpkgs: `/home/koen/.nix-defexpr/channels_root/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: 
# a list of nixos modules affected by the problem
module:
@koenw koenw added the 0.kind: bug Something is broken label Oct 8, 2021
@roberth
Copy link
Member

roberth commented Oct 8, 2021

Does this also happen with #122608?

@koenw
Copy link
Contributor Author

koenw commented Oct 9, 2021

It does not happen with #122608.

I created a patch (before I read your comment) to pass the layers via the store instead via the command line. I noticed #122608 does the same, except using the discouraged--argfile instead of --slurpfile.

I submitted the patch anyway so we can fix this without waiting for #122608 to land.

@roberth
Copy link
Member

roberth commented Oct 9, 2021

Don't worry about the potential conflict.

If you have that many layers, you'll probably benefit from #141050. Would you be interested in contributing to that?

@koenw
Copy link
Contributor Author

koenw commented Oct 9, 2021

If you have that many layers, you'll probably benefit from #141050. Would you be interested in contributing to that?

I thought so too, that's why I submitted it ;)

@roberth
Copy link
Member

roberth commented Oct 9, 2021

Oh 😆 copy paste error. I intended to ask about #122608.

@stale
Copy link

stale bot commented Apr 16, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 16, 2022
koenw added a commit to koenw/nixpkgs that referenced this issue Oct 13, 2022
When building a docker image using `dockertools.buildLayeredImage`, the
resulting image layers are passed to `jq` through the command line. When
building an image with too many layers this would exceed the maximum
command line argument length.

Hence, we store the list of layers in the Nix store and pass them to
`jq` as a file argument using `--slurpfile`.

Fixes NixOS#140908.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: docker tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants