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 mountOnMedia = lib.mkOption {
22 type = lib.types.bool;
25 When enabled, instructs udisks2 to mount removable drives under `/media/` directory, instead of the
26 default, ACL-controlled `/run/media/$USER/`. Since `/media/` is not mounted as tmpfs by default, it
27 requires cleanup to get rid of stale mountpoints; enabling this option will take care of this at boot.
31 settings = lib.mkOption rec {
32 type = lib.types.attrsOf settingsFormat.type;
33 apply = lib.recursiveUpdate default;
38 modules_load_preference = "ondemand";
45 example = lib.literalExpression ''
47 "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = {
55 Options passed to udisksd.
56 See [here](http://manpages.ubuntu.com/manpages/latest/en/man5/udisks2.conf.5.html) and
57 drive configuration in [here](http://manpages.ubuntu.com/manpages/latest/en/man8/udisks.8.html) for supported options.
68 config = lib.mkIf config.services.udisks2.enable {
70 environment.systemPackages = [ pkgs.udisks2 ];
72 environment.etc = (lib.mapAttrs' (name: value: lib.nameValuePair "udisks2/${name}" { source = value; } ) configFiles) // (
74 libblockdev = pkgs.udisks2.libblockdev;
75 majorVer = lib.versions.major libblockdev.version;
77 # We need to make sure /etc/libblockdev/@major_ver@/conf.d is populated to avoid
79 "libblockdev/${majorVer}/conf.d/00-default.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/00-default.cfg";
80 "libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg";
83 security.polkit.enable = true;
85 services.dbus.packages = [ pkgs.udisks2 ];
87 systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ]
88 ++ lib.optional cfg.mountOnMedia "D! /media 0755 root root -";
90 services.udev.packages = [ pkgs.udisks2 ];
92 services.udev.extraRules = lib.optionalString cfg.mountOnMedia ''
93 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
96 systemd.packages = [ pkgs.udisks2 ];