diff --git a/doc/clickhouse.md b/doc/clickhouse.md index 01b1e6cf..36ae0e75 100644 --- a/doc/clickhouse.md +++ b/doc/clickhouse.md @@ -23,9 +23,9 @@ Clickhouse has [HTTP Interface](https://clickhouse.com/docs/en/interfaces/http) { services.clickhouse."clickhouse-1" = { enable = true; - extraConfig = '' - http_port: 9050 - ''; + extraConfig = { + http_port = 9050 + }; }; } ``` diff --git a/nix/clickhouse/clickhouse_test.nix b/nix/clickhouse/clickhouse_test.nix index d9a230e7..bf2f7ccb 100644 --- a/nix/clickhouse/clickhouse_test.nix +++ b/nix/clickhouse/clickhouse_test.nix @@ -2,16 +2,12 @@ services.clickhouse."clickhouse1" = { enable = true; port = 9000; - extraConfig = '' - http_port: 9050 - ''; + extraConfig.http_port = 9050; }; services.clickhouse."clickhouse2" = { enable = true; port = 9001; - extraConfig = '' - http_port: 9051 - ''; + extraConfig.http_port = 9051; initialDatabases = [ { name = "sample_db"; diff --git a/nix/clickhouse/default.nix b/nix/clickhouse/default.nix index 2be00e93..fc8385e5 100644 --- a/nix/clickhouse/default.nix +++ b/nix/clickhouse/default.nix @@ -2,6 +2,7 @@ { pkgs, lib, name, config, ... }: let inherit (lib) types; + yamlFormat = pkgs.formats.yaml { }; in { options = { @@ -27,9 +28,9 @@ in }; extraConfig = lib.mkOption { - type = types.lines; + type = yamlFormat.type; description = "Additional configuration to be appended to `clickhouse-config.yaml`."; - default = ""; + default = { }; }; initialDatabases = lib.mkOption { @@ -73,22 +74,26 @@ in default = { processes = let - clickhouseConfig = pkgs.writeText "clickhouse-config.yaml" '' - logger: - level: warning - console: 1 - tcp_port: ${toString config.port} - default_profile: default - default_database: default - path: ${config.dataDir}/clickhouse - tmp_path: ${config.dataDir}/clickhouse/tmp - user_files_path: ${config.dataDir}/clickhouse/user_files - format_schema_path: ${config.dataDir}/clickhouse/format_schemas - user_directories: - users_xml: - path: ${config.package}/etc/clickhouse-server/users.xml - ${config.extraConfig} - ''; + clickhouseConfig = yamlFormat.generate "clickhouse-config.yaml" ( + { + logger = { + level = "warning"; + console = 1; + }; + tcp_port = "${toString config.port}"; + default_profile = "default"; + default_database = "default"; + path = "${config.dataDir}/clickhouse"; + tmp_path = "${config.dataDir}/clickhouse/tmp"; + user_files_path = "${config.dataDir}/clickhouse/user_files"; + format_schema_path = "${config.dataDir}/clickhouse/format_schemas"; + user_directories = { + users_xml = { + path = "${config.package}/etc/clickhouse-server/users.xml"; + }; + }; + } // config.extraConfig + ); in { # DB initialization