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