tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos: init corosync, pacemaker modules
Astro
4 years ago
a60ab35d
68c44db7
+166
3 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
cluster
corosync
default.nix
pacemaker
default.nix
+2
nixos/modules/module-list.nix
···
301
301
./services/backup/znapzend.nix
302
302
./services/blockchain/ethereum/geth.nix
303
303
./services/backup/zrepl.nix
304
304
+
./services/cluster/corosync/default.nix
304
305
./services/cluster/hadoop/default.nix
305
306
./services/cluster/k3s/default.nix
306
307
./services/cluster/kubernetes/addons/dns.nix
···
313
314
./services/cluster/kubernetes/pki.nix
314
315
./services/cluster/kubernetes/proxy.nix
315
316
./services/cluster/kubernetes/scheduler.nix
317
317
+
./services/cluster/pacemaker/default.nix
316
318
./services/cluster/spark/default.nix
317
319
./services/computing/boinc/client.nix
318
320
./services/computing/foldingathome/client.nix
+112
nixos/modules/services/cluster/corosync/default.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
let
5
5
+
cfg = config.services.corosync;
6
6
+
in
7
7
+
{
8
8
+
# interface
9
9
+
options.services.corosync = {
10
10
+
enable = mkEnableOption "corosync";
11
11
+
12
12
+
package = mkOption {
13
13
+
type = types.package;
14
14
+
default = pkgs.corosync;
15
15
+
defaultText = literalExpression "pkgs.corosync";
16
16
+
description = "Package that should be used for corosync.";
17
17
+
};
18
18
+
19
19
+
clusterName = mkOption {
20
20
+
type = types.str;
21
21
+
default = "nixcluster";
22
22
+
description = "Name of the corosync cluster.";
23
23
+
};
24
24
+
25
25
+
extraOptions = mkOption {
26
26
+
type = with types; listOf str;
27
27
+
default = [];
28
28
+
description = "Additional options with which to start corosync.";
29
29
+
};
30
30
+
31
31
+
nodelist = mkOption {
32
32
+
description = "Corosync nodelist: all cluster members.";
33
33
+
default = [];
34
34
+
type = with types; listOf (submodule {
35
35
+
options = {
36
36
+
nodeid = mkOption {
37
37
+
type = int;
38
38
+
description = "Node ID number";
39
39
+
};
40
40
+
name = mkOption {
41
41
+
type = str;
42
42
+
description = "Node name";
43
43
+
};
44
44
+
ring_addrs = mkOption {
45
45
+
type = listOf str;
46
46
+
description = "List of addresses, one for each ring.";
47
47
+
};
48
48
+
};
49
49
+
});
50
50
+
};
51
51
+
};
52
52
+
53
53
+
# implementation
54
54
+
config = mkIf cfg.enable {
55
55
+
environment.systemPackages = [ cfg.package ];
56
56
+
57
57
+
environment.etc."corosync/corosync.conf".text = ''
58
58
+
totem {
59
59
+
version: 2
60
60
+
secauth: on
61
61
+
cluster_name: ${cfg.clusterName}
62
62
+
transport: knet
63
63
+
}
64
64
+
65
65
+
nodelist {
66
66
+
${concatMapStrings ({ nodeid, name, ring_addrs }: ''
67
67
+
node {
68
68
+
nodeid: ${toString nodeid}
69
69
+
name: ${name}
70
70
+
${concatStrings (imap0 (i: addr: ''
71
71
+
ring${toString i}_addr: ${addr}
72
72
+
'') ring_addrs)}
73
73
+
}
74
74
+
'') cfg.nodelist}
75
75
+
}
76
76
+
77
77
+
quorum {
78
78
+
# only corosync_votequorum is supported
79
79
+
provider: corosync_votequorum
80
80
+
wait_for_all: 0
81
81
+
${optionalString (builtins.length cfg.nodelist < 3) ''
82
82
+
two_node: 1
83
83
+
''}
84
84
+
}
85
85
+
86
86
+
logging {
87
87
+
to_syslog: yes
88
88
+
}
89
89
+
'';
90
90
+
91
91
+
environment.etc."corosync/uidgid.d/root".text = ''
92
92
+
# allow pacemaker connection by root
93
93
+
uidgid {
94
94
+
uid: 0
95
95
+
gid: 0
96
96
+
}
97
97
+
'';
98
98
+
99
99
+
systemd.packages = [ cfg.package ];
100
100
+
systemd.services.corosync = {
101
101
+
wantedBy = [ "multi-user.target" ];
102
102
+
serviceConfig = {
103
103
+
StateDirectory = "corosync";
104
104
+
StateDirectoryMode = "0700";
105
105
+
};
106
106
+
};
107
107
+
108
108
+
environment.etc."sysconfig/corosync".text = lib.optionalString (cfg.extraOptions != []) ''
109
109
+
COROSYNC_OPTIONS="${lib.escapeShellArgs cfg.extraOptions}"
110
110
+
'';
111
111
+
};
112
112
+
}
+52
nixos/modules/services/cluster/pacemaker/default.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
let
5
5
+
cfg = config.services.pacemaker;
6
6
+
in
7
7
+
{
8
8
+
# interface
9
9
+
options.services.pacemaker = {
10
10
+
enable = mkEnableOption "pacemaker";
11
11
+
12
12
+
package = mkOption {
13
13
+
type = types.package;
14
14
+
default = pkgs.pacemaker;
15
15
+
defaultText = literalExpression "pkgs.pacemaker";
16
16
+
description = "Package that should be used for pacemaker.";
17
17
+
};
18
18
+
};
19
19
+
20
20
+
# implementation
21
21
+
config = mkIf cfg.enable {
22
22
+
assertions = [ {
23
23
+
assertion = config.services.corosync.enable;
24
24
+
message = ''
25
25
+
Enabling services.pacemaker requires a services.corosync configuration.
26
26
+
'';
27
27
+
} ];
28
28
+
29
29
+
environment.systemPackages = [ cfg.package ];
30
30
+
31
31
+
# required by pacemaker
32
32
+
users.users.hacluster = {
33
33
+
isSystemUser = true;
34
34
+
group = "pacemaker";
35
35
+
home = "/var/lib/pacemaker";
36
36
+
};
37
37
+
users.groups.pacemaker = {};
38
38
+
39
39
+
systemd.tmpfiles.rules = [
40
40
+
"d /var/log/pacemaker 0700 hacluster pacemaker -"
41
41
+
];
42
42
+
43
43
+
systemd.packages = [ cfg.package ];
44
44
+
systemd.services.pacemaker = {
45
45
+
wantedBy = [ "multi-user.target" ];
46
46
+
serviceConfig = {
47
47
+
StateDirectory = "pacemaker";
48
48
+
StateDirectoryMode = "0700";
49
49
+
};
50
50
+
};
51
51
+
};
52
52
+
}