greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

kore / home / features / misc / vesktop.nix168 lines · 5140B · raw

1{ config, lib, pkgs, outputs, ... }:
2
3let
4  inherit (outputs.palette) colors ramp;
5
6  vesktop = pkgs.vesktop.override { withSystemVencord = true; };
7
8  configDir = "${config.xdg.configHome}/vesktop";
9  downloads = config.xdg.userDirs.download;
10
11  jail = pkgs.writeShellApplication {
12    name = "vesktop";
13    runtimeInputs = with pkgs; [ bubblewrap xdg-dbus-proxy coreutils util-linux ];
14    text = ''
15      run="$XDG_RUNTIME_DIR"
16
17      exec 9> "$run/vesktop.lock"
18      if ! flock -n 9; then
19        echo "vesktop is already running" >&2
20        exit 0
21      fi
22
23      bus="$(mktemp -u "$run/vesktop-bus.XXXXXX")"
24
25      xdg-dbus-proxy "$DBUS_SESSION_BUS_ADDRESS" "$bus" --filter \
26        --talk=org.freedesktop.portal.Desktop \
27        --talk=org.freedesktop.Notifications &
28      proxy=$!
29      trap 'kill "$proxy" 2>/dev/null; rm -f "$bus"' EXIT
30      while [ ! -S "$bus" ]; do
31        kill -0 "$proxy" 2>/dev/null || { echo "vesktop: xdg-dbus-proxy failed" >&2; exit 1; }
32        sleep 0.05
33      done
34
35      mkdir -p "${configDir}" "${downloads}"
36
37      bwrap \
38        --unshare-all --share-net \
39        --die-with-parent --new-session \
40        --ro-bind /nix/store /nix/store \
41        --ro-bind /etc /etc \
42        --ro-bind /run/current-system /run/current-system \
43        --ro-bind /run/opengl-driver /run/opengl-driver \
44        --ro-bind-try /run/systemd/resolve /run/systemd/resolve \
45        --ro-bind /sys /sys \
46        --proc /proc \
47        --dev /dev \
48        --dev-bind /dev/dri /dev/dri \
49        --tmpfs /tmp \
50        --tmpfs /home \
51        --bind "${configDir}" "${configDir}" \
52        --bind "${downloads}" "${downloads}" \
53        --tmpfs "$run" \
54        --ro-bind "$run/$WAYLAND_DISPLAY" "$run/$WAYLAND_DISPLAY" \
55        --ro-bind "$run/pipewire-0" "$run/pipewire-0" \
56        --ro-bind "$run/pulse" "$run/pulse" \
57        --bind "$bus" "$run/bus" \
58        --setenv DBUS_SESSION_BUS_ADDRESS "unix:path=$run/bus" \
59        ${lib.getExe vesktop} --ozone-platform-hint=auto "$@"
60    '';
61  };
62
63  midnight = pkgs.fetchurl {
64    url = "https://raw.githubusercontent.com/refact0r/midnight-discord/0377a92073a9ea7c25f707437482353de295c2e8/build/midnight.css";
65    hash = "sha256-ko/iJ59EwcPUS69+lApnwocx28YIjHeKd6k1pJA2suI=";
66  };
67
68  palette = pkgs.writeText "garden-palette.css" ''
69    :root {
70      container-name: root;
71
72      --font-code: "Fantasque Sans Mono", monospace;
73
74      --text-0: ${colors.bg};
75      --text-1: ${colors.fg};
76      --text-2: ${colors.fg};
77      --text-3: ${ramp.blossom};
78      --text-4: ${colors.dim};
79      --text-5: ${ramp.teal};
80
81      --bg-1: ${colors.surface};
82      --bg-2: color-mix(in srgb, ${colors.bgAlt}, ${colors.surface});
83      --bg-3: ${colors.bgAlt};
84      --bg-4: ${colors.bg};
85      --hover: color-mix(in srgb, ${colors.green} 10%, transparent);
86      --active: color-mix(in srgb, ${colors.green} 18%, transparent);
87      --active-2: color-mix(in srgb, ${colors.green} 26%, transparent);
88      --message-hover: color-mix(in srgb, ${colors.bgAlt} 60%, transparent);
89
90      --accent-1: ${colors.green};
91      --accent-2: ${colors.green};
92      --accent-3: ${colors.green};
93      --accent-4: ${ramp.sage};
94      --accent-5: ${ramp.moss};
95      --accent-new: ${colors.red};
96
97      --online: ${colors.green};
98      --dnd: ${colors.red};
99      --idle: ${colors.yellow};
100      --streaming: ${colors.magenta};
101      --offline: ${colors.dim};
102    }
103  '';
104
105  theme = pkgs.runCommand "garden.css" { } ''
106    {
107      printf '/**\n * @name garden\n * @description palette.nix over the colors module of midnight-discord (MIT, refact0r)\n */\n'
108      sed -n '/^\/\* colors\.css \*\//,/^\/\* dms-button\.css \*\//p' ${midnight} | sed '$d'
109      cat ${palette}
110    } > "$out"
111    ! grep -nE "@import|url\\(.https?:" "$out"
112  '';
113in {
114  assertions = [{
115    assertion = downloads != config.home.homeDirectory;
116    message = "vesktop: xdg.userDirs.download must not be $HOME, the jail would expose the whole home";
117  }];
118
119  home.packages = [ jail ];
120
121  programs.vesktop = {
122    enable = true;
123    package = null;
124
125    settings = {
126      discordBranch = "stable";
127      checkUpdates = false;
128      arRPC = false;
129      tray = false;
130      minimizeToTray = false;
131      hardwareAcceleration = true;
132      splashTheming = true;
133      splashBackground = colors.bg;
134      splashColor = colors.fg;
135      staticTitle = true;
136    };
137
138    vencord = {
139      themes.garden = theme;
140
141      settings = {
142        autoUpdate = false;
143        autoUpdateNotification = false;
144        notifyAboutUpdates = false;
145        enabledThemes = [ "garden.css" ];
146
147        plugins = {
148          NoTrack = {
149            enabled = true;
150            disableAnalytics = true;
151          };
152          ClearURLs.enabled = true;
153          AnonymiseFileNames.enabled = true;
154        };
155      };
156    };
157  };
158
159  home.activation.vesktopState = lib.hm.dag.entryAfter [ "linkGeneration" ] ''
160    state="${configDir}/state.json"
161    if [ ! -e "$state" ]; then
162      run mkdir -p "${configDir}"
163      echo '{"firstLaunch":false}' > "$state"
164    fi
165  '';
166
167  home.persistence."/persist".directories = [ ".config/vesktop" ];
168}