From 1dcfdad4cd6f04b1afe8f96d51b0eb6405e71ca5 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Sun, 18 Feb 2024 23:46:02 +0530 Subject: [PATCH 1/3] change clickhouse `extraConfig` type to yaml --- nix/clickhouse/clickhouse_test.nix | 8 ++---- nix/clickhouse/default.nix | 41 +++++++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) 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 From d5862a6b8a2bc7a13b30a7356e66666ce56d9a06 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Sun, 18 Feb 2024 23:46:31 +0530 Subject: [PATCH 2/3] update clickhouse doc --- doc/clickhouse.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 + }; }; } ``` From ac56f9aed803cad83b6e609682d4bb74559e84b8 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Mon, 19 Feb 2024 18:13:10 +0530 Subject: [PATCH 3/3] explicitly define project root in treefmt --- dev/flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/flake.nix b/dev/flake.nix index 7a3a4491..7637885d 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -14,6 +14,7 @@ ]; perSystem = { pkgs, lib, config, ... }: { treefmt = { + projectRoot = ../.; projectRootFile = "flake.nix"; programs = { nixpkgs-fmt.enable = true;