You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
Nix
38 lines
1.2 KiB
Nix
7 years ago
|
# Source: http://chriswarbo.net/projects/nixos/useful_hacks.html
|
||
|
|
||
|
{ args, name }:
|
||
|
let
|
||
|
nixpkgs = import <nixpkgs> {};
|
||
|
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
|
||
|
'';
|
||
|
}
|