/
udiskie.nix
130 lines (105 loc) · 3.29 KB
/
udiskie.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{ config, lib, pkgs, ... }:
with lib;
let
mergeSets = sets: lists.fold attrsets.recursiveUpdate { } sets;
yaml = pkgs.formats.yaml { };
cfg = config.services.udiskie;
in {
meta.maintainers = [ maintainers.rycee ];
imports = [
(mkRemovedOptionModule [ "services" "udiskie" "sni" ] ''
Support for Status Notifier Items is now configured globally through the
xsession.preferStatusNotifierItems
option. Please change to use that instead.
'')
];
options = {
services.udiskie = {
enable = mkEnableOption "" // {
description = ''
Whether to enable the udiskie mount daemon.
Note, if you use NixOS then you must add
`services.udisks2.enable = true`
to your system configuration. Otherwise mounting will fail because
the Udisk2 DBus service is not found.
'';
};
settings = mkOption {
type = yaml.type;
default = { };
example = literalExpression ''
{
program_options = {
udisks_version = 2;
tray = true;
};
icon_names.media = [ "media-optical" ];
}
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/udiskie/config.yml`.
See <https://github.com/coldfix/udiskie/blob/master/doc/udiskie.8.txt#configuration>
for the full list of options.
'';
};
automount = mkOption {
type = types.bool;
default = true;
description = "Whether to automatically mount new devices.";
};
notify = mkOption {
type = types.bool;
default = true;
description = "Whether to show pop-up notifications.";
};
tray = mkOption {
type = types.enum [ "always" "auto" "never" ];
default = "auto";
description = ''
Whether to display tray icon.
The options are
`always`
: Always show tray icon.
`auto`
: Show tray icon only when there is a device available.
`never`
: Never show tray icon.
'';
};
};
};
config = mkIf config.services.udiskie.enable {
assertions = [
(hm.assertions.assertPlatform "services.udiskie" pkgs platforms.linux)
];
xdg.configFile."udiskie/config.yml".source =
yaml.generate "udiskie-config.yml" (mergeSets [
{
program_options = {
automount = cfg.automount;
tray = if cfg.tray == "always" then
true
else if cfg.tray == "never" then
false
else
"auto";
notify = cfg.notify;
};
}
cfg.settings
]);
systemd.user.services.udiskie = {
Unit = {
Description = "udiskie mount daemon";
Requires = lib.optional (cfg.tray != "never") "tray.target";
After = [ "graphical-session-pre.target" ]
++ lib.optional (cfg.tray != "never") "tray.target";
PartOf = [ "graphical-session.target" ];
};
Service.ExecStart = toString ([ "${pkgs.udiskie}/bin/udiskie" ]
++ optional config.xsession.preferStatusNotifierItems "--appindicator");
Install.WantedBy = [ "graphical-session.target" ];
};
};
}