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 = ''
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.string;
27 description = ''
28 Contents of the <filename>drbd.conf</filename> 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 = singleton
51 { source = pkgs.writeText "drbd.conf" cfg.config;
52 target = "drbd.conf";
53 };
54
55 systemd.services.drbd = {
56 after = [ "systemd-udev.settle.service" ];
57 wants = [ "systemd-udev.settle.service" ];
58 wantedBy = [ "ip-up.target" ];
59 script = ''
60 ${pkgs.drbd}/sbin/drbdadm up all
61 '';
62 serviceConfig.ExecStop = ''
63 ${pkgs.drbd}/sbin/drbdadm down all
64 '';
65 };
66 };
67}