fork/home-manager

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

Robert HelgessonMerge branch 'literalExpression' [#2371]4fa1ba72

master
1.7 KiB72 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.services.dwm-status;
7
8  jsonFormat = pkgs.formats.json { };
9
10  features = [ "audio" "backlight" "battery" "cpu_load" "network" "time" ];
11
12  finalConfig = { inherit (cfg) order; } // cfg.extraConfig;
13
14  configFile = jsonFormat.generate "dwm-status.json" finalConfig;
15
16in {
17  options = {
18    services.dwm-status = {
19      enable = mkEnableOption "dwm-status user service";
20
21      package = mkOption {
22        type = types.package;
23        default = pkgs.dwm-status;
24        defaultText = literalExpression "pkgs.dwm-status";
25        example = "pkgs.dwm-status.override { enableAlsaUtils = false; }";
26        description = "Which dwm-status package to use.";
27      };
28
29      order = mkOption {
30        type = types.listOf (types.enum features);
31        description = "List of enabled features in order.";
32      };
33
34      extraConfig = mkOption {
35        type = jsonFormat.type;
36        default = { };
37        example = literalExpression ''
38          {
39            separator = "#";
40
41            battery = {
42              notifier_levels = [ 2 5 10 15 20 ];
43            };
44
45            time = {
46              format = "%H:%M";
47            };
48          }
49        '';
50        description = "Extra config of dwm-status.";
51      };
52    };
53  };
54
55  config = mkIf cfg.enable {
56    assertions = [
57      (lib.hm.assertions.assertPlatform "services.dwm-status" pkgs
58        lib.platforms.linux)
59    ];
60
61    systemd.user.services.dwm-status = {
62      Unit = {
63        Description = "DWM status service";
64        PartOf = [ "graphical-session.target" ];
65      };
66
67      Install = { WantedBy = [ "graphical-session.target" ]; };
68
69      Service = { ExecStart = "${cfg.package}/bin/dwm-status ${configFile}"; };
70    };
71  };
72}