fork/home-manager

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

midchildanmodules: add platform assertions17dc5939

master
2.2 KiB94 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.stalonetray;
8
9in {
10  options = {
11    services.stalonetray = {
12      enable = mkEnableOption "Stalonetray system tray";
13
14      package = mkOption {
15        default = pkgs.stalonetray;
16        defaultText = literalExpression "pkgs.stalonetray";
17        type = types.package;
18        example = literalExpression "pkgs.stalonetray";
19        description = "The package to use for the Stalonetray binary.";
20      };
21
22      config = mkOption {
23        type = with types; attrsOf (nullOr (either str (either bool int)));
24        description = ''
25          Stalonetray configuration as a set of attributes.
26        '';
27        default = { };
28        example = {
29          geometry = "3x1-600+0";
30          decorations = null;
31          icon_size = 30;
32          sticky = true;
33          background = "#cccccc";
34        };
35      };
36
37      extraConfig = mkOption {
38        type = types.lines;
39        description = "Additional configuration lines for stalonetrayrc.";
40        default = "";
41        example = ''
42          geometry 3x1-600+0
43          decorations none
44          icon_size 30
45          sticky true
46          background "#cccccc"
47        '';
48      };
49    };
50  };
51
52  config = mkIf cfg.enable (mkMerge [
53    {
54      assertions = [
55        (hm.assertions.assertPlatform "services.stalonetray" pkgs
56          platforms.linux)
57      ];
58
59      home.packages = [ cfg.package ];
60
61      systemd.user.services.stalonetray = {
62        Unit = {
63          Description = "Stalonetray system tray";
64          PartOf = [ "tray.target" ];
65        };
66
67        Install = { WantedBy = [ "tray.target" ]; };
68
69        Service = {
70          ExecStart = "${cfg.package}/bin/stalonetray";
71          Restart = "on-failure";
72        };
73      };
74    }
75
76    (mkIf (cfg.config != { }) {
77      home.file.".stalonetrayrc".text = let
78        valueToString = v:
79          if isBool v then
80            (if v then "true" else "false")
81          else if (v == null) then
82            "none"
83          else
84            ''"${toString v}"'';
85      in concatStrings (mapAttrsToList (k: v: ''
86        ${k} ${valueToString v}
87      '') cfg.config);
88    })
89
90    (mkIf (cfg.extraConfig != "") {
91      home.file.".stalonetrayrc".text = cfg.extraConfig;
92    })
93  ]);
94}