greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

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