2018-04-10 03:16:33 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cockroachdb;
|
|
|
|
crdb = cfg.package;
|
|
|
|
|
|
|
|
escape = builtins.replaceStrings ["%"] ["%%"];
|
2019-04-24 05:48:22 +02:00
|
|
|
ifNotNull = v: s: optionalString (v != null) s;
|
2018-04-10 03:16:33 +02:00
|
|
|
|
|
|
|
startupCommand = lib.concatStringsSep " "
|
|
|
|
[ # Basic startup
|
|
|
|
"${crdb}/bin/cockroach start"
|
|
|
|
"--logtostderr"
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
"--store=/var/lib/cockroachdb"
|
2018-04-10 03:16:33 +02:00
|
|
|
(ifNotNull cfg.locality "--locality='${cfg.locality}'")
|
|
|
|
|
|
|
|
# WebUI settings
|
|
|
|
"--http-addr='${cfg.http.address}:${toString cfg.http.port}'"
|
|
|
|
|
|
|
|
# Cluster listen address
|
|
|
|
"--listen-addr='${cfg.listen.address}:${toString cfg.listen.port}'"
|
|
|
|
|
|
|
|
# Cluster configuration
|
|
|
|
(ifNotNull cfg.join "--join=${cfg.join}")
|
|
|
|
|
|
|
|
# Cache and memory settings. Must be escaped.
|
|
|
|
"--cache='${escape cfg.cache}'"
|
|
|
|
"--max-sql-memory='${escape cfg.maxSqlMemory}'"
|
|
|
|
|
|
|
|
# Certificate/security settings.
|
|
|
|
(if cfg.insecure then "--insecure" else "--certs-dir=${cfg.certsDir}")
|
|
|
|
];
|
|
|
|
|
|
|
|
addressOption = descr: defaultPort: {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "Address to bind to for ${descr}";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
type = types.port;
|
2018-04-10 03:16:33 +02:00
|
|
|
default = defaultPort;
|
|
|
|
description = "Port to bind to for ${descr}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.cockroachdb = {
|
|
|
|
enable = mkEnableOption "CockroachDB Server";
|
|
|
|
|
|
|
|
listen = addressOption "intra-cluster communication" 26257;
|
|
|
|
|
|
|
|
http = addressOption "http-based Admin UI" 8080;
|
|
|
|
|
|
|
|
locality = mkOption {
|
|
|
|
type = types.nullOr 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:
|
|
|
|
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
<literal>
|
2018-04-10 03:16:33 +02:00
|
|
|
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
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
</literal>
|
2018-04-10 03:16:33 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
join = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "The addresses for connecting the node to a cluster.";
|
|
|
|
};
|
|
|
|
|
|
|
|
insecure = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Run in insecure mode.";
|
|
|
|
};
|
|
|
|
|
|
|
|
certsDir = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = "The path to the certificate directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "cockroachdb";
|
|
|
|
description = "User account under which CockroachDB runs";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "cockroachdb";
|
|
|
|
description = "User account under which CockroachDB runs";
|
|
|
|
};
|
|
|
|
|
|
|
|
openPorts = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open firewall ports for cluster communication by default";
|
|
|
|
};
|
|
|
|
|
|
|
|
cache = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "25%";
|
|
|
|
description = ''
|
|
|
|
The total size for caches.
|
|
|
|
|
|
|
|
This can be a percentage, expressed with a fraction sign or as a
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
decimal-point number, or any bytes-based unit. For example,
|
|
|
|
<literal>"25%"</literal>, <literal>"0.25"</literal> both represent
|
|
|
|
25% of the available system memory. The values
|
|
|
|
<literal>"1000000000"</literal> and <literal>"1GB"</literal> both
|
|
|
|
represent 1 gigabyte of memory.
|
|
|
|
|
2018-04-10 03:16:33 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
maxSqlMemory = mkOption {
|
|
|
|
type = 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
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
decimal-point number, or any bytes-based unit. For example,
|
|
|
|
<literal>"25%"</literal>, <literal>"0.25"</literal> both represent
|
|
|
|
25% of the available system memory. The values
|
|
|
|
<literal>"1000000000"</literal> and <literal>"1GB"</literal> both
|
|
|
|
represent 1 gigabyte of memory.
|
2018-04-10 03:16:33 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.cockroachdb;
|
2018-12-02 22:16:24 +01:00
|
|
|
defaultText = "pkgs.cockroachdb";
|
2018-04-10 03:16:33 +02:00
|
|
|
description = ''
|
|
|
|
The CockroachDB derivation to use for running the service.
|
2019-11-22 22:28:17 +01:00
|
|
|
|
2018-04-10 03:16:33 +02:00
|
|
|
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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.services.cockroachdb.enable {
|
|
|
|
assertions = [
|
2019-04-24 05:48:22 +02:00
|
|
|
{ assertion = !cfg.insecure -> cfg.certsDir != null;
|
2018-04-10 03:16:33 +02:00
|
|
|
message = "CockroachDB must have a set of SSL certificates (.certsDir), or run in Insecure Mode (.insecure = true)";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ crdb ];
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == "cockroachdb") {
|
|
|
|
cockroachdb = {
|
2018-04-10 03:16:33 +02:00
|
|
|
description = "CockroachDB Server User";
|
|
|
|
uid = config.ids.uids.cockroachdb;
|
|
|
|
group = cfg.group;
|
2019-09-14 19:51:29 +02:00
|
|
|
};
|
|
|
|
};
|
2018-04-10 03:16:33 +02:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups = optionalAttrs (cfg.group == "cockroachdb") {
|
|
|
|
cockroachdb.gid = config.ids.gids.cockroachdb;
|
|
|
|
};
|
2018-04-10 03:16:33 +02:00
|
|
|
|
|
|
|
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" ];
|
|
|
|
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/cockroachdb";
|
2018-04-10 03:16:33 +02:00
|
|
|
|
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart = startupCommand;
|
|
|
|
Type = "notify";
|
|
|
|
User = cfg.user;
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
StateDirectory = "cockroachdb";
|
|
|
|
StateDirectoryMode = "0700";
|
2018-04-10 03:16:33 +02:00
|
|
|
|
|
|
|
Restart = "always";
|
nixos/cockroachdb: simplify dataDir management, tweaks
This cleans up the CockroachDB expression, with a few suggestions from
@aszlig.
However, it brought up the note of using systemd's StateDirectory=
directive, which is a nice feature for managing long-term data files,
especially for UID/GID assigned services. However, it can only manage
directories under /var/lib (for global services), so it has to introduce
a special path to make use of it at all in the case someone wants a path
at a different root.
While the dataDir directive at the NixOS level is _occasionally_ useful,
I've gone ahead and removed it for now, as this expression is so new,
and it makes the expression cleaner, while other kinks can be worked out
and people can test drive it.
CockroachDB's dataDir directive, instead, has been replaced with
systemd's StateDirectory management to place the data under
/var/lib/cockroachdb for all uses.
There's an included RequiresMountsFor= clause like usual though, so if
people want dependencies for any kind of mounted device at boot
time/before database startup, it's easy to specify using their own
mount/filesystems clause.
This can also be reverted if necessary, but, we can see if anyone ever
actually wants that later on before doing it -- it's a backwards
compatible change, anyway.
Signed-off-by: Austin Seipp <aseipp@pobox.com>
2018-12-05 00:35:16 +01:00
|
|
|
|
|
|
|
# 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;
|
2018-04-10 03:16:33 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ thoughtpolice ];
|
|
|
|
}
|