How to query all enabled services in configuraion.nix

I’m trying to do some configuration magic based on which services are enabled in in the current nixos config. I can get a list of all services that are available, but trying to filter by enabled blows up when it encounters service definitions that have been removed e.g. with mkRemovedOption.

let getSuccess = thunk: ({success, value}: success && value) (builtins.tryEval thunk);
    isEnabled = name: attrs: getSuccess (pkgs.lib.hasAttr "enable" attrs && pkgs.lib.isBool attrs.enable && attrs.enable);
in pkgs.lib.filterAttrs isEnabled config.services;

This is my current best effort that doesn’t work. Does anyone know of a better way?

If one just wanted to know what is in the configuration.nix right before applying, would be good to have evaluation result, nix-instantiate maybe ?

I’m trying to do some dynamic configuration based on which services are enabled, so this has to be done at evaluation time, not as a post-instantiate step.