runCommandLocal: bash Argument list too long

Hi Everybody,

I have a function like this:

  myConversion =
    builtins.fromJSON (
      builtins.readFile (
        runCommandLocal "myConversion"
            inherit x;
            some-command <<< $x

And so far it worked fine. You can replace for example some-command by yq and you get yaml->json conversion.

The problem is that recently the input string got too large and I get: error: executing '/nix/store/...-bash-5.2-p15/bin/bash': Argument list too long.

If I was only in Bash I could solve it by for example by cat /file | some-command or some-command --read /file but the problem is that the x input is already a string. It is not a file.

Could you please help me to solve this?

Thank you.

You can list the attribute name in passAsFile attribute and then it will be available as xPath variable.

1 Like

Thank you @jtojnar !

I’m googling passAsFile but I can’t find an example with runCommand. Does it mean that I need to use mkDerivation instead? Could you please link me to an example code?

Thank you again!

runCommand uses stdenv.mkDerivation internally, which uses Nix derivation internally.

1 Like

I recommend to use search on github. It’s very fast for a gigantic repo like nixpkgs:

1 Like