2 { config, lib, pkgs, ... }:
4 cfg = config.services.udisks2;
5 settingsFormat = pkgs.formats.ini {
6 listToValue = lib.concatMapStringsSep "," (lib.generators.mkValueStringDefault {});
8 configFiles = lib.mapAttrs (name: value: (settingsFormat.generate name value)) (lib.mapAttrs' (name: value: lib.nameValuePair name value ) config.services.udisks2.settings);
19 enable = lib.mkEnableOption "udisks2, a DBus service that allows applications to query and manipulate storage devices";
21 package = lib.mkPackageOption pkgs "udisks2" {};
23 mountOnMedia = lib.mkOption {
24 type = lib.types.bool;
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 = lib.mkOption rec {
34 type = lib.types.attrsOf settingsFormat.type;
35 apply = lib.recursiveUpdate default;
40 modules_load_preference = "ondemand";
47 example = lib.literalExpression ''
49 "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = {
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 = lib.mkIf config.services.udisks2.enable {
72 environment.systemPackages = [ cfg.package ];
74 environment.etc = (lib.mapAttrs' (name: value: lib.nameValuePair "udisks2/${name}" { source = value; } ) configFiles) // (
76 libblockdev = cfg.package.libblockdev;
77 majorVer = lib.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 = [ cfg.package ];
89 systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ]
90 ++ lib.optional cfg.mountOnMedia "D! /media 0755 root root -";
92 services.udev.packages = [ cfg.package ];
94 services.udev.extraRules = lib.optionalString cfg.mountOnMedia ''
95 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
98 systemd.packages = [ cfg.package ];