summary refs log tree commit diff
path: root/nixos/modules/tasks/swraid.nix
blob: 93e03c44c868bf4f64a46f54dd926c27bbda34a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{ pkgs, ... }:

{

  environment.systemPackages = [ pkgs.mdadm ];

  services.udev.packages = [ pkgs.mdadm ];

  boot.initrd.availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ];

  boot.initrd.extraUdevRulesCommands = ''
    cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
  '';

  systemd.services.mdadm-shutdown = {
    wantedBy = [ "final.target"];
    after = [ "umount.target" ];

    unitConfig = {
      DefaultDependencies = false;
    };

    serviceConfig = {
      Type = "oneshot";
      ExecStart = ''${pkgs.mdadm}/bin/mdadm --wait-clean --scan'';
    };
  };

  systemd.services."mdmon@" = {
    description = "MD Metadata Monitor on /dev/%I";

    unitConfig.DefaultDependencies = false;

    serviceConfig = {
      Type = "forking";
      Environment = "IMSM_NO_PLATFORM=1";
      ExecStart = ''${pkgs.mdadm}/bin/mdmon --offroot --takeover %I'';
      KillMode = "none";
    };
  };

  systemd.services."mdadm-grow-continue@" = {
    description = "Manage MD Reshape on /dev/%I";

    unitConfig.DefaultDependencies = false;

    serviceConfig = {
      ExecStart = ''${pkgs.mdadm}/bin/mdadm --grow --continue /dev/%I'';
      StandardInput = "null";
      StandardOutput = "null";
      StandardError = "null";
      KillMode = "none";
    };
  };
 
}