summary refs log tree commit diff
path: root/nixos/modules/services/display-managers/greetd.nix
blob: 89cb81f3a78f6159420e5615672d07885c302680 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{ config, lib, pkgs, ... }:
with lib;

let
  cfg = config.services.greetd;
  tty = "tty${toString cfg.vt}";
  settingsFormat = pkgs.formats.toml {};
in
{
  options.services.greetd = {
    enable = mkEnableOption (lib.mdDoc "greetd");

    package = mkOption {
      type = types.package;
      default = pkgs.greetd.greetd;
      defaultText = literalExpression "pkgs.greetd.greetd";
      description = lib.mdDoc "The greetd package that should be used.";
    };

    settings = mkOption {
      type = settingsFormat.type;
      example = literalExpression ''
        {
          default_session = {
            command = "''${pkgs.greetd.greetd}/bin/agreety --cmd sway";
          };
        }
      '';
      description = lib.mdDoc ''
        greetd configuration ([documentation](https://man.sr.ht/~kennylevinsen/greetd/))
        as a Nix attribute set.
      '';
    };

    vt = mkOption  {
      type = types.int;
      default = 1;
      description = lib.mdDoc ''
        The virtual console (tty) that greetd should use. This option also disables getty on that tty.
      '';
    };

    restart = mkOption {
      type = types.bool;
      default = !(cfg.settings ? initial_session);
      defaultText = literalExpression "!(config.services.greetd.settings ? initial_session)";
      description = lib.mdDoc ''
        Whether to restart greetd when it terminates (e.g. on failure).
        This is usually desirable so a user can always log in, but should be disabled when using 'settings.initial_session' (autologin),
        because every greetd restart will trigger the autologin again.
      '';
    };
  };
  config = mkIf cfg.enable {

    services.greetd.settings.terminal.vt = mkDefault cfg.vt;
    services.greetd.settings.default_session.user = mkDefault "greeter";

    security.pam.services.greetd = {
      allowNullPassword = true;
      startSession = true;
      enableGnomeKeyring = mkDefault config.services.gnome.gnome-keyring.enable;
    };

    # This prevents nixos-rebuild from killing greetd by activating getty again
    systemd.services."autovt@${tty}".enable = false;

    systemd.services.greetd = {
      unitConfig = {
        Wants = [
          "systemd-user-sessions.service"
        ];
        After = [
          "systemd-user-sessions.service"
          "plymouth-quit-wait.service"
          "getty@${tty}.service"
        ];
        Conflicts = [
          "getty@${tty}.service"
        ];
      };

      serviceConfig = {
        ExecStart = "${pkgs.greetd.greetd}/bin/greetd --config ${settingsFormat.generate "greetd.toml" cfg.settings}";

        Restart = mkIf cfg.restart "always";

        # Defaults from greetd upstream configuration
        IgnoreSIGPIPE = false;
        SendSIGHUP = true;
        TimeoutStopSec = "30s";
        KeyringMode = "shared";

        Type = "idle";
      };

      # Don't kill a user session when using nixos-rebuild
      restartIfChanged = false;

      wantedBy = [ "graphical.target" ];
    };

    systemd.defaultUnit = "graphical.target";

    users.users.greeter = {
      isSystemUser = true;
      group = "greeter";
    };

    users.groups.greeter = {};
  };

  meta.maintainers = with maintainers; [ queezle ];
}