mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 11:45:45 +03:00

After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
236 lines
6.9 KiB
Nix
236 lines
6.9 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
utils,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.cockroachdb;
|
|
crdb = cfg.package;
|
|
|
|
startupCommand = utils.escapeSystemdExecArgs (
|
|
[
|
|
# Basic startup
|
|
"${crdb}/bin/cockroach"
|
|
"start"
|
|
"--logtostderr"
|
|
"--store=/var/lib/cockroachdb"
|
|
|
|
# WebUI settings
|
|
"--http-addr=${cfg.http.address}:${toString cfg.http.port}"
|
|
|
|
# Cluster listen address
|
|
"--listen-addr=${cfg.listen.address}:${toString cfg.listen.port}"
|
|
|
|
# Cache and memory settings.
|
|
"--cache=${cfg.cache}"
|
|
"--max-sql-memory=${cfg.maxSqlMemory}"
|
|
|
|
# Certificate/security settings.
|
|
(if cfg.insecure then "--insecure" else "--certs-dir=${cfg.certsDir}")
|
|
]
|
|
++ lib.optional (cfg.join != null) "--join=${cfg.join}"
|
|
++ lib.optional (cfg.locality != null) "--locality=${cfg.locality}"
|
|
++ cfg.extraArgs
|
|
);
|
|
|
|
addressOption = descr: defaultPort: {
|
|
address = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "localhost";
|
|
description = "Address to bind to for ${descr}";
|
|
};
|
|
|
|
port = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = defaultPort;
|
|
description = "Port to bind to for ${descr}";
|
|
};
|
|
};
|
|
in
|
|
|
|
{
|
|
options = {
|
|
services.cockroachdb = {
|
|
enable = lib.mkEnableOption "CockroachDB Server";
|
|
|
|
listen = addressOption "intra-cluster communication" 26257;
|
|
|
|
http = addressOption "http-based Admin UI" 8080;
|
|
|
|
locality = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
description = ''
|
|
An ordered, comma-separated list of key-value pairs that describe the
|
|
topography of the machine. Topography might include country,
|
|
datacenter or rack designations. Data is automatically replicated to
|
|
maximize diversities of each tier. The order of tiers is used to
|
|
determine the priority of the diversity, so the more inclusive
|
|
localities like country should come before less inclusive localities
|
|
like datacenter. The tiers and order must be the same on all nodes.
|
|
Including more tiers is better than including fewer. For example:
|
|
|
|
```
|
|
country=us,region=us-west,datacenter=us-west-1b,rack=12
|
|
country=ca,region=ca-east,datacenter=ca-east-2,rack=4
|
|
|
|
planet=earth,province=manitoba,colo=secondary,power=3
|
|
```
|
|
'';
|
|
};
|
|
|
|
join = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
description = "The addresses for connecting the node to a cluster.";
|
|
};
|
|
|
|
insecure = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = "Run in insecure mode.";
|
|
};
|
|
|
|
certsDir = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.path;
|
|
default = null;
|
|
description = "The path to the certificate directory.";
|
|
};
|
|
|
|
user = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "cockroachdb";
|
|
description = "User account under which CockroachDB runs";
|
|
};
|
|
|
|
group = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "cockroachdb";
|
|
description = "User account under which CockroachDB runs";
|
|
};
|
|
|
|
openPorts = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = "Open firewall ports for cluster communication by default";
|
|
};
|
|
|
|
cache = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "25%";
|
|
description = ''
|
|
The total size for caches.
|
|
|
|
This can be a percentage, expressed with a fraction sign or as a
|
|
decimal-point number, or any bytes-based unit. For example,
|
|
`"25%"`, `"0.25"` both represent
|
|
25% of the available system memory. The values
|
|
`"1000000000"` and `"1GB"` both
|
|
represent 1 gigabyte of memory.
|
|
|
|
'';
|
|
};
|
|
|
|
maxSqlMemory = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "25%";
|
|
description = ''
|
|
The maximum in-memory storage capacity available to store temporary
|
|
data for SQL queries.
|
|
|
|
This can be a percentage, expressed with a fraction sign or as a
|
|
decimal-point number, or any bytes-based unit. For example,
|
|
`"25%"`, `"0.25"` both represent
|
|
25% of the available system memory. The values
|
|
`"1000000000"` and `"1GB"` both
|
|
represent 1 gigabyte of memory.
|
|
'';
|
|
};
|
|
|
|
package = lib.mkPackageOption pkgs "cockroachdb" {
|
|
extraDescription = ''
|
|
This would primarily be useful to enable Enterprise Edition features
|
|
in your own custom CockroachDB build (Nixpkgs CockroachDB binaries
|
|
only contain open source features and open source code).
|
|
'';
|
|
};
|
|
|
|
extraArgs = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ ];
|
|
example = [
|
|
"--advertise-addr"
|
|
"[fe80::f6f2:::]"
|
|
];
|
|
description = ''
|
|
Extra CLI arguments passed to {command}`cockroach start`.
|
|
For the full list of supported arguments, check <https://www.cockroachlabs.com/docs/stable/cockroach-start.html#flags>
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf config.services.cockroachdb.enable {
|
|
assertions = [
|
|
{
|
|
assertion = !cfg.insecure -> cfg.certsDir != null;
|
|
message = "CockroachDB must have a set of SSL certificates (.certsDir), or run in Insecure Mode (.insecure = true)";
|
|
}
|
|
];
|
|
|
|
environment.systemPackages = [ crdb ];
|
|
|
|
users.users = lib.optionalAttrs (cfg.user == "cockroachdb") {
|
|
cockroachdb = {
|
|
description = "CockroachDB Server User";
|
|
uid = config.ids.uids.cockroachdb;
|
|
group = cfg.group;
|
|
};
|
|
};
|
|
|
|
users.groups = lib.optionalAttrs (cfg.group == "cockroachdb") {
|
|
cockroachdb.gid = config.ids.gids.cockroachdb;
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = lib.optionals cfg.openPorts [
|
|
cfg.http.port
|
|
cfg.listen.port
|
|
];
|
|
|
|
systemd.services.cockroachdb = {
|
|
description = "CockroachDB Server";
|
|
documentation = [
|
|
"man:cockroach(1)"
|
|
"https://www.cockroachlabs.com"
|
|
];
|
|
|
|
after = [
|
|
"network.target"
|
|
"time-sync.target"
|
|
];
|
|
requires = [ "time-sync.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/cockroachdb";
|
|
|
|
serviceConfig = {
|
|
ExecStart = startupCommand;
|
|
Type = "notify";
|
|
User = cfg.user;
|
|
StateDirectory = "cockroachdb";
|
|
StateDirectoryMode = "0700";
|
|
|
|
Restart = "always";
|
|
|
|
# A conservative-ish timeout is alright here, because for Type=notify
|
|
# cockroach will send systemd pings during startup to keep it alive
|
|
TimeoutStopSec = 60;
|
|
RestartSec = 10;
|
|
};
|
|
};
|
|
};
|
|
|
|
meta.maintainers = with lib.maintainers; [ thoughtpolice ];
|
|
}
|