From 8bb530758c7c78c5902c6ddbfbb12b99c64e6cae Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Thu, 4 Aug 2022 10:45:31 +0300 Subject: [PATCH] Add nixos module --- flake.nix | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 605b0c3..50167c3 100644 --- a/flake.nix +++ b/flake.nix @@ -35,5 +35,46 @@ 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; + }; + }; + }; + }; + }; }