blob: 7eb30014207aad2f6aa5dd96122f36eb97468a09 (
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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# nixos-config - My current NixOS configuration
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of my nixos-config.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
config,
lib,
system,
pkgs,
externalBinaries,
...
}: let
cfg = config.soispha.programs.river;
esa = lib.strings.escapeShellArg;
riverctl = lib.getExe' cfg.package "riverctl";
river-start = pkgs.callPackage ./river-start/package.nix {};
mkOutputFlags = output: flags: let
expandedFlags = builtins.concatStringsSep " " (lib.attrsets.mapAttrsToList (flag: value: "--${esa flag} ${esa value}") flags);
in ''
err_fail ${lib.getExe pkgs.wlr-randr} --output ${esa output} ${expandedFlags}
'';
screenSetupCode = builtins.concatStringsSep "" (lib.attrsets.mapAttrsToList mkOutputFlags cfg.init.screenSetupCode);
mkLrProgram = input: let
program = builtins.concatStringsSep " " (
if lib.isDerivation input
then [(lib.getExe input)]
else builtins.map esa input
);
in "err_fail ${program} &";
longRunningPrograms =
builtins.concatStringsSep "\n" (builtins.map mkLrProgram
cfg.init.autoStart);
keymapFormat = pkgs.formats.json {};
keymapGenerate = name: value:
pkgs.runCommandLocal "mk-${name}-and-check" {
nativeBuildInputs = [pkgs.river-mk-keymap];
preferLocalBuild = true;
env = {
JSON_FILE = keymapFormat.generate name value;
};
} ''
river-mk-keymap --keymap "$JSON_FILE" init --dry-run;
cp "$JSON_FILE" "$out"
'';
keymappings = ''
err_fail ${riverctl} keyboard-layout ${esa cfg.init.mappings.layout}
err_fail ${lib.getExe pkgs.river-mk-keymap} --keymap ${keymapGenerate "keys.json" cfg.init.mappings.keymap} init
'';
mkRule = {
app-id,
title,
action,
}: ''
err_fail ${riverctl} rule-add -app-id ${esa app-id} -title ${esa title} ${esa action}
'';
ruleSetup = builtins.concatStringsSep "" (builtins.map mkRule cfg.init.rules);
mkSetting = name: maybe_values: let
rawValues =
if builtins.isString maybe_values
then [maybe_values]
else maybe_values;
values = builtins.concatStringsSep " " (builtins.map esa rawValues);
in ''
err_fail ${riverctl} ${esa name} ${values}
'';
generalSettings =
builtins.concatStringsSep "" (lib.attrsets.mapAttrsToList mkSetting
cfg.init.generalSettings);
mkInput = name: arguments:
builtins.concatStringsSep "" (builtins.map (argumentLine: mkSetting "input" ([name] ++ argumentLine)) arguments);
inputs =
builtins.concatStringsSep "" (lib.attrsets.mapAttrsToList mkInput cfg.init.inputs);
in {
options.soispha.programs.river = {
enable = lib.mkEnableOption "river";
package = lib.mkPackageOption pkgs "river-classic" {};
unicodeInput = {
enable = lib.mkEnableOption "udev rules for rawhid based unicode input";
};
init = {
mappings = {
layout = lib.mkOption {
type = lib.types.str;
description = "The keymap to use";
default = "dvorak-modified";
};
keymap = lib.mkOption {
type = lib.types.submodule {
freeformType = keymapFormat.type;
options = {};
};
default = {};
description = ''
Configuration for river-mk-keymap via `keys.json`.
'';
};
};
rules = lib.mkOption {
type = lib.types.listOf (lib.types.attrsOf lib.types.str);
default = [];
example = ''
[
{
app-id = "*";
title = "floating please";
action = "float";
}
{
app-id = "*";
title = "*";
action = "ssd";
}
]
'';
description = ''
Configuration for river's rules.
'';
};
generalSettings = lib.mkOption {
type = lib.types.attrsOf (lib.types.either (lib.types.listOf lib.types.str) lib.types.str);
description = "Simple key value settings.";
default = {};
example = ''
{
background-color = "0x002b36";
set-repeat = ["50" "300"];
hide-cursor = ["when-typing" "enabled"];
}
'';
};
inputs = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf (lib.types.listOf lib.types.str));
description = "Options to set per input device";
default = {};
example = ''
{
pointer-1133-49970-Logitech_Gaming_Mouse_G502 = [["pointer-accel" "0"] ["accel-profile" "none"]];
pointer-12951-6505-ZSA_Technology_Labs_Moonlander_Mark_I = [["pointer-accel" "0"] ["accel-profile" "none"]];
}
'';
};
autoStart = lib.mkOption {
type =
lib.types.listOf (lib.types.either lib.types.package (lib.types.listOf
lib.types.str));
description = "List of programs to be started at river start";
example = ''
[
''${lib.getExe pkgs.foot}
]
'';
};
screenSetupCode = lib.mkOption {
type = lib.types.attrsOf (lib.types.attrsOf lib.types.str);
default = {};
description = ''
`wlr-randr` flags to set up outputs. The attribute names are the `--output` keys
and the attrs are flag value pairs to setup.
'';
example = ''
{
"Virtual-1" = {mode = "1920x1080";};
"DP-2" = {pos = "2560,0";};
"DP-1" = {scale = "1.5"; pos = "0,0";};
}
'';
};
};
};
imports = [
./keymap.nix
];
config = lib.mkIf cfg.enable {
services.udev.packages = lib.mkIf cfg.unicodeInput.enable [externalBinaries.qmk_firmware.packages.${system}.qmk_unicode_type];
home-manager.users.soispha = {
xdg.desktopEntries."river" = {
name = "river";
exec = lib.getExe river-start;
comment = "A non-monolithic Wayland compositor";
settings = {
X-DesktopNames = "river";
Type = "Application";
};
};
home.sessionVariables = {
WM = "river";
XDG_CURRENT_DESKTOP = "river";
DESKTOP_SESSION = "river";
# Export Wayland env Vars {{{
QT_QPA_PLATFORM = "wayland";
QT_QPA_PLATFORMTHEME = "qt5ct"; # needs qt5ct
CLUTTER_BACKEND = "wayland";
SDL_VIDEODRIVER = "wayland"; # might brake some things
# }}}
};
home.packages = [
river-start
pkgs.swallow
];
xdg.configFile."river/init" = {
executable = true;
text = let
mkHeading = text: other_stuff: ''
# ${text}
${other_stuff}
'';
sessionVars =
(builtins.attrNames config.environment.sessionVariables)
++ (builtins.attrNames config.home-manager.users.soispha.home.sessionVariables)
++ [
"WAYLAND_DISPLAY"
"DISPLAY"
"XDG_RUNTIME_DIR"
];
part = acc: vars: let
firstTen = lib.lists.take 5 vars;
in
if firstTen == []
then acc
else part (acc ++ [firstTen]) (lib.lists.removePrefix firstTen vars);
partedSessionVars = part [] sessionVars;
mkEnvSet = prefix: vars: let
stringVars = builtins.concatStringsSep " " vars;
in ''err_fail ${riverctl} spawn "${prefix} ${stringVars}"'';
dbusEnvs =
builtins.map
(mkEnvSet "${lib.getExe' pkgs.dbus "dbus-update-activation-environment"} --verbose --systemd")
partedSessionVars;
systemdUserEnvs =
builtins.map
(mkEnvSet "systemctl --user --verbose import-environment")
partedSessionVars;
in
builtins.readFile ./init_base.sh
+
# bash
mkHeading "Environment variables" ''
export XDG_CURRENT_DESKTOP=river DESKTOP_SESSION=river;
''
+ mkHeading "Informing dbus about changed env-vars" (builtins.concatStringsSep "\n" dbusEnvs)
+ mkHeading "Informing systemd user about changed env-vars" (builtins.concatStringsSep "\n" systemdUserEnvs)
+ mkHeading "Starting graphical-session-target" ''
err_fail systemctl --user start nixos-fake-graphical-session.target
''
+ mkHeading "Key Mappings" keymappings
+ mkHeading "Rules" ruleSetup
+ mkHeading "General Settings" generalSettings
+ mkHeading "Input Section" inputs
+ mkHeading "Screen setup code" screenSetupCode
+ mkHeading "Background services" longRunningPrograms
+ mkHeading "Layout Setup" ''
err_fail ${riverctl} default-layout rivertile
${lib.getExe' cfg.package "rivertile"} -main-ratio 0.5 -view-padding 1 -outer-padding 0
'';
};
};
};
}
|