Configuring VictoriaMetrics with Grafana for Metrics on NixOS

Ok, so it seems that I’ve fixed it.

I’m using this dashboard in Grafana.

And these are the nix config files:

# grafana.nix
{ config, pkgs, systemSettings, userSettings, ... }:

{
    services.grafana = {
        enable = true;
        settings = {
            server = {
                http_addr = "127.0.0.1";
                http_port = 2345; # default: 3000
                enable_gzip = true;
            };
            security.admin_email = systemSettings.extraSettings.email;
            analytics.reporting_enabled = false;
        };

        provision = {
            dashboards.settings.providers = [
                { name = "Overview"; options.path = "/etc/grafana-dashboards"; }
            ];

            datasources.settings = {
                apiVersion = 1;
                datasources = [
                    {
                        name = "VictoriaMetrics";
                        type = "victoriametrics-metrics-datasource";
                        access = "proxy";
                        url = "http://127.0.0.1:8428";
                        isDefault = true;
                    }

                    {
                        name = "VictoriaLogs";
                        type = "victoriametrics-logs-datasource";
                        access = "proxy";
                        url = "http://127.0.0.1:9428";
                        isDefault = false;
                    }
                ];
            };
        };

        declarativePlugins = with pkgs.grafanaPlugins; [
            victoriametrics-metrics-datasource
            victoriametrics-logs-datasource
        ];
    };
}
# victoriametrics.nix
{ config, pkgs, systemSettings, userSettings, ... }:

{
    # Default port: 8428
    services.victoriametrics = {
        enable = true;

        prometheusConfig = {
            global = {
            #     scrape_intervals = "10s";
            };
            scrape_configs = [
                {
                    job_name = "node-exporter";
                    # stream_parse = true;
                    scrape_interval = "60s";
                    static_configs = [
                        { targets = ["127.0.0.1:9100"]; labels.type = "node"; }
                    ];
                }
                {
                    job_name = "victoriametrics";
                    # stream_parse = true;
                    scrape_interval = "60s";
                    static_configs = [ { targets = ["http://127.0.0.1:8428/metrics"]; } ];
                }
            ];
        };
    };

    services.prometheus.exporters.node.enable = true;
}
# victorialogs.nix
{ config, pkgs, systemSettings, userSettings, ... }:

{
    # Default port: 9428
    services.victorialogs = {
        enable = true;
        extraOptions = [
            "-retentionPeriod=14d"
        ];
    };

    services.journald.upload = {
        enable = true;
        settings.Upload.URL = "http://localhost:9428/insert/journald";
    };
}

If anybody is interested in replicating this and has any questions, let me know. Also if anybody sees any issues I’d be happy to see other suggestions!