2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.clickhouse;
|
|
|
|
in
|
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.clickhouse = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "ClickHouse database server");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.clickhouse;
|
2022-12-17 10:02:37 +00:00
|
|
|
defaultText = lib.literalExpression "pkgs.clickhouse";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-12-06 16:07:01 +00:00
|
|
|
ClickHouse package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.users.clickhouse = {
|
|
|
|
name = "clickhouse";
|
|
|
|
uid = config.ids.uids.clickhouse;
|
|
|
|
group = "clickhouse";
|
|
|
|
description = "ClickHouse server user";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.clickhouse.gid = config.ids.gids.clickhouse;
|
|
|
|
|
|
|
|
systemd.services.clickhouse = {
|
|
|
|
description = "ClickHouse server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2023-05-24 13:37:59 +00:00
|
|
|
Type = "notify";
|
2020-04-24 23:36:52 +00:00
|
|
|
User = "clickhouse";
|
|
|
|
Group = "clickhouse";
|
|
|
|
ConfigurationDirectory = "clickhouse-server";
|
2021-05-20 23:08:51 +00:00
|
|
|
AmbientCapabilities = "CAP_SYS_NICE";
|
2020-04-24 23:36:52 +00:00
|
|
|
StateDirectory = "clickhouse";
|
|
|
|
LogsDirectory = "clickhouse";
|
2023-02-16 17:41:37 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml";
|
2023-05-24 13:37:59 +00:00
|
|
|
TimeoutStartSec = "infinity";
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
# Switching off watchdog is very important for sd_notify to work correctly.
|
|
|
|
CLICKHOUSE_WATCHDOG_ENABLE = "0";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"clickhouse-server/config.xml" = {
|
2021-12-06 16:07:01 +00:00
|
|
|
source = "${cfg.package}/etc/clickhouse-server/config.xml";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
"clickhouse-server/users.xml" = {
|
2021-12-06 16:07:01 +00:00
|
|
|
source = "${cfg.package}/etc/clickhouse-server/users.xml";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# startup requires a `/etc/localtime` which only if exists if `time.timeZone != null`
|
|
|
|
time.timeZone = mkDefault "UTC";
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|