How do I override TwigEnvironment?
You're using an undefined twig.lexer tag there.

It looks as though you want that tag to work as a service_collector like twig.extension, but calling setLexer instead of addExtension.

For that, you probably need to add a line to your twig service definition, below the other tag:

- { name: service_collector, tag: 'twig.lexer', call: setLexer }


(Note: I don't know if this is actually good architecture. The service_collector tag is normally used when there can be multiple extensions, and multiple lexers would just replace each other. But it should work.)