base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / nixos / modules / services / cluster / corosync / default.nix
blobcf3448620a5d78b8ce55c2ca870121295ebb2064
1 { config, lib, pkgs, ... }:
3 with lib;
4 let
5   cfg = config.services.corosync;
6 in
8   # interface
9   options.services.corosync = {
10     enable = mkEnableOption "corosync";
12     package = mkPackageOption pkgs "corosync" { };
14     clusterName = mkOption {
15       type = types.str;
16       default = "nixcluster";
17       description = "Name of the corosync cluster.";
18     };
20     extraOptions = mkOption {
21       type = with types; listOf str;
22       default = [];
23       description = "Additional options with which to start corosync.";
24     };
26     nodelist = mkOption {
27       description = "Corosync nodelist: all cluster members.";
28       default = [];
29       type = with types; listOf (submodule {
30         options = {
31           nodeid = mkOption {
32             type = int;
33             description = "Node ID number";
34           };
35           name = mkOption {
36             type = str;
37             description = "Node name";
38           };
39           ring_addrs = mkOption {
40             type = listOf str;
41             description = "List of addresses, one for each ring.";
42           };
43         };
44       });
45     };
46   };
48   # implementation
49   config = mkIf cfg.enable {
50     environment.systemPackages = [ cfg.package ];
52     environment.etc."corosync/corosync.conf".text = ''
53       totem {
54         version: 2
55         secauth: on
56         cluster_name: ${cfg.clusterName}
57         transport: knet
58       }
60       nodelist {
61         ${concatMapStrings ({ nodeid, name, ring_addrs }: ''
62           node {
63             nodeid: ${toString nodeid}
64             name: ${name}
65             ${concatStrings (imap0 (i: addr: ''
66               ring${toString i}_addr: ${addr}
67             '') ring_addrs)}
68           }
69         '') cfg.nodelist}
70       }
72       quorum {
73         # only corosync_votequorum is supported
74         provider: corosync_votequorum
75         wait_for_all: 0
76         ${optionalString (builtins.length cfg.nodelist < 3) ''
77           two_node: 1
78         ''}
79       }
81       logging {
82         to_syslog: yes
83       }
84     '';
86     environment.etc."corosync/uidgid.d/root".text = ''
87       # allow pacemaker connection by root
88       uidgid {
89         uid: 0
90         gid: 0
91       }
92     '';
94     systemd.packages = [ cfg.package ];
95     systemd.services.corosync = {
96       wantedBy = [ "multi-user.target" ];
97       serviceConfig = {
98         StateDirectory = "corosync";
99         StateDirectoryMode = "0700";
100       };
101     };
103     environment.etc."sysconfig/corosync".text = lib.optionalString (cfg.extraOptions != []) ''
104       COROSYNC_OPTIONS="${lib.escapeShellArgs cfg.extraOptions}"
105     '';
106   };