Files
testdata/nix/module.nix
2025-05-29 17:57:06 +02:00

69 lines
1.4 KiB
Nix

inputs:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.testdata;
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
{
options.services.testdata = {
enable = mkEnableOption "testdata";
settings = mkOption {
type =
with types;
let
valueType = nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]);
in
valueType;
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";
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ package ];
systemd.services.testdata = {
enable = true;
serviceConfig = {
Type = "simple";
ExecStart = "${package}/bin/testdata --config ${configFile} --listen ${cfg.host} --port ${builtins.toString cfg.port}";
};
wantedBy = [ "multi-user.target" ];
};
};
}