Skip to content

nix develop gcc fails with bad substitution (bash-5 breakage) #6848

@trofi

Description

@trofi

Describe the bug

$ ./src/nix/nix --extra-experimental-features nix-command develop -f ~/nm gcc -L
gcc-wrapper> /nix/store/c6m8m8qjr3dxsli8iymc6js3jsyzg5cy-get-env.sh: line 70: expand-response-params: bad substitution

This should not fail.

Additional context

Looks like bash-5 no longer allows indirect variable dereference with invalid variable names. Simple reproducer:

$ LANG=C env 'my-hyphenated-variable=hello' bash
$ name='my-hyphenated-variable'
$ echo ${!name}
bash: my-hyphenated-variable: invalid variable name

Looks like it used to work in bash-4. This pattern is used in src/nix/get-env.sh:

__vars="$(declare -p)"
...

__dumpEnv() {
...
    while read __line; do
        if ! [[ $__line =~ ^declare\ (-[^ ])\ ([^=]*) ]]; then continue; fi
        local type="${BASH_REMATCH[1]}"
        local __var_name="${BASH_REMATCH[2]}"
...
        if [[ $type == -x ]]; then
            printf '"type": "exported", "value": '
            __escapeString "${!__var_name}"
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnew-cliRelating to the "nix" command
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions