change clickhouse extraConfig type to yaml (#99)

* change clickhouse `extraConfig` type to yaml

* update clickhouse doc
This commit is contained in:
Abhishek Singh 2024-02-19 11:08:14 +05:30 committed by GitHub
parent 7593351c71
commit 76beca31cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 27 deletions

View File

@ -23,9 +23,9 @@ Clickhouse has [HTTP Interface](https://clickhouse.com/docs/en/interfaces/http)
{ {
services.clickhouse."clickhouse-1" = { services.clickhouse."clickhouse-1" = {
enable = true; enable = true;
extraConfig = '' extraConfig = {
http_port: 9050 http_port = 9050
''; };
}; };
} }
``` ```

View File

@ -2,16 +2,12 @@
services.clickhouse."clickhouse1" = { services.clickhouse."clickhouse1" = {
enable = true; enable = true;
port = 9000; port = 9000;
extraConfig = '' extraConfig.http_port = 9050;
http_port: 9050
'';
}; };
services.clickhouse."clickhouse2" = { services.clickhouse."clickhouse2" = {
enable = true; enable = true;
port = 9001; port = 9001;
extraConfig = '' extraConfig.http_port = 9051;
http_port: 9051
'';
initialDatabases = [ initialDatabases = [
{ {
name = "sample_db"; name = "sample_db";

View File

@ -2,6 +2,7 @@
{ pkgs, lib, name, config, ... }: { pkgs, lib, name, config, ... }:
let let
inherit (lib) types; inherit (lib) types;
yamlFormat = pkgs.formats.yaml { };
in in
{ {
options = { options = {
@ -27,9 +28,9 @@ in
}; };
extraConfig = lib.mkOption { extraConfig = lib.mkOption {
type = types.lines; type = yamlFormat.type;
description = "Additional configuration to be appended to `clickhouse-config.yaml`."; description = "Additional configuration to be appended to `clickhouse-config.yaml`.";
default = ""; default = { };
}; };
initialDatabases = lib.mkOption { initialDatabases = lib.mkOption {
@ -73,22 +74,26 @@ in
default = { default = {
processes = processes =
let let
clickhouseConfig = pkgs.writeText "clickhouse-config.yaml" '' clickhouseConfig = yamlFormat.generate "clickhouse-config.yaml" (
logger: {
level: warning logger = {
console: 1 level = "warning";
tcp_port: ${toString config.port} console = 1;
default_profile: default };
default_database: default tcp_port = "${toString config.port}";
path: ${config.dataDir}/clickhouse default_profile = "default";
tmp_path: ${config.dataDir}/clickhouse/tmp default_database = "default";
user_files_path: ${config.dataDir}/clickhouse/user_files path = "${config.dataDir}/clickhouse";
format_schema_path: ${config.dataDir}/clickhouse/format_schemas tmp_path = "${config.dataDir}/clickhouse/tmp";
user_directories: user_files_path = "${config.dataDir}/clickhouse/user_files";
users_xml: format_schema_path = "${config.dataDir}/clickhouse/format_schemas";
path: ${config.package}/etc/clickhouse-server/users.xml user_directories = {
${config.extraConfig} users_xml = {
''; path = "${config.package}/etc/clickhouse-server/users.xml";
};
};
} // config.extraConfig
);
in in
{ {
# DB initialization # DB initialization