# Source: http://chriswarbo.net/projects/nixos/useful_hacks.html { args, name }: let nixpkgs = import {}; lib = nixpkgs.lib; in rec { # Store each arg in a separate variable, named numerically env = with lib.foldl' (result: arg: { # Increment the count, for the next arg (if any) count = result.count + 1; # Append a variable to the environment for this arg vars = result.vars // { "${name}${toString result.count}" = arg; }; }) # Start with variable 1 in an empty environment { count = 1; vars = {}; } args; vars; code = '' ### Auto-generated by nixListToBashArray ${name}=() for N in $(seq 1 "${toString (lib.length args)}") do # Use a "variable variable" to look up "$name$N" as a variable name NIXLISTTOBASHARRAYTEMP="${name}$N" ${name}=("''${${name}[@]}" "''${!NIXLISTTOBASHARRAYTEMP}") unset NIXLISTTOBASHARRAYTEMP done ### End of auto-generated code ''; }