2013-04-04 07:50:16 +00:00
|
|
|
# Udisks daemon.
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2022-04-03 06:22:08 +00:00
|
|
|
let
|
2022-01-01 19:37:02 +00:00
|
|
|
cfg = config.services.udisks2;
|
2022-04-03 06:22:08 +00:00
|
|
|
settingsFormat = pkgs.formats.ini {
|
2024-08-27 18:43:26 +00:00
|
|
|
listToValue = lib.concatMapStringsSep "," (lib.generators.mkValueStringDefault {});
|
2022-04-03 06:22:08 +00:00
|
|
|
};
|
2024-08-27 18:43:26 +00:00
|
|
|
configFiles = lib.mapAttrs (name: value: (settingsFormat.generate name value)) (lib.mapAttrs' (name: value: lib.nameValuePair name value ) config.services.udisks2.settings);
|
2022-04-03 06:22:08 +00:00
|
|
|
in
|
|
|
|
|
2013-04-04 07:50:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.udisks2 = {
|
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
enable = lib.mkEnableOption "udisks2, a DBus service that allows applications to query and manipulate storage devices";
|
2022-01-01 19:37:02 +00:00
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
mountOnMedia = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-01-01 19:37:02 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
When enabled, instructs udisks2 to mount removable drives under `/media/` directory, instead of the
|
|
|
|
default, ACL-controlled `/run/media/$USER/`. Since `/media/` is not mounted as tmpfs by default, it
|
|
|
|
requires cleanup to get rid of stale mountpoints; enabling this option will take care of this at boot.
|
|
|
|
'';
|
|
|
|
};
|
2013-04-04 07:50:16 +00:00
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
settings = lib.mkOption rec {
|
|
|
|
type = lib.types.attrsOf settingsFormat.type;
|
|
|
|
apply = lib.recursiveUpdate default;
|
2022-04-03 06:22:08 +00:00
|
|
|
default = {
|
|
|
|
"udisks2.conf" = {
|
|
|
|
udisks2 = {
|
|
|
|
modules = [ "*" ];
|
|
|
|
modules_load_preference = "ondemand";
|
|
|
|
};
|
|
|
|
defaults = {
|
|
|
|
encryption = "luks2";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-08-27 18:43:26 +00:00
|
|
|
example = lib.literalExpression ''
|
2022-04-03 06:22:08 +00:00
|
|
|
{
|
|
|
|
"WDC-WD10EZEX-60M2NA0-WD-WCC3F3SJ0698.conf" = {
|
|
|
|
ATA = {
|
|
|
|
StandbyTimeout = 50;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
2022-01-01 19:37:02 +00:00
|
|
|
description = ''
|
2022-04-03 06:22:08 +00:00
|
|
|
Options passed to udisksd.
|
|
|
|
See [here](http://manpages.ubuntu.com/manpages/latest/en/man5/udisks2.conf.5.html) and
|
|
|
|
drive configuration in [here](http://manpages.ubuntu.com/manpages/latest/en/man8/udisks.8.html) for supported options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-04-04 07:50:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
config = lib.mkIf config.services.udisks2.enable {
|
2013-04-04 07:50:16 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.udisks2 ];
|
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
environment.etc = (lib.mapAttrs' (name: value: lib.nameValuePair "udisks2/${name}" { source = value; } ) configFiles) // (
|
2023-07-23 02:46:13 +00:00
|
|
|
let
|
|
|
|
libblockdev = pkgs.udisks2.libblockdev;
|
2024-08-27 18:43:26 +00:00
|
|
|
majorVer = lib.versions.major libblockdev.version;
|
2023-07-23 02:46:13 +00:00
|
|
|
in {
|
|
|
|
# We need to make sure /etc/libblockdev/@major_ver@/conf.d is populated to avoid
|
2022-11-09 18:30:55 +00:00
|
|
|
# warnings
|
2023-07-23 02:46:13 +00:00
|
|
|
"libblockdev/${majorVer}/conf.d/00-default.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/00-default.cfg";
|
|
|
|
"libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg".source = "${libblockdev}/etc/libblockdev/${majorVer}/conf.d/10-lvm-dbus.cfg";
|
|
|
|
});
|
2022-04-03 06:22:08 +00:00
|
|
|
|
2022-03-02 16:38:36 +00:00
|
|
|
security.polkit.enable = true;
|
|
|
|
|
2013-04-04 07:50:16 +00:00
|
|
|
services.dbus.packages = [ pkgs.udisks2 ];
|
|
|
|
|
2022-01-01 19:37:02 +00:00
|
|
|
systemd.tmpfiles.rules = [ "d /var/lib/udisks2 0755 root root -" ]
|
2024-08-27 18:43:26 +00:00
|
|
|
++ lib.optional cfg.mountOnMedia "D! /media 0755 root root -";
|
2013-04-04 07:50:16 +00:00
|
|
|
|
2015-12-14 23:38:07 +00:00
|
|
|
services.udev.packages = [ pkgs.udisks2 ];
|
2018-07-08 14:35:10 +00:00
|
|
|
|
2024-08-27 18:43:26 +00:00
|
|
|
services.udev.extraRules = lib.optionalString cfg.mountOnMedia ''
|
2022-01-01 19:37:02 +00:00
|
|
|
ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
|
|
|
|
'';
|
|
|
|
|
2018-07-08 14:35:10 +00:00
|
|
|
systemd.packages = [ pkgs.udisks2 ];
|
2013-04-04 07:50:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|