twitter-prometheus/flake.nix

81 lines
2.3 KiB
Nix

{
description = "Twitter follower counts in Prometheus.";
inputs.utils.url = "github:numtide/flake-utils";
inputs.devshell = {
url = "github:numtide/devshell";
inputs.utils.follows = "utils";
};
outputs = {
self,
nixpkgs,
utils,
devshell,
}:
utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [devshell.overlay];
};
in rec {
packages.default = pkgs.buildGoModule {
name = "twitter-prometheus";
src = self;
vendorSha256 = "vZ56zJNcMSZonNqLNPEWCQkyuDH50SqGOC/vdz0w6uA=";
# Inject the git version if you want
#ldflags = ''
# -X main.version=${if self ? rev then self.rev else "dirty"}
#'';
};
apps.default = utils.lib.mkApp {drv = packages.default;};
devShells.default =
pkgs.devshell.mkShell {packages = with pkgs; [go gopls];};
formatter = pkgs.alejandra;
})
// {
overlays.default = final: prev: {
twitter-prometheus = self.packages.${prev.system}.default;
};
nixosModules.default = {
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.twitter-prometheus;
in {
options.services.twitter-prometheus = {
enable = mkEnableOption "Enables the twitter-prometheus service";
listenAddr = mkOption {
type = types.str;
description = "The address to listen on.";
default = "localhost";
};
listenPort = mkOption {
type = types.port;
description = "The port to listen on.";
default = 9700;
};
};
config = mkIf cfg.enable {
nixpkgs.overlays = [self.overlays.default];
systemd.services.twitter-prometheus = {
description = "Twitter prometheus exporter";
wantedBy = ["multi-user.target"];
serviceConfig = {
User = "twitter-prometheus";
ExecStart = "${pkgs.twitter-prometheus}/bin/twitter-prometheus -listen ${cfg.listenAddr}:${toString cfg.listenPort}";
Restart = "on-failure";
DynamicUser = true;
};
};
};
};
};
}