-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdefault.nix
More file actions
284 lines (253 loc) · 9.74 KB
/
Copy pathdefault.nix
File metadata and controls
284 lines (253 loc) · 9.74 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
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
# This file should contain basic DE setup but not the big KDE config, etc.
# ocf.graphical:
# - enable: enable ocf graphical config
# - kiosk: enable minimal kiosk config
# - desktop: default desktop env
# - extra: install extra desktop sessions/apps
# - apps.browsers: browsers
# - apps.documents: document handling
# - apps.games: games
# - apps.other: everything else
{
lib,
config,
pkgs,
...
}:
let
cfg = config.ocf.graphical;
vncScript = pkgs.writeShellScriptBin "ocf-tv" ''
if [ -z $XDG_RUNTIME_DIR ]; then
echo "XDG_RUNTIME_DIR must be set"
exit 1
fi
# remmina needs to write to the profile
/run/current-system/sw/bin/cp ${./ocf-tv.remmina} "$XDG_RUNTIME_DIR/ocf-tv.remmina"
${pkgs.remmina}/bin/remmina -c "$XDG_RUNTIME_DIR/ocf-tv.remmina"
'';
# override ocf-tv from util
ocf-tv = lib.hiPrio vncScript;
catppuccin-sddm = pkgs.catppuccin-sddm.override {
themeConfig.General = {
FontSize = 12;
Background = "/etc/ocf-assets/images/login.png";
#Logo = "/etc/ocf-assets/images/penguin.svg";
CustomBackground = true;
};
};
in
{
options.ocf.graphical = {
enable = lib.mkEnableOption "Enable desktop environment configuration";
# FIXME: this doesnt check if the given value is a valid session
desktop = lib.mkOption {
type = lib.types.str;
description = "Default desktop session in display manager";
default = "cosmic";
};
extra = lib.mkOption {
type = lib.types.bool;
description = "Install non essential stuff";
default = false;
};
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
(lib.mkIf cfg.extra {
programs.sway.enable = true;
programs.sway.extraOptions = [ "--unsupported-gpu" ];
programs.hyprland.enable = true;
programs.wayfire.enable = true;
programs.niri.enable = true;
services.xserver.desktopManager.xfce.enable = true;
services.desktopManager.gnome.enable = true;
services.gnome.gcr-ssh-agent.enable = false;
services.desktopManager.plasma6.enable = true;
environment.systemPackages = [ pkgs.plasma-applet-commandoutput ];
})
{
i18n.inputMethod = {
enable = true;
# see https://github.com/pop-os/libcosmic/pull/1182, cosmic specific text will have ime support once this is merged soon
# see skel/.config/fcitx5 for IMEs enabled by default on cosmic
type = "fcitx5";
fcitx5.waylandFrontend = true;
fcitx5.addons = with pkgs; [
fcitx5-gtk
fcitx5-mozc
fcitx5-rime
qt6Packages.fcitx5-chinese-addons
fcitx5-hangul
kdePackages.fcitx5-unikey
fcitx5-bamboo
fcitx5-m17n
];
};
# cosmic-initial-setup will run on every desktop environment and is a
# nuisance since home directories are cleared
environment.cosmic.excludePackages = [
pkgs.cosmic-initial-setup
];
environment.etc = {
skel.source = ./skel;
ocf-assets.source = ./assets;
};
# Conflict override since multiple DEs set this option
programs.ssh.askPassword = pkgs.lib.mkForce (lib.getExe pkgs.ksshaskpass.out);
environment.systemPackages = with pkgs; [
catppuccin-sddm
# terminal emulators
kitty
foot
# misc wayland utils
wl-clipboard
libnotify
ocf-tv
# COSMIC greeter override for logout button
ocf-cosmic-greeter
# OCF IRC
halloy
];
fonts.packages = with pkgs; [
meslo-lgs-nf
noto-fonts
noto-fonts-cjk-sans
];
services = {
desktopManager.cosmic = {
enable = true;
showExcludedPkgsWarning = false;
};
displayManager = {
defaultSession = cfg.desktop;
sddm = {
enable = true;
theme = "${catppuccin-sddm}/share/sddm/themes/catppuccin-latte";
wayland.enable = true;
settings.Users = {
RememberLastUser = false;
RememberLastSession = false;
};
};
};
};
systemd.user.services.wayout = {
description = "Automatic idle logout manager";
after = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "graphical-session.target" ];
serviceConfig = {
ExecStart = "${pkgs.ocf-wayout}/bin/wayout";
Type = "simple";
Restart = "on-failure";
};
};
systemd.user.services.desktoprc = {
description = "Source custom rc shared across desktops";
after = [ "graphical-session.target" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "graphical-session.target" ];
environment = {
PATH = lib.mkForce "/run/current-system/sw/bin";
};
script = ''
if [ -f ~/remote/.desktoprc ]; then
. ~/remote/.desktoprc
else
echo "User doesn't have a ~/remote/.desktoprc file"
fi
'';
};
systemd.user.services.cosmic-scale = {
description = "Set COSMIC display scaling";
after = [ "cosmic-session.target" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "cosmic-session.target" ];
environment = {
PATH = lib.mkForce "/run/current-system/sw/bin";
};
script = ''
# Set 175% scaling for all enabled displays
${pkgs.cosmic-randr}/bin/cosmic-randr list | grep "(enabled)" | sed 's/\x1b[[0-9;]*m//g' | awk '{print $1}' | while read -r output; do
# Get current mode for this output
mode=$(${pkgs.cosmic-randr}/bin/cosmic-randr list | awk '/@/ {gsub(/\x1b[[0-9;]*m/, ""); print $1, $3;
exit}')
if [ -n "$mode" ]; then
width=$(echo "$mode" | cut -d'x' -f1)
height=$(echo "$mode" | cut -d'x' -f2 | cut -d' ' -f1)
hz=$(echo "$mode" | cut -d' ' -f2)
scale=1.25
if [[ "$height" -ge "2160" ]]; then
scale=1.5
fi
${pkgs.cosmic-randr}/bin/cosmic-randr mode "$output" "$width" "$height" --refresh "$hz" --scale "$scale"
fi
done
'';
};
# EDGE CASE: if user has custom halloy config with specific rose pine colorscheme and doesnt want it to dynamically change with dark/light mode, they should name their colorscheme something aside from the OCF defaults (rose-pine.toml and rose-pine-dawn.toml)! Content can stay the same.
systemd.user.services.cosmictheme-dark = {
description = "Changes the user's persistent preference in ~/remote when the cosmic dark mode setting is changed.";
after = [ "cosmic-session.target" ];
partOf = [ "graphical-session.target" ];
wantedBy = [ "cosmic-session.target" ];
environment = {
PATH = lib.mkForce "/run/current-system/sw/bin";
};
script = ''
COSMIC_THEME_FILE="$HOME/.config/cosmic/com.system76.CosmicTheme.Mode/v1/is_dark"
COSMIC_BG_FILE="$HOME/.config/cosmic/com.system76.CosmicBackground/v1/all"
OCF_THEME_FILE="$HOME/remote/.config/ocf/theme"
sync_theme() {
if [ -f "$COSMIC_THEME_FILE" ]; then
content=$(cat "$COSMIC_THEME_FILE")
mkdir -p "$(dirname "$OCF_THEME_FILE")"
if [ "$content" = "true" ]; then
echo "dark" > "$OCF_THEME_FILE"
sed -i -E 's/bg-(light|dark)/bg-dark/g' $COSMIC_BG_FILE
sed -i 's/theme = "rose-pine-dawn"/theme = "rose-pine"/' $HOME/.config/halloy/config.toml
else
echo "light" > "$OCF_THEME_FILE"
sed -i -E 's/bg-(light|dark)/bg-light/g' $COSMIC_BG_FILE
sed -i 's/theme = "rose-pine"/theme = "rose-pine-dawn"/' $HOME/.config/halloy/config.toml
fi
pkill -USR1 halloy || true
fi
}
# Initial sync
sync_theme
# Watch for changes
${pkgs.inotify-tools}/bin/inotifywait -m -e close_write,moved_to,create \
"$(dirname "$COSMIC_THEME_FILE")" 2>/dev/null | while read -r dir events file; do
if [ "$file" = "is_dark" ]; then
sync_theme
fi
done
'';
};
## Generate Halloy IRC config
# First, checks for plaintext password file at ~/remote/.config/hallow/nickserv-password.
# If that doesn't exist, prompts for password with kdialog gui.
systemd.user.services."halloy-config" = {
description = "Generate default halloy IRC config with OCF username";
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
cat > $HOME/.config/halloy/config.toml << EOF
theme = "rose-pine-dawn"
[servers.ocf]
nickname = "$USER"
server = "irc.ocf.berkeley.edu"
[servers.ocf.sasl.plain]
username = "$USER"
password_command = 'sh -c "cat ~/remote/.config/ocf/halloy/nickserv-password 2>/dev/null || kdialog --password \"NickServ password (leave blank if not registered)\""'
EOF
'';
};
}
]
);
}