greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

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