at 25.11-pre 3.1 kB view raw
1{ 2 pkgs, 3 lib, 4 config, 5 ... 6}: 7let 8 cfg = config.services.gatus; 9 10 settingsFormat = pkgs.formats.yaml { }; 11 12 inherit (lib) 13 getExe 14 literalExpression 15 maintainers 16 mkEnableOption 17 mkIf 18 mkOption 19 mkPackageOption 20 ; 21 22 inherit (lib.types) 23 bool 24 int 25 nullOr 26 path 27 submodule 28 ; 29in 30{ 31 options.services.gatus = { 32 enable = mkEnableOption "Gatus"; 33 34 package = mkPackageOption pkgs "gatus" { }; 35 36 configFile = mkOption { 37 type = path; 38 default = settingsFormat.generate "gatus.yaml" cfg.settings; 39 defaultText = literalExpression '' 40 let settingsFormat = pkgs.formats.yaml { }; in settingsFormat.generate "gatus.yaml" cfg.settings; 41 ''; 42 description = '' 43 Path to the Gatus configuration file. 44 Overrides any configuration made using the `settings` option. 45 ''; 46 }; 47 48 environmentFile = mkOption { 49 type = nullOr path; 50 default = null; 51 description = '' 52 File to load as environment file. 53 Environmental variables from this file can be interpolated in the configuration file using `''${VARIABLE}`. 54 This is useful to avoid putting secrets into the nix store. 55 ''; 56 }; 57 58 settings = mkOption { 59 type = submodule { 60 freeformType = settingsFormat.type; 61 options = { 62 web.port = mkOption { 63 type = int; 64 default = 8080; 65 description = '' 66 The TCP port to serve the Gatus service at. 67 ''; 68 }; 69 }; 70 }; 71 72 default = { }; 73 74 example = literalExpression '' 75 { 76 web.port = 8080; 77 endpoints = [{ 78 name = "website"; 79 url = "https://twin.sh/health"; 80 interval = "5m"; 81 conditions = [ 82 "[STATUS] == 200" 83 "[BODY].status == UP" 84 "[RESPONSE_TIME] < 300" 85 ]; 86 }]; 87 } 88 ''; 89 90 description = '' 91 Configuration for Gatus. 92 Supported options can be found at the [docs](https://gatus.io/docs). 93 ''; 94 }; 95 96 openFirewall = mkOption { 97 type = bool; 98 default = false; 99 description = '' 100 Whether to open the firewall for the Gatus web interface. 101 ''; 102 }; 103 }; 104 105 config = mkIf cfg.enable { 106 systemd.services.gatus = { 107 description = "Automated developer-oriented status page"; 108 after = [ "network.target" ]; 109 wantedBy = [ "multi-user.target" ]; 110 111 serviceConfig = { 112 DynamicUser = true; 113 User = "gatus"; 114 Group = "gatus"; 115 Type = "simple"; 116 Restart = "on-failure"; 117 ExecStart = getExe cfg.package; 118 StateDirectory = "gatus"; 119 SyslogIdentifier = "gatus"; 120 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; 121 }; 122 123 environment = { 124 GATUS_CONFIG_PATH = cfg.configFile; 125 }; 126 }; 127 128 networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.settings.web.port ]; 129 }; 130 131 meta.maintainers = with maintainers; [ pizzapim ]; 132}