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?