diff --git a/lib/spack/spack/cmd/config.py b/lib/spack/spack/cmd/config.py index 90652e94316..a3ba9b6a9dc 100644 --- a/lib/spack/spack/cmd/config.py +++ b/lib/spack/spack/cmd/config.py @@ -350,9 +350,12 @@ def _config_change(config_path, match_spec_str=None): if spack.config.get(key_path, scope=scope): ideal_scope_to_modify = scope break + # If we find our key in a specific scope, that's the one we want + # to modify. Otherwise we use the default write scope. + write_scope = ideal_scope_to_modify or spack.config.default_modify_scope() update_path = f"{key_path}:[{str(spec)}]" - spack.config.add(update_path, scope=ideal_scope_to_modify) + spack.config.add(update_path, scope=write_scope) else: raise ValueError("'config change' can currently only change 'require' sections")