def preprocess(config):
    """Return a copy of the config with ${-} handled."""

    def aux(ctx, service_name, service):
        compiler, _ = get_compiler(config, service)
        r2 = compiler.preprocess(ctx, service_name, service)
        ctx = ctx + [service_name]
        for child_name, child in compiler.children(service):
            r2[child_name] = aux(ctx, child_name, child)
        return r2

    r = {
        'environments': config['environments'],
    }

    for service_name, service in services(config):
        r[service_name] = aux([], service_name, service)

    return r