oddlama / nix-topology

🍁 Generate infrastructure and network diagrams directly from your NixOS configurations
https://oddlama.github.io/nix-topology
MIT License
576 stars 25 forks source link

Define local extractors #40

Closed kjeremy closed 2 months ago

kjeremy commented 2 months ago

Can I define extractors locally in my project? For instance I use some services from https://github.com/lopsided98/nix-ros-overlay/ and have some other services defined locally in my flake that I would like to detect.

oddlama commented 2 months ago

Of course, the extractors are just a regular NixOS module that are included on your host. All it does is to define some entries in topology.self.services. Anything you put in there will be shown automatically.

So anywhere in your relevant nixos configurations you can just do something like:

topology.self.services.mycustomservice = mkIf config.services.mycustomservice.enable {
  name = "My Custom Service";
  icon = ./mycustomservice.svg; # any SVG (recommended) / PNG
  # Extra stuff to show
  details.listen = "${config.services.mycustomservice.address}:${toString config.services.mycustomservice.port}";
};
oddlama commented 2 months ago

Relevant options: https://oddlama.github.io/nix-topology/topology-options.html#nodesnameservices

kjeremy commented 2 months ago

Thank you. I'm struggling a little with this:

  topology-diagrams =
    let t = import inputs.nix-topology {
      pkgs = local.legacyPackages;
      modules = [
        ({config, ...} : { topology.self.services.what = { name = "HI"; info = "INFO"; }; })
        { nixosConfigurations = mapAttrs (n: v: nixosWithModules v) hosts; }
      ];
    };
    in t.config.output;
$ nix build .#myplatform/topology-diagrams

ends in:

 … while evaluating the attribute 'config.output'
         at /nix/store/dk2rpyb6ndvfbf19bkb2plcz5y3k8i5v-source/lib/modules.nix:322:9:
          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: The option `topology.topology.self' does not exist. Definition values:
       - In `<unknown-file>':
           {
             services = {
               what = {
                 info = "INFO";
                 name = "HI";
           ...
oddlama commented 2 months ago

This -> topology.self.services.what = { name = "HI"; info = "INFO"; }; is supposed to go into your nixos configuration, not the topology config. Set it on the host that exposes the service