Skip to content

Conversation

@johnspade
Copy link

I deploy services as OCI containers on NixOS, so I wanted to create an extractor for virtualisation.oci-containers.containers. I had to do a little refactoring and extract the service registry so that the service extractors could share the service names and icons.

It works by matching the virtualisation.oci-containers.containers.<name>.image option with a list of known service container repository references (mostly official ones), e.g. jellyfin/jellyfin and linuxserver/jellyfin for Jellyfin.

Users can define custom functions to extract info and details from their container configurations, as well as override and update the service registry.

in
mkIf (specNix != null && specNix.path != []) (
let
cfg = attrByPath specNix.path {} config;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match the NixOS services by the option path

# The config should only be applied on the toplevel topology module,
# not for each nixos node.
config = {};
config.topology.serviceRegistry = serviceDefs;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this line but it was the only way I could make it to work (I needed to expose the service registry to the NixOS configurations)

};
in
f {
options.serviceRegistry = mkOption {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose the service registry as an option (for overriding and customizations)

map (svc: {inherit node svc;}) visible
) (attrValues config.nodes);

# Deduplicate services by serviceId in overview
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the (supposedly rare) case when the same service deployed both as a container and a NixOS service display it only once in the overview

repoLower = strings.toLower repo;
in
canon == repoLower || strings.hasSuffix ("/" + repoLower) canon;
matchesRepos = img: repos: builtins.any (suffixMatch img) repos;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match the containerized services by the image reference

builtins.trace
("oci-container extractor: UNMATCHED containers → "
+ (concatStringsSep ", "
(map (c: "${c._name} (${c.image})") unmatched)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output the unmatched containers

@johnspade johnspade marked this pull request as ready for review June 18, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant