fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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