at 23.11-pre 3.0 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 (mdDoc "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 = 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. 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 = 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. 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 # We need to make sure /etc/libblockdev/conf.d is populated to avoid 76 # warnings 77 "libblockdev/conf.d/00-default.cfg".source = "${pkgs.libblockdev}/etc/libblockdev/conf.d/00-default.cfg"; 78 "libblockdev/conf.d/10-lvm-dbus.cfg".source = "${pkgs.libblockdev}/etc/libblockdev/conf.d/10-lvm-dbus.cfg"; 79 }; 80 81 security.polkit.enable = true; 82 83 services.dbus.packages = [ pkgs.udisks2 ]; 84 85 systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ] 86 ++ optional cfg.mountOnMedia "D! /media 0755 root root -"; 87 88 services.udev.packages = [ pkgs.udisks2 ]; 89 90 services.udev.extraRules = optionalString cfg.mountOnMedia '' 91 ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1" 92 ''; 93 94 systemd.packages = [ pkgs.udisks2 ]; 95 }; 96 97}