-
Notifications
You must be signed in to change notification settings - Fork 44
/
autostart.nix
156 lines (135 loc) · 4.7 KB
/
autostart.nix
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{ config, lib, pkgs, ... }:
let
inherit (lib)
mkDefault
mkIf
mkMerge
mkOption
types
;
cfg = config.jovian.steam;
in
{
options = {
jovian = {
steam = {
autoStart = mkOption {
type = types.bool;
default = false;
description = ''
Whether to automatically launch the Steam Deck UI on boot.
Traditional Display Managers cannot be enabled in conjunction with this option.
'';
};
user = mkOption {
type = types.str;
description = ''
The user to run Steam with.
'';
};
desktopSession = mkOption {
type = with types ; nullOr str // {
check = userProvidedDesktopSession:
lib.assertMsg (userProvidedDesktopSession != null -> (str.check userProvidedDesktopSession && lib.elem userProvidedDesktopSession config.services.displayManager.sessionData.sessionNames)) ''
Desktop session '${userProvidedDesktopSession}' not found.
Valid values for 'jovian.steam.desktopSession' are:
${lib.concatStringsSep "\n " config.services.displayManager.sessionData.sessionNames}
If you don't want a desktop session to switch to, set 'jovian.steam.desktopSession' to 'gamescope-wayland'.
'';
};
default = null;
example = "plasma";
description = ''
The session to launch for Desktop Mode.
By default, attempting to switch to the desktop will launch Gaming Mode again.
'';
};
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.autoStart {
assertions = [
{
assertion = !config.systemd.services.display-manager.enable;
message = ''
Traditional Display Managers cannot be enabled when jovian.steam.autoStart is used
Hint: check `services.displayManager.*.enable` options in your configuration.
'';
}
];
warnings = lib.optional (cfg.desktopSession == null) ''
jovian.steam.desktopSession is unset.
This means that using the Switch to Desktop function in Gaming Mode will
relaunch Gaming Mode.
Set jovian.steam.desktopSession to the name of a desktop session, or "gamescope-wayland"
to keep this behavior.
'';
services.displayManager.enable = true;
systemd.user.services.gamescope-session = {
overrideStrategy = "asDropin";
environment = mkMerge (
[
{
JOVIAN_DESKTOP_SESSION = cfg.desktopSession;
PATH = lib.mkForce null;
}
]
# Add any globally defined well-known XKB_DEFAULT environment variables to the session
# This is the closest wayland sessions have to generic keyboard configurations.
++ (map (var:
(mkIf (config.environment.variables ? "${var}") {
"${var}" = mkDefault config.environment.variables."${var}";
})
) [
"XKB_DEFAULT_LAYOUT"
"XKB_DEFAULT_OPTIONS"
"XKB_DEFAULT_MODEL"
"XKB_DEFAULT_RULES"
"XKB_DEFAULT_VARIANT"
]
)
);
};
services.greetd = {
enable = true;
settings = {
default_session = {
user = "root";
command = "${pkgs.jovian-greeter}/bin/jovian-greeter ${cfg.user}";
};
};
greeterManagesPlymouth = true;
};
# We handle this ourselves in the greeter
systemd.services.plymouth-quit.enable = false;
security.pam.services = {
greetd.text = ''
auth requisite pam_nologin.so
auth sufficient pam_succeed_if.so user = ${cfg.user} quiet_success
auth required pam_unix.so
account sufficient pam_unix.so
password required pam_deny.so
session optional pam_keyinit.so revoke
session include login
'';
};
environment = {
systemPackages = [ pkgs.jovian-greeter.helper ];
pathsToLink = [ "lib/jovian-greeter" ];
};
security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) {
if (
action.id == "org.freedesktop.policykit.exec" &&
action.lookup("program") == "/run/current-system/sw/lib/jovian-greeter/consume-session" &&
subject.user == "jovian-greeter"
) {
return polkit.Result.YES;
}
});
'';
xdg.portal.configPackages = mkDefault [ pkgs.gamescope-session ];
})
]);
}