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