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