I’m trying to expand on another post to get a working way to list all the enabled services in a NixOS test node. I can get to a useful REPL place for exploring a NixOS deployment by running nix repl .#.nixosConfigurations.NAME. How do I get to the same place in a .#.checks.ARCH.NAME.nodes.NAME derivation? For example, I can get the options for a NixOS configuration, but I can’t find the same attribute under .#.checks.ARCH.NAME.nodes.NAME. Based on the findings so far I’ve ended up with this horrible hack to work around all the ways in which filtering services can fail:
let
nixosConfiguration = nixosConfigurations.ci-full-stable;
in
nixosConfiguration.pkgs.lib.filterAttrs (
serviceName: serviceConfig: let
serviceOptions = nixosConfiguration.options.services;
isDefined = let result = builtins.tryEval (serviceOptions ? ${serviceName} && serviceOptions.${serviceName} ? enable && serviceOptions.${serviceName}.enable.isDefined); in result.success && result.value;
isEnabled = let result = builtins.tryEval serviceConfig.enable; in result.success && result.value;
in serviceName != "frp" && isDefined && isEnabled
) checks.x86_64-linux.androidBackupService.nodes.machine.services
The goal is to minimize the complexity and size of the test VM, and thereby maximize the chance that it runs reliably in CI.