2 { config, lib, pkgs, ... }:
6 cfg = config.services.udisks2;
7 settingsFormat = pkgs.formats.ini {
8 listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {});
10 configFiles = mapAttrs (name: value: (settingsFormat.generate name value)) (mapAttrs' (name: value: nameValuePair name value ) config.services.udisks2.settings);
21 enable = mkEnableOption (mdDoc "udisks2, a DBus service that allows applications to query and manipulate storage devices");
23 mountOnMedia = mkOption {
26 description = mdDoc ''
27 When enabled, instructs udisks2 to mount removable drives under `/media/` directory, instead of the
28 default, ACL-controlled `/run/media/$USER/`. Since `/media/` is not mounted as tmpfs by default, it
29 requires cleanup to get rid of stale mountpoints; enabling this option will take care of this at boot.
33 settings = mkOption rec {
34 type = types.attrsOf settingsFormat.type;
35 apply = recursiveUpdate default;
40 modules_load_preference = "ondemand";
47 example = literalExpression ''
49 "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = {
56 description = mdDoc ''
57 Options passed to udisksd.
58 See [here](http://manpages.ubuntu.com/manpages/latest/en/man5/udisks2.conf.5.html) and
59 drive configuration in [here](http://manpages.ubuntu.com/manpages/latest/en/man8/udisks.8.html) for supported options.
70 config = mkIf config.services.udisks2.enable {
72 environment.systemPackages = [ pkgs.udisks2 ];
74 environment.etc = (mapAttrs' (name: value: nameValuePair "udisks2/${name}" { source = value; } ) configFiles) // (
76 libblockdev = pkgs.udisks2.libblockdev;
77 majorVer = versions.major libblockdev.version;
79 # We need to make sure /etc/libblockdev/@major_ver@/conf.d is populated to avoid
81 "libblockdev/${majorVer}/conf.d/00-default.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/00-default.cfg";
82 "libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg";
85 security.polkit.enable = true;
87 services.dbus.packages = [ pkgs.udisks2 ];
89 systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ]
90 ++ optional cfg.mountOnMedia "D! /media 0755 root root -";
92 services.udev.packages = [ pkgs.udisks2 ];
94 services.udev.extraRules = optionalString cfg.mountOnMedia ''
95 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
98 systemd.packages = [ pkgs.udisks2 ];