NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.06k stars 14.04k forks source link

build environment variables size reaching ARG_MAX limit on musl #217075

Open yu-re-ka opened 1 year ago

yu-re-ka commented 1 year ago

Seen with tdesktop, and recently libreoffice-fresh, on x86_64-unknown-linux-musl.

musl has 128K ARG_MAX limit, darwin has 256K. Once these limits are reached (can check with printenv | wc -c), all find ... -exec will fail.

We are the only distro running into this, because our nix store path names (in PATH, etc.) bloat the environment variables size quite a bit.

After some discussions in musl irc, for musl-linux it would be possible to patch findutils to ignore the limit, since the kernel actually has a significantly higher limit (which is dynamically calculated relatively to the process stack size).

But even if we can use this workaround for musl, we might eventually run into this on darwin.

Artturin commented 1 year ago

structuredAttrs + https://github.com/NixOS/nixpkgs/pull/205183 will be a start to fixing this (Haven't checked if we need to or how we could remove nativeBuildInputs and buildInputs from attrs.sh and only have them in attrs.json)

yu-re-ka commented 1 year ago

structuredAttrs is a good hint, thanks! However currently seems to be not ready. NIX_CFLAGS_COMPILE is not correctly set with structuredAttrs, thus the build fails.

As a workaround, I have added these to my overlay:

  tdesktop = prev.tdesktop.overrideAttrs (oldAttrs: {
    # env variables get too big (>128K)
    preFixup = ''
      unset QT_ADDITIONAL_PACKAGES_PREFIX_PATH
      unset CMAKE_INCLUDE_PATH
      unset NIX_CFLAGS_COMPILE
    '';
  });

  libreoffice-fresh = prev.libreoffice-fresh.override {
    libreoffice = prev.libreoffice-fresh.libreoffice.overrideAttrs (oldAttrs: {
      [...]
      # env variables get too big (>128K)
      prePatch = ''
        unset postUnpack
      '' + (oldAttrs.prePatch or "");
    });
  };
Artturin commented 1 year ago

NIX_CFLAGS_COMPILE is not correctly set with structuredAttrs, thus the build fails.

https://github.com/NixOS/nixpkgs/pull/217206