at 25.11-pre 3.4 kB view raw
1# Udisks daemon. 2{ 3 config, 4 lib, 5 pkgs, 6 ... 7}: 8let 9 cfg = config.services.udisks2; 10 settingsFormat = pkgs.formats.ini { 11 listToValue = lib.concatMapStringsSep "," (lib.generators.mkValueStringDefault { }); 12 }; 13 configFiles = lib.mapAttrs (name: value: (settingsFormat.generate name value)) ( 14 lib.mapAttrs' (name: value: lib.nameValuePair name value) config.services.udisks2.settings 15 ); 16in 17 18{ 19 20 ###### interface 21 22 options = { 23 24 services.udisks2 = { 25 26 enable = lib.mkEnableOption "udisks2, a DBus service that allows applications to query and manipulate storage devices"; 27 28 package = lib.mkPackageOption pkgs "udisks2" { }; 29 30 mountOnMedia = lib.mkOption { 31 type = lib.types.bool; 32 default = false; 33 description = '' 34 When enabled, instructs udisks2 to mount removable drives under `/media/` directory, instead of the 35 default, ACL-controlled `/run/media/$USER/`. Since `/media/` is not mounted as tmpfs by default, it 36 requires cleanup to get rid of stale mountpoints; enabling this option will take care of this at boot. 37 ''; 38 }; 39 40 settings = lib.mkOption rec { 41 type = lib.types.attrsOf settingsFormat.type; 42 apply = lib.recursiveUpdate default; 43 default = { 44 "udisks2.conf" = { 45 udisks2 = { 46 modules = [ "*" ]; 47 modules_load_preference = "ondemand"; 48 }; 49 defaults = { 50 encryption = "luks2"; 51 }; 52 }; 53 }; 54 example = lib.literalExpression '' 55 { 56 "WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = { 57 ATA = { 58 StandbyTimeout = 50; 59 }; 60 }; 61 }; 62 ''; 63 description = '' 64 Options passed to udisksd. 65 See [here](http://manpages.ubuntu.com/manpages/latest/en/man5/udisks2.conf.5.html) and 66 drive configuration in [here](http://manpages.ubuntu.com/manpages/latest/en/man8/udisks.8.html) for supported options. 67 ''; 68 }; 69 70 }; 71 72 }; 73 74 ###### implementation 75 76 config = lib.mkIf config.services.udisks2.enable { 77 78 environment.systemPackages = [ cfg.package ]; 79 80 environment.etc = 81 (lib.mapAttrs' (name: value: lib.nameValuePair "udisks2/${name}" { source = value; }) configFiles) 82 // ( 83 let 84 libblockdev = cfg.package.libblockdev; 85 majorVer = lib.versions.major libblockdev.version; 86 in 87 { 88 # We need to make sure /etc/libblockdev/@major_ver@/conf.d is populated to avoid 89 # warnings 90 "libblockdev/${majorVer}/conf.d/00-default.cfg".source = 91 "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/00-default.cfg"; 92 "libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg".source = 93 "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg"; 94 } 95 ); 96 97 security.polkit.enable = true; 98 99 services.dbus.packages = [ cfg.package ]; 100 101 systemd.tmpfiles.rules = [ 102 "d /var/lib/udisks2 0755 root root -" 103 ] ++ lib.optional cfg.mountOnMedia "D! /media 0755 root root -"; 104 105 services.udev.packages = [ cfg.package ]; 106 107 services.udev.extraRules = lib.optionalString cfg.mountOnMedia '' 108 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1" 109 ''; 110 111 systemd.packages = [ cfg.package ]; 112 }; 113 114}