1{ config, lib, pkgs, ... }:
2with lib;
3
4let
5 cfg = config.services.greetd;
6 tty = "tty${toString cfg.vt}";
7 settingsFormat = pkgs.formats.toml {};
8in
9{
10 options.services.greetd = {
11 enable = mkEnableOption "greetd";
12
13 package = mkOption {
14 type = types.package;
15 default = pkgs.greetd.greetd;
16 defaultText = "pkgs.greetd.greetd";
17 description = "The greetd package that should be used.";
18 };
19
20 settings = mkOption {
21 type = settingsFormat.type;
22 example = literalExample ''
23 {
24 default_session = {
25 command = "''${pkgs.greetd.greetd}/bin/agreety --cmd sway";
26 };
27 }
28 '';
29 description = ''
30 greetd configuration (<link xlink:href="https://man.sr.ht/~kennylevinsen/greetd/">documentation</link>)
31 as a Nix attribute set.
32 '';
33 };
34
35 vt = mkOption {
36 type = types.int;
37 default = 1;
38 description = ''
39 The virtual console (tty) that greetd should use. This option also disables getty on that tty.
40 '';
41 };
42
43 restart = mkOption {
44 type = types.bool;
45 default = !(cfg.settings ? initial_session);
46 defaultText = "!(config.services.greetd.settings ? initial_session)";
47 description = ''
48 Wether to restart greetd when it terminates (e.g. on failure).
49 This is usually desirable so a user can always log in, but should be disabled when using 'settings.initial_session' (autologin),
50 because every greetd restart will trigger the autologin again.
51 '';
52 };
53 };
54 config = mkIf cfg.enable {
55
56 services.greetd.settings.terminal.vt = mkDefault cfg.vt;
57 services.greetd.settings.default_session = mkDefault "greeter";
58
59 security.pam.services.greetd = {
60 allowNullPassword = true;
61 startSession = true;
62 };
63
64 # This prevents nixos-rebuild from killing greetd by activating getty again
65 systemd.services."autovt@${tty}".enable = false;
66
67 systemd.services.greetd = {
68 unitConfig = {
69 Wants = [
70 "systemd-user-sessions.service"
71 ];
72 After = [
73 "systemd-user-sessions.service"
74 "plymouth-quit-wait.service"
75 "getty@${tty}.service"
76 ];
77 Conflicts = [
78 "getty@${tty}.service"
79 ];
80 };
81
82 serviceConfig = {
83 ExecStart = "${pkgs.greetd.greetd}/bin/greetd --config ${settingsFormat.generate "greetd.toml" cfg.settings}";
84
85 Restart = mkIf cfg.restart "always";
86
87 # Defaults from greetd upstream configuration
88 IgnoreSIGPIPE = false;
89 SendSIGHUP = true;
90 TimeoutStopSec = "30s";
91 KeyringMode = "shared";
92 };
93
94 # Don't kill a user session when using nixos-rebuild
95 restartIfChanged = false;
96
97 wantedBy = [ "graphical.target" ];
98 };
99
100 systemd.defaultUnit = "graphical.target";
101
102 users.users.greeter.isSystemUser = true;
103 };
104
105 meta.maintainers = with maintainers; [ queezle ];
106}