1{
2 lib,
3 pkgs,
4 config,
5 ...
6}:
7let
8 cfg = config.programs.regreet;
9 settingsFormat = pkgs.formats.toml { };
10 user = config.services.greetd.settings.default_session.user;
11in
12{
13 options.programs.regreet = {
14 enable = lib.mkEnableOption null // {
15 description = ''
16 Enable ReGreet, a clean and customizable greeter for greetd.
17
18 To use ReGreet, {option}`services.greetd` has to be enabled and
19 {option}`services.greetd.settings.default_session` should contain the
20 appropriate configuration to launch
21 {option}`config.programs.regreet.package`. For examples, see the
22 [ReGreet Readme](https://github.com/rharish101/ReGreet#set-as-default-session).
23
24 A minimal configuration that launches ReGreet in {command}`cage` is
25 enabled by this module by default.
26 '';
27 };
28
29 package = lib.mkPackageOption pkgs "regreet" { };
30
31 settings = lib.mkOption {
32 type = settingsFormat.type;
33 default = { };
34 description = ''
35 ReGreet configuration file. Refer
36 <https://github.com/rharish101/ReGreet/blob/main/regreet.sample.toml>
37 for options.
38 '';
39 };
40
41 cageArgs = lib.mkOption {
42 type = lib.types.listOf lib.types.str;
43 default = [ "-s" ];
44 example = lib.literalExpression ''
45 [ "-s" "-m" "last" ]
46 '';
47 description = ''
48 Additional arguments to be passed to
49 [cage](https://github.com/cage-kiosk/cage).
50 '';
51 };
52
53 extraCss = lib.mkOption {
54 type = lib.types.either lib.types.path lib.types.lines;
55 default = "";
56 description = ''
57 Extra CSS rules to apply on top of the GTK theme. Refer to
58 [GTK CSS Properties](https://docs.gtk.org/gtk4/css-properties.html) for
59 modifiable properties.
60 '';
61 };
62
63 theme = {
64 package = lib.mkPackageOption pkgs "gnome-themes-extra" { } // {
65 description = ''
66 The package that provides the theme given in the name option.
67 '';
68 };
69
70 name = lib.mkOption {
71 type = lib.types.str;
72 default = "Adwaita";
73 description = ''
74 Name of the theme to use for regreet.
75 '';
76 };
77 };
78
79 iconTheme = {
80 package = lib.mkPackageOption pkgs "adwaita-icon-theme" { } // {
81 description = ''
82 The package that provides the icon theme given in the name option.
83 '';
84 };
85
86 name = lib.mkOption {
87 type = lib.types.str;
88 default = "Adwaita";
89 description = ''
90 Name of the icon theme to use for regreet.
91 '';
92 };
93 };
94
95 font = {
96 package = lib.mkPackageOption pkgs "cantarell-fonts" { } // {
97 description = ''
98 The package that provides the font given in the name option.
99 '';
100 };
101
102 name = lib.mkOption {
103 type = lib.types.str;
104 default = "Cantarell";
105 description = ''
106 Name of the font to use for regreet.
107 '';
108 };
109
110 size = lib.mkOption {
111 type = lib.types.ints.positive;
112 default = 16;
113 description = ''
114 Size of the font to use for regreet.
115 '';
116 };
117 };
118
119 cursorTheme = {
120 package = lib.mkPackageOption pkgs "adwaita-icon-theme" { } // {
121 description = ''
122 The package that provides the cursor theme given in the name option.
123 '';
124 };
125
126 name = lib.mkOption {
127 type = lib.types.str;
128 default = "Adwaita";
129 description = ''
130 Name of the cursor theme to use for regreet.
131 '';
132 };
133 };
134 };
135
136 config = lib.mkIf cfg.enable {
137 environment.systemPackages = [
138 cfg.theme.package
139 cfg.iconTheme.package
140 cfg.cursorTheme.package
141 ];
142
143 fonts.packages = [ cfg.font.package ];
144
145 programs.regreet.settings.GTK = {
146 cursor_theme_name = cfg.cursorTheme.name;
147 font_name = "${cfg.font.name} ${toString cfg.font.size}";
148 icon_theme_name = cfg.iconTheme.name;
149 theme_name = cfg.theme.name;
150 };
151
152 services.greetd = {
153 enable = lib.mkDefault true;
154 settings.default_session.command = lib.mkDefault "${pkgs.dbus}/bin/dbus-run-session ${lib.getExe pkgs.cage} ${lib.escapeShellArgs cfg.cageArgs} -- ${lib.getExe cfg.package}";
155 };
156
157 environment.etc = {
158 "greetd/regreet.css" =
159 if lib.isPath cfg.extraCss then { source = cfg.extraCss; } else { text = cfg.extraCss; };
160
161 "greetd/regreet.toml".source =
162 if lib.isPath cfg.settings then
163 cfg.settings
164 else
165 settingsFormat.generate "regreet.toml" cfg.settings;
166 };
167
168 systemd.tmpfiles.settings."10-regreet" =
169 let
170 defaultConfig = {
171 inherit user;
172 group =
173 if config.users.users.${user}.group != "" then config.users.users.${user}.group else "greeter";
174 mode = "0755";
175 };
176 dataDir =
177 if lib.versionAtLeast (cfg.package.version) "0.2.0" then
178 { "/var/lib/regreet".d = defaultConfig; }
179 else
180 { "/var/cache/regreet".d = defaultConfig; };
181 in
182 {
183 "/var/log/regreet".d = defaultConfig;
184 }
185 // dataDir;
186
187 assertions = [
188 {
189 assertion = (config.users.users.${user} or { }) != { };
190 message = "regreet: user ${user} does not exist. Please create it before referencing it.";
191 }
192 ];
193 };
194}