at 24.11-pre 3.2 kB view raw
1# Udisks daemon. 2{ config, lib, pkgs, ... }: 3with lib; 4 5let 6 cfg = config.services.udisks2; 7 settingsFormat = pkgs.formats.ini { 8 listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {}); 9 }; 10 configFiles = mapAttrs (name: value: (settingsFormat.generate name value)) (mapAttrs' (name: value: nameValuePair name value ) config.services.udisks2.settings); 11in 12 13{ 14 15 ###### interface 16 17 options = { 18 19 services.udisks2 = { 20 21 enable = mkEnableOption "udisks2, a DBus service that allows applications to query and manipulate storage devices"; 22 23 mountOnMedia = mkOption { 24 type = types.bool; 25 default = false; 26 description = '' 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. 30 ''; 31 }; 32 33 settings = mkOption rec { 34 type = types.attrsOf settingsFormat.type; 35 apply = recursiveUpdate default; 36 default = { 37 "udisks2.conf" = { 38 udisks2 = { 39 modules = [ "*" ]; 40 modules_load_preference = "ondemand"; 41 }; 42 defaults = { 43 encryption = "luks2"; 44 }; 45 }; 46 }; 47 example = literalExpression '' 48 { 49 "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = { 50 ATA = { 51 StandbyTimeout = 50; 52 }; 53 }; 54 }; 55 ''; 56 description = '' 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. 60 ''; 61 }; 62 63 }; 64 65 }; 66 67 68 ###### implementation 69 70 config = mkIf config.services.udisks2.enable { 71 72 environment.systemPackages = [ pkgs.udisks2 ]; 73 74 environment.etc = (mapAttrs' (name: value: nameValuePair "udisks2/${name}" { source = value; } ) configFiles) // ( 75 let 76 libblockdev = pkgs.udisks2.libblockdev; 77 majorVer = versions.major libblockdev.version; 78 in { 79 # We need to make sure /etc/libblockdev/@major_ver@/conf.d is populated to avoid 80 # warnings 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"; 83 }); 84 85 security.polkit.enable = true; 86 87 services.dbus.packages = [ pkgs.udisks2 ]; 88 89 systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ] 90 ++ optional cfg.mountOnMedia "D! /media 0755 root root -"; 91 92 services.udev.packages = [ pkgs.udisks2 ]; 93 94 services.udev.extraRules = optionalString cfg.mountOnMedia '' 95 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1" 96 ''; 97 98 systemd.packages = [ pkgs.udisks2 ]; 99 }; 100 101}