at 24.11-pre 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.services.goss; 5 6 settingsFormat = pkgs.formats.yaml { }; 7 configFile = settingsFormat.generate "goss.yaml" cfg.settings; 8 9in { 10 meta = { 11 doc = ./goss.md; 12 maintainers = [ lib.maintainers.anthonyroussel ]; 13 }; 14 15 options = { 16 services.goss = { 17 enable = lib.mkEnableOption "Goss daemon"; 18 19 package = lib.mkPackageOption pkgs "goss" { }; 20 21 environment = lib.mkOption { 22 type = lib.types.attrsOf lib.types.str; 23 default = { }; 24 example = { 25 GOSS_FMT = "json"; 26 GOSS_LOGLEVEL = "FATAL"; 27 GOSS_LISTEN = ":8080"; 28 }; 29 description = '' 30 Environment variables to set for the goss service. 31 32 See <https://github.com/goss-org/goss/blob/master/docs/manual.md> 33 ''; 34 }; 35 36 settings = lib.mkOption { 37 type = lib.types.submodule { freeformType = settingsFormat.type; }; 38 default = { }; 39 example = { 40 addr."tcp://localhost:8080" = { 41 reachable = true; 42 local-address = "127.0.0.1"; 43 }; 44 service.goss = { 45 enabled = true; 46 running = true; 47 }; 48 }; 49 description = '' 50 The global options in `config` file in yaml format. 51 52 Refer to <https://github.com/goss-org/goss/blob/master/docs/goss-json-schema.yaml> for schema. 53 ''; 54 }; 55 }; 56 }; 57 58 config = lib.mkIf cfg.enable { 59 environment.systemPackages = [ cfg.package ]; 60 61 systemd.services.goss = { 62 description = "Goss - Quick and Easy server validation"; 63 unitConfig.Documentation = "https://github.com/goss-org/goss/blob/master/docs/manual.md"; 64 65 after = [ "network-online.target" ]; 66 wantedBy = [ "multi-user.target" ]; 67 wants = [ "network-online.target" ]; 68 69 environment = { 70 GOSS_FILE = configFile; 71 } // cfg.environment; 72 73 reloadTriggers = [ configFile ]; 74 75 serviceConfig = { 76 DynamicUser = true; 77 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 78 ExecStart = "${cfg.package}/bin/goss serve"; 79 Group = "goss"; 80 Restart = "on-failure"; 81 RestartSec = 5; 82 User = "goss"; 83 }; 84 }; 85 }; 86}