dot

vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks

62 lines2894 bytesNix
1# Signal Desktop with config/signal/theme.css applied. Signal has no user
2# stylesheet, so this repacks the app.asar of nixpkgs' signal-desktop so that it
3# 1. loads theme.css as stylesheets/custom.css after Signal's own stylesheets, and
4# 2. creates the main window transparent, so Hyprland's blur shows through.
5# Nothing else is changed; the electron, flags and profile (~/.config/Signal) are
6# those of the stock package.
7#
8# This replaces signal/launch from the old dotfiles: the copy is built here, once,
9# instead of at start-up. Edit theme.css, rebuild, and run config/signal/restart.
10# If a Signal update moves one of the two places being patched, the build fails
11# rather than shipping an unthemed or half-patched Signal.
12{
13 lib,
14 runCommand,
15 signal-desktop,
16 asar,
17 theme ? ../../config/signal/theme.css,
18}:
19
20runCommand "signal-desktop-themed-${signal-desktop.version}"
21 {
22 nativeBuildInputs = [ asar ];
23 inherit (signal-desktop) meta;
24 passthru.unthemed = signal-desktop;
25 }
26 ''
27 src=${signal-desktop}
28 mkdir -p $out/bin $out/share
29 for d in $src/share/*; do
30 [ "$(basename "$d")" = signal-desktop ] || [ "$(basename "$d")" = applications ] || ln -s "$d" $out/share/
31 done
32
33 mkdir -p $out/share/signal-desktop
34 for f in $src/share/signal-desktop/*; do
35 case "$(basename "$f")" in app.asar|app.asar.unpacked) ;; *) ln -s "$f" $out/share/signal-desktop/ ;; esac
36 done
37
38 asar extract $src/share/signal-desktop/app.asar app
39 cp ${theme} app/stylesheets/custom.css
40
41 # 1. Load the theme last, so it wins over Signal's own stylesheets.
42 anchor='<link href="stylesheets/tailwind.css" rel="stylesheet" type="text/css" />'
43 grep -qF "$anchor" app/background.html
44 sed -i "s|$anchor|&\n <link href=\"stylesheets/custom.css\" rel=\"stylesheet\" type=\"text/css\" />|" app/background.html
45 grep -qF 'href="stylesheets/custom.css"' app/background.html
46
47 # 2. Transparent main window. It is the only BrowserWindow created with
48 # sandbox:false, which is what the pattern keys on; exactly one match or stop.
49 sed -i 's/backgroundColor:[A-Za-z0-9_$]*,\(webPreferences:{[^}]*sandbox:!1\)/transparent:!0,backgroundColor:`#00000000`,\1/' app/bundles/main.js
50 [ "$(grep -o 'transparent:!0,backgroundColor:`#00000000`' app/bundles/main.js | wc -l)" = 1 ]
51
52 asar pack --unpack '*.node' app $out/share/signal-desktop/app.asar
53
54 # Same launcher as the stock package, pointed at the themed app.asar.
55 substitute $src/bin/signal-desktop $out/bin/signal-desktop \
56 --replace-fail "$src/share/signal-desktop/app.asar" "$out/share/signal-desktop/app.asar"
57 chmod +x $out/bin/signal-desktop
58
59 mkdir -p $out/share/applications
60 substitute $src/share/applications/signal.desktop $out/share/applications/signal.desktop \
61 --replace-quiet "$src/bin/signal-desktop" "$out/bin/signal-desktop"
62 ''