1# Support for DRBD, the Distributed Replicated Block Device.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let cfg = config.services.drbd; in
8
9{
10
11 ###### interface
12
13 options = {
14
15 services.drbd.enable = mkOption {
16 default = false;
17 type = types.bool;
18 description = lib.mdDoc ''
19 Whether to enable support for DRBD, the Distributed Replicated
20 Block Device.
21 '';
22 };
23
24 services.drbd.config = mkOption {
25 default = "";
26 type = types.lines;
27 description = lib.mdDoc ''
28 Contents of the {file}`drbd.conf` configuration file.
29 '';
30 };
31
32 };
33
34
35 ###### implementation
36
37 config = mkIf cfg.enable {
38
39 environment.systemPackages = [ pkgs.drbd ];
40
41 services.udev.packages = [ pkgs.drbd ];
42
43 boot.kernelModules = [ "drbd" ];
44
45 boot.extraModprobeConfig =
46 ''
47 options drbd usermode_helper=/run/current-system/sw/bin/drbdadm
48 '';
49
50 environment.etc."drbd.conf" =
51 { source = pkgs.writeText "drbd.conf" cfg.config; };
52
53 systemd.services.drbd = {
54 after = [ "systemd-udev.settle.service" "network.target" ];
55 wants = [ "systemd-udev.settle.service" ];
56 wantedBy = [ "multi-user.target" ];
57 serviceConfig = {
58 ExecStart = "${pkgs.drbd}/sbin/drbdadm up all";
59 ExecStop = "${pkgs.drbd}/sbin/drbdadm down all";
60 };
61 };
62 };
63}