summary refs log tree commit diff
path: root/nixos/modules/services/hardware/udisks2.nix
blob: f9b5afceac3261017da948d077c748c6d7a682b0 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Udisks daemon.

{ config, lib, pkgs, ... }:

with lib;

let
  settingsFormat = pkgs.formats.ini {
    listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {});
  };
  configFiles = mapAttrs (name: value: (settingsFormat.generate name value)) (mapAttrs' (name: value: nameValuePair name value ) config.services.udisks2.settings);
in

{

  ###### interface

  options = {

    services.udisks2 = {

      enable = mkOption {
        type = types.bool;
        default = true;
        description = lib.mdDoc ''
          Whether to enable Udisks, a DBus service that allows
          applications to query and manipulate storage devices.
        '';
      };

      settings = mkOption rec {
        type = types.attrsOf settingsFormat.type;
        apply = recursiveUpdate default;
        default = {
          "udisks2.conf" = {
            udisks2 = {
              modules = [ "*" ];
              modules_load_preference = "ondemand";
            };
            defaults = {
              encryption = "luks2";
            };
          };
        };
        example = literalExpression ''
        {
          "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = {
            ATA = {
              StandbyTimeout = 50;
            };
          };
        };
        '';
        description = lib.mdDoc ''
          Options passed to udisksd.
          See [here](http://manpages.ubuntu.com/manpages/latest/en/man5/udisks2.conf.5.html) and
          drive configuration in [here](http://manpages.ubuntu.com/manpages/latest/en/man8/udisks.8.html) for supported options.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf config.services.udisks2.enable {

    environment.systemPackages = [ pkgs.udisks2 ];

    environment.etc = mapAttrs' (name: value: nameValuePair "udisks2/${name}" { source = value; } ) configFiles;

    security.polkit.enable = true;

    services.dbus.packages = [ pkgs.udisks2 ];

    systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ];

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

    systemd.packages = [ pkgs.udisks2 ];
  };

}