lol

nixos: init corosync, pacemaker modules

Astro a60ab35d 68c44db7

+166
+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 + ./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 + ./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 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + let 5 + cfg = config.services.corosync; 6 + in 7 + { 8 + # interface 9 + options.services.corosync = { 10 + enable = mkEnableOption "corosync"; 11 + 12 + package = mkOption { 13 + type = types.package; 14 + default = pkgs.corosync; 15 + defaultText = literalExpression "pkgs.corosync"; 16 + description = "Package that should be used for corosync."; 17 + }; 18 + 19 + clusterName = mkOption { 20 + type = types.str; 21 + default = "nixcluster"; 22 + description = "Name of the corosync cluster."; 23 + }; 24 + 25 + extraOptions = mkOption { 26 + type = with types; listOf str; 27 + default = []; 28 + description = "Additional options with which to start corosync."; 29 + }; 30 + 31 + nodelist = mkOption { 32 + description = "Corosync nodelist: all cluster members."; 33 + default = []; 34 + type = with types; listOf (submodule { 35 + options = { 36 + nodeid = mkOption { 37 + type = int; 38 + description = "Node ID number"; 39 + }; 40 + name = mkOption { 41 + type = str; 42 + description = "Node name"; 43 + }; 44 + ring_addrs = mkOption { 45 + type = listOf str; 46 + description = "List of addresses, one for each ring."; 47 + }; 48 + }; 49 + }); 50 + }; 51 + }; 52 + 53 + # implementation 54 + config = mkIf cfg.enable { 55 + environment.systemPackages = [ cfg.package ]; 56 + 57 + environment.etc."corosync/corosync.conf".text = '' 58 + totem { 59 + version: 2 60 + secauth: on 61 + cluster_name: ${cfg.clusterName} 62 + transport: knet 63 + } 64 + 65 + nodelist { 66 + ${concatMapStrings ({ nodeid, name, ring_addrs }: '' 67 + node { 68 + nodeid: ${toString nodeid} 69 + name: ${name} 70 + ${concatStrings (imap0 (i: addr: '' 71 + ring${toString i}_addr: ${addr} 72 + '') ring_addrs)} 73 + } 74 + '') cfg.nodelist} 75 + } 76 + 77 + quorum { 78 + # only corosync_votequorum is supported 79 + provider: corosync_votequorum 80 + wait_for_all: 0 81 + ${optionalString (builtins.length cfg.nodelist < 3) '' 82 + two_node: 1 83 + ''} 84 + } 85 + 86 + logging { 87 + to_syslog: yes 88 + } 89 + ''; 90 + 91 + environment.etc."corosync/uidgid.d/root".text = '' 92 + # allow pacemaker connection by root 93 + uidgid { 94 + uid: 0 95 + gid: 0 96 + } 97 + ''; 98 + 99 + systemd.packages = [ cfg.package ]; 100 + systemd.services.corosync = { 101 + wantedBy = [ "multi-user.target" ]; 102 + serviceConfig = { 103 + StateDirectory = "corosync"; 104 + StateDirectoryMode = "0700"; 105 + }; 106 + }; 107 + 108 + environment.etc."sysconfig/corosync".text = lib.optionalString (cfg.extraOptions != []) '' 109 + COROSYNC_OPTIONS="${lib.escapeShellArgs cfg.extraOptions}" 110 + ''; 111 + }; 112 + }
+52
nixos/modules/services/cluster/pacemaker/default.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + let 5 + cfg = config.services.pacemaker; 6 + in 7 + { 8 + # interface 9 + options.services.pacemaker = { 10 + enable = mkEnableOption "pacemaker"; 11 + 12 + package = mkOption { 13 + type = types.package; 14 + default = pkgs.pacemaker; 15 + defaultText = literalExpression "pkgs.pacemaker"; 16 + description = "Package that should be used for pacemaker."; 17 + }; 18 + }; 19 + 20 + # implementation 21 + config = mkIf cfg.enable { 22 + assertions = [ { 23 + assertion = config.services.corosync.enable; 24 + message = '' 25 + Enabling services.pacemaker requires a services.corosync configuration. 26 + ''; 27 + } ]; 28 + 29 + environment.systemPackages = [ cfg.package ]; 30 + 31 + # required by pacemaker 32 + users.users.hacluster = { 33 + isSystemUser = true; 34 + group = "pacemaker"; 35 + home = "/var/lib/pacemaker"; 36 + }; 37 + users.groups.pacemaker = {}; 38 + 39 + systemd.tmpfiles.rules = [ 40 + "d /var/log/pacemaker 0700 hacluster pacemaker -" 41 + ]; 42 + 43 + systemd.packages = [ cfg.package ]; 44 + systemd.services.pacemaker = { 45 + wantedBy = [ "multi-user.target" ]; 46 + serviceConfig = { 47 + StateDirectory = "pacemaker"; 48 + StateDirectoryMode = "0700"; 49 + }; 50 + }; 51 + }; 52 + }