aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/services/udiskie.nix
blob: 2444d68ff931ef87cca30c44e43b3910b6230d00 (plain)
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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.udiskie;

  commandArgs = concatStringsSep " " (map (opt: "-" + opt) [
    (if cfg.automount then "a" else "A")
    (if cfg.notify then "n" else "N")
    ({
      always = "t";
      auto = "s";
      never = "T";
    }.${cfg.tray})
  ] ++ optional config.xsession.preferStatusNotifierItems "--appindicator");

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 "udiskie mount daemon";

      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.
          </para><para>
          The options are
          <variablelist>
          <varlistentry>
            <term><literal>always</literal></term>
            <listitem><para>Always show tray icon.</para></listitem>
          </varlistentry>
          <varlistentry>
            <term><literal>auto</literal></term>
            <listitem><para>
              Show tray icon only when there is a device available.
            </para></listitem>
          </varlistentry>
          <varlistentry>
            <term><literal>never</literal></term>
            <listitem><para>Never show tray icon.</para></listitem>
          </varlistentry>
          </variablelist>
        '';
      };
    };
  };

  config = mkIf config.services.udiskie.enable {
    systemd.user.services.udiskie = {
      Unit = {
        Description = "udiskie mount daemon";
        After = [ "graphical-session-pre.target" ];
        PartOf = [ "graphical-session.target" ];
      };

      Service = {
        ExecStart = "${pkgs.udiskie}/bin/udiskie -2 ${commandArgs}";
      };

      Install = { WantedBy = [ "graphical-session.target" ]; };
    };
  };
}