blob: ead701293508a4f499dedd821579e5209e6c54b8 (
plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
{ pkgs, ... }: {
imports = [
./hardware-configuration.nix
];
services.displayManager = {
defaultSession = "hyprland";
autoLogin = {
enable = true;
user = "phos";
};
};
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
powerManagement.enable = false;
powerManagement.finegrained = false;
open = false;
nvidiaSettings = true;
};
hardware.graphics = {
enable = true;
enable32Bit = true;
};
networking.interfaces.enp4s0.wakeOnLan.enable = true;
services.sunshine = {
enable = true;
autoStart = true;
openFirewall = true;
capSysAdmin = true;
settings = {
sunshine_name = "phosphophyllite";
output_name = 1;
capture = "wlr";
encoder = "software";
hevc_mode = 1;
av1_mode = 1;
packetsize = 1200;
min_log_level = "debug";
origin_web_ui_allowed = "lan";
global_prep_cmd = ''[
{"do":"/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl stop sunshine-poweroff.timer","undo":"/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl start sunshine-poweroff.timer"},
{"do":"${pkgs.systemd}/bin/systemctl --user start sunshine-monitor-prep.service","undo":"${pkgs.systemd}/bin/systemctl --user start sunshine-monitor-restore.service"}
]'';
};
};
systemd.user.services.sunshine.serviceConfig.ExecStartPre = "-${pkgs.procps}/bin/pkill -x sunshine";
security.sudo.extraRules = [
{
users = [ "phos" ];
commands = [
{
command = "${pkgs.systemd}/bin/systemctl start sunshine-poweroff.timer";
options = [ "NOPASSWD" ];
}
{
command = "${pkgs.systemd}/bin/systemctl stop sunshine-poweroff.timer";
options = [ "NOPASSWD" ];
}
];
}
];
systemd.user.services.sunshine-monitor-prep = {
description = "Disable vertical monitor for Sunshine sessions";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash -lc '/run/current-system/sw/bin/hyprctl keyword monitor HDMI-A-1,disable || true'";
};
};
systemd.user.services.sunshine-monitor-restore = {
description = "Restore vertical monitor after Sunshine sessions";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash -lc '/run/current-system/sw/bin/hyprctl keyword monitor HDMI-A-1,1920x1080@60,2560x0,1,transform,3 || true'";
};
};
systemd.user.services.autolock-after-login = {
description = "Lock session shortly after autologin";
wantedBy = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash -lc 'sleep 2; command -v serpantinum >/dev/null && serpantinum lock || true'";
};
};
systemd.user.services.audio-default-sink = {
description = "Force default sink to speakers";
wantedBy = [ "graphical-session.target" ];
after = [
"graphical-session.target"
"pipewire-pulse.service"
"wireplumber.service"
];
serviceConfig = {
Type = "oneshot";
};
script = ''
for _ in $(${pkgs.coreutils}/bin/seq 1 20); do
${pkgs.pulseaudio}/bin/pactl info >/dev/null 2>&1 && break
sleep 1
done
${pkgs.pulseaudio}/bin/pactl set-default-sink alsa_output.pci-0000_0a_00.4.analog-stereo || true
inputs="$(${pkgs.pulseaudio}/bin/pactl list short sink-inputs | ${pkgs.gawk}/bin/awk '{print $1}' || true)"
if [ -n "$inputs" ]; then
while read -r input; do
[ -z "$input" ] && continue
${pkgs.pulseaudio}/bin/pactl move-sink-input "$input" alsa_output.pci-0000_0a_00.4.analog-stereo || true
done <<EOF
$inputs
EOF
fi
'';
};
systemd.timers.sunshine-poweroff = {
description = "Shutdown desktop 15 minutes after Sunshine disconnect";
timerConfig = {
OnActiveSec = "15m";
AccuracySec = "30s";
Unit = "sunshine-poweroff.service";
};
};
systemd.services.sunshine-poweroff = {
description = "Power off if machine stays idle after Sunshine disconnect";
serviceConfig.Type = "oneshot";
script = ''
set -euo pipefail
sessions="$(${pkgs.systemd}/bin/loginctl list-sessions --no-legend || true)"
if [ -n "$sessions" ]; then
while read -r session _; do
[ -z "$session" ] && continue
seat="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p Seat --value)"
[ -z "$seat" ] && continue
active="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p Active --value)"
idle="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p IdleHint --value)"
if [ "$active" = "yes" ] && [ "$idle" = "no" ]; then
exit 0
fi
done <<EOF
$sessions
EOF
fi
exec ${pkgs.systemd}/bin/systemctl poweroff
'';
};
services.pipewire.wireplumber.extraConfig."10-rename-devices" = {
"monitor.alsa.rules" = [
{
matches = [
{
"node.name" = "alsa_output.pci-0000_0a_00.4.analog-stereo";
}
];
actions = {
update-props = {
"node.description" = "Speakers";
};
};
}
{
matches = [
{
"node.name" = "alsa_output.pci-0000_08_00.1.hdmi-stereo";
}
];
actions = {
update-props = {
"device.disabled" = true;
};
};
}
{
matches = [
{
"node.name" = "alsa_output.usb-HP__Inc_HyperX_Cloud_II_Core_Wireless-00";
}
];
actions = {
update-props = {
"node.description" = "HyperX Cloud II";
};
};
}
];
};
}
|