Add nixos module

This commit is contained in:
Sam W 2022-08-04 10:45:31 +03:00
parent 6436cc2e57
commit bd3d79adf3
1 changed files with 42 additions and 1 deletions

View File

@ -35,5 +35,46 @@
devShells.default =
pkgs.devshell.mkShell {packages = with pkgs; [go gopls];};
formatter = pkgs.alejandra;
});
})
// {
overlays.default = final: prev: {
twitter-prometheus = self.defaultPackage.${prev.system};
};
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.string;
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 = self.description;
wantedBy = ["multi-user.target"];
serviceConfig = {
User = "twitter-prometheus";
ExecStart = "${pkgs.twitter-prometheus}/bin/twitter-prometheus -listenAddr ${cfg.listenAddr}:${toString cfg.listenPort}";
Restart = "on-failure";
DynamicUser = true;
};
};
};
};
};
}