-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
211 lines (190 loc) · 6.12 KB
/
Copy pathmodule.nix
File metadata and controls
211 lines (190 loc) · 6.12 KB
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
209
210
211
{ config, pkgs, lib, ... }:
let
cfg = config.services.greg-ng;
format = pkgs.formats.toml { };
in
{
options.services.greg-ng = {
enable = lib.mkEnableOption "greg-ng, an mpv based media player";
package = lib.mkPackageOption pkgs "greg-ng" { };
mpvPackage = lib.mkPackageOption pkgs "mpv" { };
enableSway = lib.mkEnableOption "sway as the main window manager";
enablePipewire = lib.mkEnableOption "pipewire" // { default = true; };
# TODO: create some better descriptions
settings = lib.mkOption {
default = { };
type = lib.types.submodule {
freeformType = format.type;
options = {
server = {
host = lib.mkOption {
type = lib.types.str;
default = "localhost";
example = "0.0.0.0";
description = ''
Which host to bind to.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 8008;
example = 10008;
description = ''
Which port to bind to.
'';
};
verbosity = lib.mkOption {
type = lib.types.enum [ "off" "error" "warn" "info" "debug" "trace" ];
default = "debug";
description = "Log level.";
};
};
mpv = {
socket_path = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "%t/greg-ng-mpv.sock";
description = ''
Path to the mpv socket to connect to, when not auto-starting mpv.
'';
};
executable_path = lib.mkOption {
type = lib.types.str;
default = lib.getExe cfg.mpvPackage;
defaultText = lib.literalExpression ''
lib.getExe config.services.greg-ng.mpvPackage
'';
description = ''
Path to the mpv executable.
'';
};
config_file = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
Path to a mpv config file.
'';
};
auto_start = lib.mkOption {
type = with lib.types; nullOr bool;
default = true;
description = ''
Whether to automatically start our own private mpv instance.
::: {.note}
This mpv instance will not use the socket path specified in
{option}`services.greg-ng.settings.mpv.socket_path`.
:::
'';
};
};
};
};
};
};
config = lib.mkMerge [
(lib.mkIf cfg.enable {
systemd.user.sockets.greg-ng = {
description = "Socket for greg-ng, an mpv based media player";
wantedBy = [ "sockets.target" ];
socketConfig = {
ListenStream = "${cfg.settings.server.host}:${toString cfg.settings.server.port}";
};
};
systemd.user.services.greg-ng = {
description = "greg-ng, an mpv based media player";
wantedBy = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
serviceConfig = {
Type = "notify";
ExecStart = let
configFile = format.generate "greg-ng.toml" (
lib.filterAttrsRecursive (_: v: v != null) cfg.settings
);
in "${lib.getExe cfg.package} --systemd --config ${configFile}";
Sockets = [ "greg-ng.socket" ];
CacheDirectory = "greg-ng";
RuntimeDirectory = "greg-ng";
Restart = "always";
RestartSec = 3;
WatchdogSec = lib.mkDefault 15;
TimeoutStartSec = lib.mkDefault 30;
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
AmbientCapabilities = [ "" ];
CapabilityBoundingSet = [ "" ];
DeviceAllow = [ "" ];
LockPersonality = true;
# Might work, but wouldn't bet on it with embedded lua in mpv
MemoryDenyWriteExecute = false;
NoNewPrivileges = true;
# MPV and mesa tries to talk directly to the GPU.
PrivateDevices = false;
PrivateMounts = true;
PrivateTmp = true;
PrivateUsers = true;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
# MPV wants ~/.cache
ProtectHome = false;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
# I'll figure it out sometime
# ProtectSystem = "full";
RemoveIPC = true;
UMask = "0077";
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
# Something brokey
# SystemCallFilter = [
# "@system-service"
# "~@privileged"
# "~@resources"
# ];
};
};
})
(lib.mkIf (cfg.enable && cfg.enablePipewire) {
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
})
(lib.mkIf (cfg.enable && cfg.enableSway) {
programs.sway = {
enable = true;
wrapperFeatures.gtk = true;
};
xdg.portal = {
enable = true;
wlr.enable = true;
extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
};
users = {
users.greg = {
isNormalUser = true;
group = "greg";
uid = 2000;
description = "loud gym bro";
};
groups.greg.gid = 2000;
};
services.greetd = {
enable = true;
settings = rec {
initial_session = {
command = "${pkgs.sway}/bin/sway";
user = "greg";
};
default_session = initial_session;
};
};
})
];
}