nixos/clickhouse: allow configuring with Nix attribute set (#458319)
This commit is contained in:
@@ -279,6 +279,7 @@
|
|||||||
|
|
||||||
- `cloudflare-ddns`: Added package cloudflare-ddns.
|
- `cloudflare-ddns`: Added package cloudflare-ddns.
|
||||||
|
|
||||||
|
- `clickhouse`: Added `serverConfig`, `usersConfig` configuration options accepting Nix attribute sets. Also added `extraServerConfig` and `extraUsersConfig` options accepting plain text (expecting XML configuration).
|
||||||
|
|
||||||
- [`homebox` 0.20.0](https://github.com/sysadminsmedia/homebox/releases/tag/v0.20.0) changed how assets are stored and hashed. It is recommended to back up your database before this update. In particular, `--storage-data` was replaced with `--storage-conn-string` and `--storage-prefix-path`. If your configuration set `HBOX_STORAGE_DATA` manually, you must migrate it to `HBOX_STORAGE_CONN_STRING` and `HBOX_STORAGE_PREFIX_PATH`.
|
- [`homebox` 0.20.0](https://github.com/sysadminsmedia/homebox/releases/tag/v0.20.0) changed how assets are stored and hashed. It is recommended to back up your database before this update. In particular, `--storage-data` was replaced with `--storage-conn-string` and `--storage-prefix-path`. If your configuration set `HBOX_STORAGE_DATA` manually, you must migrate it to `HBOX_STORAGE_CONN_STRING` and `HBOX_STORAGE_PREFIX_PATH`.
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,15 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.services.clickhouse;
|
cfg = config.services.clickhouse;
|
||||||
|
format = pkgs.formats.yaml { };
|
||||||
|
|
||||||
|
serverConfigFile = format.generate "config.yaml" cfg.serverConfig;
|
||||||
|
usersConfigFile = format.generate "users.yaml" cfg.usersConfig;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
||||||
|
meta.maintainers = [ "thevar1able" ];
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@@ -17,7 +23,86 @@ in
|
|||||||
|
|
||||||
enable = lib.mkEnableOption "ClickHouse database server";
|
enable = lib.mkEnableOption "ClickHouse database server";
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "clickhouse" { };
|
package = lib.mkPackageOption pkgs "clickhouse" {
|
||||||
|
example = "pkgs.clickhouse-lts";
|
||||||
|
};
|
||||||
|
|
||||||
|
serverConfig = lib.mkOption {
|
||||||
|
type = format.type;
|
||||||
|
default = { };
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
{
|
||||||
|
http_port = 8123;
|
||||||
|
tcp_port = 9000;
|
||||||
|
|
||||||
|
remote_servers = {
|
||||||
|
default = {
|
||||||
|
shard = {
|
||||||
|
replica = [
|
||||||
|
{ host = "::"; port = "9000"; }
|
||||||
|
{ host = "::"; port = "9001"; }
|
||||||
|
{ host = "::"; port = "9002"; }
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Your {file}`config.yaml` as a Nix attribute set.
|
||||||
|
Check the [documentation](https://clickhouse.com/docs/operations/configuration-files)
|
||||||
|
for possible options.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
usersConfig = lib.mkOption {
|
||||||
|
type = format.type;
|
||||||
|
default = { };
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
{
|
||||||
|
profiles = {};
|
||||||
|
|
||||||
|
users = {
|
||||||
|
default = {
|
||||||
|
profile = "default";
|
||||||
|
password_sha256_hex = "36dd292533174299fb0c34665df468bb881756ca9eaf9757d0cfde38f9ededa1"; # `echo -n verysecret | sha256sum`
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Your {file}`users.yaml` as a Nix attribute set.
|
||||||
|
Check the [documentation](https://clickhouse.com/docs/operations/configuration-files#user-settings)
|
||||||
|
for possible options.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
extraServerConfig = lib.mkOption {
|
||||||
|
type = lib.types.lines;
|
||||||
|
default = "";
|
||||||
|
example = ''
|
||||||
|
<clickhouse>
|
||||||
|
<max_connections>500</max_connections>
|
||||||
|
<keep_alive_timeout>3</keep_alive_timeout>
|
||||||
|
</clickhouse>
|
||||||
|
'';
|
||||||
|
description = "Additional raw XML configuration for ClickHouse server.";
|
||||||
|
};
|
||||||
|
|
||||||
|
extraUsersConfig = lib.mkOption {
|
||||||
|
type = lib.types.lines;
|
||||||
|
default = "";
|
||||||
|
example = ''
|
||||||
|
<clickhouse>
|
||||||
|
<users>
|
||||||
|
<readonly>
|
||||||
|
<profile>readonly</profile>
|
||||||
|
</readonly>
|
||||||
|
</users>
|
||||||
|
</clickhouse>
|
||||||
|
'';
|
||||||
|
description = "Additional raw XML configuration for ClickHouse server.";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,18 +125,15 @@ in
|
|||||||
description = "ClickHouse server";
|
description = "ClickHouse server";
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "notify";
|
Type = "notify";
|
||||||
User = "clickhouse";
|
User = "clickhouse";
|
||||||
Group = "clickhouse";
|
Group = "clickhouse";
|
||||||
ConfigurationDirectory = "clickhouse-server";
|
|
||||||
AmbientCapabilities = "CAP_SYS_NICE";
|
AmbientCapabilities = "CAP_SYS_NICE";
|
||||||
StateDirectory = "clickhouse";
|
StateDirectory = "clickhouse";
|
||||||
LogsDirectory = "clickhouse";
|
ExecStart = "${cfg.package}/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml";
|
||||||
ExecStart = "${cfg.package}/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml";
|
|
||||||
TimeoutStartSec = "infinity";
|
TimeoutStartSec = "infinity";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,6 +151,26 @@ in
|
|||||||
"clickhouse-server/users.xml" = {
|
"clickhouse-server/users.xml" = {
|
||||||
source = "${cfg.package}/etc/clickhouse-server/users.xml";
|
source = "${cfg.package}/etc/clickhouse-server/users.xml";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
"clickhouse-server/config.d/100-nixos-module-config.yaml" = lib.mkIf (cfg.serverConfig != { }) {
|
||||||
|
source = serverConfigFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
"clickhouse-server/users.d/100-nixos-module-config.yaml" = lib.mkIf (cfg.usersConfig != { }) {
|
||||||
|
source = usersConfigFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
"clickhouse-server/config.d/200-nixos-module-extra-config.xml" =
|
||||||
|
lib.mkIf (cfg.extraServerConfig != "")
|
||||||
|
{
|
||||||
|
text = cfg.extraServerConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
"clickhouse-server/users.d/200-nixos-module-extra-config.xml" =
|
||||||
|
lib.mkIf (cfg.extraUsersConfig != "")
|
||||||
|
{
|
||||||
|
text = cfg.extraUsersConfig;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|||||||
Reference in New Issue
Block a user