2022-03-02 22:38:42 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.corosync;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
# interface
|
|
|
|
options.services.corosync = {
|
2024-12-08 13:18:22 +01:00
|
|
|
enable = lib.mkEnableOption "corosync";
|
2022-03-02 22:38:42 +01:00
|
|
|
|
2024-12-08 13:18:22 +01:00
|
|
|
package = lib.mkPackageOption pkgs "corosync" { };
|
2022-03-02 22:38:42 +01:00
|
|
|
|
2024-12-08 13:18:22 +01:00
|
|
|
clusterName = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2022-03-02 22:38:42 +01:00
|
|
|
default = "nixcluster";
|
|
|
|
description = "Name of the corosync cluster.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:22 +01:00
|
|
|
extraOptions = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
2022-03-02 22:38:42 +01:00
|
|
|
default = [ ];
|
|
|
|
description = "Additional options with which to start corosync.";
|
|
|
|
};
|
|
|
|
|
2024-12-08 13:18:22 +01:00
|
|
|
nodelist = lib.mkOption {
|
2022-03-02 22:38:42 +01:00
|
|
|
description = "Corosync nodelist: all cluster members.";
|
|
|
|
default = [ ];
|
2024-12-08 13:18:22 +01:00
|
|
|
type =
|
|
|
|
with lib.types;
|
|
|
|
listOf (submodule {
|
2022-03-02 22:38:42 +01:00
|
|
|
options = {
|
2024-12-08 13:18:22 +01:00
|
|
|
nodeid = lib.mkOption {
|
2022-03-02 22:38:42 +01:00
|
|
|
type = int;
|
|
|
|
description = "Node ID number";
|
|
|
|
};
|
2024-12-08 13:18:22 +01:00
|
|
|
name = lib.mkOption {
|
2022-03-02 22:38:42 +01:00
|
|
|
type = str;
|
|
|
|
description = "Node name";
|
|
|
|
};
|
2024-12-08 13:18:22 +01:00
|
|
|
ring_addrs = lib.mkOption {
|
2022-03-02 22:38:42 +01:00
|
|
|
type = listOf str;
|
|
|
|
description = "List of addresses, one for each ring.";
|
2024-12-10 20:26:33 +01:00
|
|
|
};
|
2022-03-02 22:38:42 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# implementation
|
2024-12-08 13:18:22 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
2022-03-02 22:38:42 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
environment.etc."corosync/corosync.conf".text = ''
|
|
|
|
totem {
|
|
|
|
version: 2
|
|
|
|
secauth: on
|
|
|
|
cluster_name: ${cfg.clusterName}
|
|
|
|
transport: knet
|
|
|
|
}
|
|
|
|
|
|
|
|
nodelist {
|
2024-12-08 13:18:22 +01:00
|
|
|
${lib.concatMapStrings (
|
|
|
|
{
|
|
|
|
nodeid,
|
|
|
|
name,
|
|
|
|
ring_addrs,
|
|
|
|
}:
|
|
|
|
''
|
2022-03-02 22:38:42 +01:00
|
|
|
node {
|
|
|
|
nodeid: ${toString nodeid}
|
|
|
|
name: ${name}
|
2024-12-08 13:18:22 +01:00
|
|
|
${lib.concatStrings (
|
|
|
|
lib.imap0 (i: addr: ''
|
2022-03-02 22:38:42 +01:00
|
|
|
ring${toString i}_addr: ${addr}
|
|
|
|
'') ring_addrs
|
|
|
|
)}
|
|
|
|
}
|
|
|
|
''
|
|
|
|
) cfg.nodelist}
|
|
|
|
}
|
|
|
|
|
|
|
|
quorum {
|
|
|
|
# only corosync_votequorum is supported
|
|
|
|
provider: corosync_votequorum
|
|
|
|
wait_for_all: 0
|
2024-12-08 13:18:22 +01:00
|
|
|
${lib.optionalString (builtins.length cfg.nodelist < 3) ''
|
2022-03-02 22:38:42 +01:00
|
|
|
two_node: 1
|
|
|
|
''}
|
|
|
|
}
|
|
|
|
|
|
|
|
logging {
|
|
|
|
to_syslog: yes
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.etc."corosync/uidgid.d/root".text = ''
|
|
|
|
# allow pacemaker connection by root
|
|
|
|
uidgid {
|
|
|
|
uid: 0
|
|
|
|
gid: 0
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.packages = [ cfg.package ];
|
|
|
|
systemd.services.corosync = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
StateDirectory = "corosync";
|
|
|
|
StateDirectoryMode = "0700";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."sysconfig/corosync".text = lib.optionalString (cfg.extraOptions != [ ]) ''
|
|
|
|
COROSYNC_OPTIONS="${lib.escapeShellArgs cfg.extraOptions}"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|