Repository navigation
Expand file tree
/
Copy pathdefault.nix
More file actions
99 lines (89 loc) · 2.94 KB
/
Copy pathdefault.nix
File metadata and controls
99 lines (89 loc) · 2.94 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
# my-dotfiles | Copyright (C) 2025 eth-p
# Repository: https://github.com/eth-p/my-dotfiles
#
# Program: https://discord.com/
# ==============================================================================
{
lib,
config,
pkgs,
...
}@inputs:
let
inherit (lib) mkIf mkMerge;
cfg = config.my-dotfiles.discord;
in
{
options.my-dotfiles.discord = {
enable = lib.mkEnableOption "enable Discord config";
supported = lib.mkOption {
readOnly = true;
type = lib.types.bool;
description = "whether Discord is supported on the current platform";
default = pkgs.stdenv.hostPlatform.isLinux;
};
source = lib.mkOption {
type = lib.types.enum [ "flatpak" ];
description = "the installation source for Discord";
default = "flatpak";
};
betterdiscord = {
enable = lib.mkEnableOption "install BetterDiscord";
};
};
config =
let
sources = {
flatpak = {
configDir = config.home.homeDirectory + "/.var/app/com.discordapp.Discord/config";
};
};
inherit (sources."${cfg.source}") configDir;
in
mkIf (cfg.supported && cfg.enable) (mkMerge [
# Install BetterDiscord by wrapping the .desktop file.
(mkIf cfg.betterdiscord.enable {
home.packages = [ pkgs.betterdiscordctl ];
})
(mkIf (cfg.betterdiscord.enable && cfg.source == "flatpak") (
let
wrapper = pkgs.writeShellApplication {
name = "discord-betterdiscord-flatpak-wrapper";
runtimeInputs = [ pkgs.betterdiscordctl ];
text = ''
if betterdiscordctl -i flatpak status | grep 'no$'; then
betterdiscordctl -i flatpak install
fi
flatpak run --branch=stable \
--arch=${pkgs.stdenv.targetPlatform.linuxArch} \
--command=com.discordapp.Discord \
--file-forwarding \
com.discordapp.Discord "$@"
'';
};
in
{
# Flatpak has XDG_DATA_DIRS higher priority than `~/.nix-profile`.
# As a workaround, we'll just write it directly to `~/.local`.
home.file.".local/share/applications/com.discordapp.Discord.desktop" = {
text = ''
[Desktop Entry]
Name=Discord
StartupWMClass=discord
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
GenericName=Internet Messenger
Exec=${wrapper}/bin/${wrapper.name} @@u %U @@
Icon=com.discordapp.Discord
Type=Application
Categories=Network;InstantMessaging;
Path=/usr/bin
X-Desktop-File-Install-Version=0.28
MimeType=x-scheme-handler/discord;
X-Flatpak-Tags=proprietary;
X-Flatpak=com.discordapp.Discord
'';
};
}
))
]);
}