Skip to content

Latest commit

 

History

History
63 lines (46 loc) · 1.44 KB

no-flags-spaces.md

File metadata and controls

63 lines (46 loc) · 1.44 KB

buildFlags and other similar attributes are passed around unquoted in stdenv. This means Bash will split them along $IFS when given as arguments to a program or when iterated over in a loop. The downside is that you cannot pass flags containing spaces to stdenv using these variables.

Bash also does not really interpret the values of variables passed to derivations so it does not matter if you include quotes, apostrophes, backslashes, dollar signs or any other special characters – you will not be able to sidestep this splitting behaviour.

To fix this, add the flags to buildFlagsArray in one of the Bash hooks (e.g. in preBuild). Unfortunately, *FlagsArray cannot be used as a mkDerivation argument in Nix.

Examples

Before

stdenv.mkDerivation {makeFlags = [
    "RELEASE=August 2020"
  ];
}

After

stdenv.mkDerivation {preBuild = ''
    makeFlagsArray+=(
      "RELEASE=August 2020"
    )
  '';
}

Exceptions

If the list item in question are actually multiple arguments:

stdenv.mkDerivation {configureFlags = [
    "--with-foo bar"
  ];
}

you should make the division explicit:

  configureFlags = [
    "--with-foo" "bar"
  ];

or, if they are a key and a value and the script supports it, join them using =:

  configureFlags = [
    "--with-foo=bar"
  ];