2024-04-11 19:11:05 +00:00
|
|
|
inputs: {
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2025-01-02 17:18:57 +00:00
|
|
|
cfg = config.services.testdata;
|
2024-04-11 19:11:05 +00:00
|
|
|
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
|
|
inherit (lib) mkIf mkEnableOption mkOption types;
|
|
|
|
|
|
|
|
format = pkgs.formats.json {};
|
|
|
|
configFile = format.generate "config.json" cfg.settings;
|
|
|
|
in {
|
2025-01-02 17:18:57 +00:00
|
|
|
options.services.testdata = {
|
2024-04-11 19:11:05 +00:00
|
|
|
enable = mkEnableOption "testdata";
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = with types; let
|
|
|
|
valueType = nullOr (oneOf [
|
|
|
|
# TODO: restrict type to actual config file structure
|
|
|
|
bool
|
|
|
|
int
|
|
|
|
float
|
|
|
|
str
|
|
|
|
path
|
|
|
|
(attrsOf valueType)
|
|
|
|
(listOf valueType)
|
|
|
|
]);
|
|
|
|
in
|
|
|
|
valueType;
|
2025-01-02 17:18:57 +00:00
|
|
|
default = throw "Please specify services.testdata.settings";
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = throw "Please specify a services.testdata.port";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = throw "Please specify a services.testdata.port";
|
2024-04-11 19:11:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [package];
|
|
|
|
|
|
|
|
systemd.services.testdata = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2025-01-02 17:18:57 +00:00
|
|
|
ExecStart = "${package}/bin/testdata --config ${configFile} --listen ${cfg.host} --port ${builtins.toString cfg.port}";
|
2024-04-11 19:11:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|