fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.7 KiB148 linesraw
1{ config, lib, pkgs, ... }:
2
3let
4  inherit (lib) all filterAttrs isStorePath literalExpression types;
5  inherit (lib.options) mkEnableOption mkPackageOption mkOption;
6  inherit (lib.modules) mkIf;
7  inherit (lib.strings) concatMapStrings;
8  inherit (builtins) toJSON;
9
10  cfg = config.programs.wlogout;
11
12  jsonFormat = pkgs.formats.json { };
13
14  wlogoutLayoutConfig = with types;
15    submodule {
16      freeformType = jsonFormat.type;
17
18      options = {
19        label = mkOption {
20          type = str;
21          default = "";
22          example = "shutdown";
23          description = "CSS label of button.";
24        };
25
26        action = mkOption {
27          type = either path str;
28          default = "";
29          example = "systemctl poweroff";
30          description = "Command to execute when clicked.";
31        };
32
33        text = mkOption {
34          type = str;
35          default = "";
36          example = "Shutdown";
37          description = "Text displayed on button.";
38        };
39
40        keybind = mkOption {
41          type = str;
42          default = "";
43          example = "s";
44          description = "Keyboard character to trigger this action.";
45        };
46
47        height = mkOption {
48          type = nullOr (numbers.between 0 1);
49          default = null;
50          example = 0.5;
51          description = "Relative height of tile.";
52        };
53
54        width = mkOption {
55          type = nullOr (numbers.between 0 1);
56          default = null;
57          example = 0.5;
58          description = "Relative width of tile.";
59        };
60
61        circular = mkOption {
62          type = nullOr bool;
63          default = null;
64          example = true;
65          description = "Make button circular.";
66        };
67      };
68    };
69in {
70  meta.maintainers = [ lib.maintainers.Scrumplex ];
71
72  options.programs.wlogout = with lib.types; {
73    enable = mkEnableOption "wlogout";
74
75    package = mkPackageOption pkgs "wlogout" { };
76
77    layout = mkOption {
78      type = listOf wlogoutLayoutConfig;
79      default = [ ];
80      description = ''
81        Layout configuration for wlogout, see <https://github.com/ArtsyMacaw/wlogout#config>
82        for supported values.
83      '';
84      example = literalExpression ''
85        [
86          {
87            label = "shutdown";
88            action = "systemctl poweroff";
89            text = "Shutdown";
90            keybind = "s";
91          }
92        ]
93      '';
94    };
95
96    style = mkOption {
97      type = nullOr (either path str);
98      default = null;
99      description = ''
100        CSS style of the bar.
101
102        See <https://github.com/ArtsyMacaw/wlogout#style>
103        for the documentation.
104
105        If the value is set to a path literal, then the path will be used as the css file.
106      '';
107      example = ''
108        window {
109          background: #16191C;
110        }
111
112        button {
113          color: #AAB2BF;
114        }
115      '';
116    };
117  };
118
119  config = let
120    # Removes nulls because wlogout ignores them.
121    # This is not recursive.
122    removeTopLevelNulls = filterAttrs (_: v: v != null);
123    cleanJSON = foo: toJSON (removeTopLevelNulls foo);
124
125    # wlogout doesn't want a JSON array, it just wants a list of JSON objects
126    layoutJsons = map cleanJSON cfg.layout;
127    layoutContent = concatMapStrings (l: l + "\n") layoutJsons;
128
129  in mkIf cfg.enable {
130    assertions = [
131      (lib.hm.assertions.assertPlatform "programs.wlogout" pkgs
132        lib.platforms.linux)
133    ];
134
135    home.packages = [ cfg.package ];
136
137    xdg.configFile."wlogout/layout" = mkIf (cfg.layout != [ ]) {
138      source = pkgs.writeText "wlogout/layout" layoutContent;
139    };
140
141    xdg.configFile."wlogout/style.css" = mkIf (cfg.style != null) {
142      source = if builtins.isPath cfg.style || isStorePath cfg.style then
143        cfg.style
144      else
145        pkgs.writeText "wlogout/style.css" cfg.style;
146    };
147  };
148}