|
| 1 | +{ withSystem, ... }: |
| 2 | +{ |
| 3 | + flake.modules.nixos.cachix-deploy-metrics = |
| 4 | + { |
| 5 | + pkgs, |
| 6 | + config, |
| 7 | + lib, |
| 8 | + ... |
| 9 | + }: |
| 10 | + let |
| 11 | + inherit (lib) |
| 12 | + types |
| 13 | + mkEnableOption |
| 14 | + mkOption |
| 15 | + mkIf |
| 16 | + concatMapStringsSep |
| 17 | + ; |
| 18 | + cfg = config.services.cachix-deploy-metrics; |
| 19 | + defaultPackage = withSystem pkgs.stdenv.hostPlatform.system ( |
| 20 | + { config, ... }: config.packages.cachix-deploy-metrics |
| 21 | + ); |
| 22 | + in |
| 23 | + { |
| 24 | + options.services.cachix-deploy-metrics = with lib; { |
| 25 | + enable = mkEnableOption (lib.mdDoc "Cachix Deploy Metrics"); |
| 26 | + |
| 27 | + package = mkOption { |
| 28 | + type = types.package; |
| 29 | + default = defaultPackage; |
| 30 | + description = "Package providing the deploy-metrics binary."; |
| 31 | + }; |
| 32 | + |
| 33 | + scrape-interval = mkOption { |
| 34 | + type = types.int; |
| 35 | + default = 1; |
| 36 | + description = "Scrape interval in seconds."; |
| 37 | + }; |
| 38 | + |
| 39 | + auth-token-path = mkOption { |
| 40 | + type = types.path; |
| 41 | + description = "Cachix auth token path."; |
| 42 | + }; |
| 43 | + |
| 44 | + workspace = mkOption { |
| 45 | + type = types.str; |
| 46 | + description = "Cachix workspace."; |
| 47 | + }; |
| 48 | + |
| 49 | + agent-names = mkOption { |
| 50 | + type = types.listOf types.str; |
| 51 | + default = [ ]; |
| 52 | + description = "List of Cachix deploy agents."; |
| 53 | + example = [ |
| 54 | + "machine-01" |
| 55 | + "machine-02" |
| 56 | + ]; |
| 57 | + }; |
| 58 | + |
| 59 | + port = mkOption { |
| 60 | + type = types.port; |
| 61 | + default = 9160; |
| 62 | + description = "Port number of Cachix Deployments Exporter service."; |
| 63 | + }; |
| 64 | + }; |
| 65 | + |
| 66 | + config = mkIf cfg.enable { |
| 67 | + systemd.services.cachix-deploy-metrics = { |
| 68 | + description = "Prometheus exporter for Cachix Deploy"; |
| 69 | + wantedBy = [ "multi-user.target" ]; |
| 70 | + path = [ cfg.package ]; |
| 71 | + serviceConfig = { |
| 72 | + ExecStart = '' |
| 73 | + ${lib.getExe cfg.package} \ |
| 74 | + --port ${toString cfg.port} \ |
| 75 | + --scrape-interval ${toString cfg.scrape-interval} \ |
| 76 | + --auth-token-path ${cfg.auth-token-path} \ |
| 77 | + --workspace ${cfg.workspace} \ |
| 78 | + ${ |
| 79 | + if cfg.agent-names == [ ] then |
| 80 | + "" |
| 81 | + else |
| 82 | + concatMapStringsSep " \\\n" (agent: "--agent-names=${agent}") cfg.agent-names |
| 83 | + } |
| 84 | + ''; |
| 85 | + Restart = "on-failure"; |
| 86 | + RestartSec = 10; |
| 87 | + }; |
| 88 | + }; |
| 89 | + }; |
| 90 | + }; |
| 91 | +} |
0 commit comments