1 { config, lib, pkgs, ... }:
5 cfg = config.services.corosync;
9 options.services.corosync = {
10 enable = mkEnableOption "corosync";
12 package = mkPackageOption pkgs "corosync" { };
14 clusterName = mkOption {
16 default = "nixcluster";
17 description = "Name of the corosync cluster.";
20 extraOptions = mkOption {
21 type = with types; listOf str;
23 description = "Additional options with which to start corosync.";
27 description = "Corosync nodelist: all cluster members.";
29 type = with types; listOf (submodule {
33 description = "Node ID number";
37 description = "Node name";
39 ring_addrs = mkOption {
41 description = "List of addresses, one for each ring.";
49 config = mkIf cfg.enable {
50 environment.systemPackages = [ cfg.package ];
52 environment.etc."corosync/corosync.conf".text = ''
56 cluster_name: ${cfg.clusterName}
61 ${concatMapStrings ({ nodeid, name, ring_addrs }: ''
63 nodeid: ${toString nodeid}
65 ${concatStrings (imap0 (i: addr: ''
66 ring${toString i}_addr: ${addr}
73 # only corosync_votequorum is supported
74 provider: corosync_votequorum
76 ${optionalString (builtins.length cfg.nodelist < 3) ''
86 environment.etc."corosync/uidgid.d/root".text = ''
87 # allow pacemaker connection by root
94 systemd.packages = [ cfg.package ];
95 systemd.services.corosync = {
96 wantedBy = [ "multi-user.target" ];
98 StateDirectory = "corosync";
99 StateDirectoryMode = "0700";
103 environment.etc."sysconfig/corosync".text = lib.optionalString (cfg.extraOptions != []) ''
104 COROSYNC_OPTIONS="${lib.escapeShellArgs cfg.extraOptions}"