mime: extract declaration from implementation

Maybe this should be made into a separate package later.
This commit is contained in:
Leonardo Eugênio 2023-10-26 22:03:27 -03:00
parent 884d02f003
commit 58b3150d3a
4 changed files with 116 additions and 75 deletions

58
user/desktop-entries.nix Normal file
View file

@ -0,0 +1,58 @@
{ config, pkgs, lib, ... }: {
xdg.desktopEntries = {
kak = {
name = "Kakoune";
genericName = "Text Editor";
comment = "Edit text files";
exec = "kak %F";
terminal = true;
type = "Application";
icon = "kak.desktop";
categories = [ "Utility" "TextEditor" ];
startupNotify = true;
mimeType = [
"text/english"
"text/plain"
"text/x-makefile"
"text/x-c++hdr"
"text/x-c++src"
"text/x-chdr"
"text/x-csrc"
"text/x-java"
"text/x-moc"
"text/x-pascal"
"text/x-tcl"
"text/x-tex"
"application/x-shellscript"
"text/x-c"
"text/x-c++"
];
settings = {
Keywords = "Text;editor;";
TryExec = "kak";
};
};
neomutt = {
name = "Neomutt";
genericName = "Email Client";
comment = "View and Send Emails";
exec = "neomutt %U";
terminal = true;
type = "Application";
icon = "mutt";
categories = [ "Network" "Email" ];
startupNotify = false;
mimeType = [ "x-scheme-handler/mailto" ];
settings = { Keywords = "Mail;E-mail;"; };
};
down_meme = {
name = "DownMeme";
genericName = "Download memes";
exec = "down_meme";
terminal = true;
type = "Application";
icon = "download";
categories = [ "Network" ];
};
};
}

View file

@ -35,4 +35,15 @@
gnome-passwordsafe
];
xdg.defaultApplications = {
enable = true;
text-editor = "codium.desktop";
image-viewer = "org.gnome.eog.desktop";
video-player = "org.gnome.Totem.desktop";
web-browser = "firefox.desktop";
document-viewer = "org.gnome.Evince.desktop";
file-manager = "org.gnome.Nautilus.desktop";
email-client = "thunderbird.desktop";
torrent-client = "torrent.desktop";
};
}

View file

@ -19,6 +19,7 @@
./pipewire.nix
./rtp-sink.nix
./mimeapps.nix
./desktop-entries.nix
./chat.nix
./email.nix
./syncthing.nix
@ -153,6 +154,21 @@
indicator = true;
};
xdg.defaultApplications = {
enable = true;
text-editor = lib.mkDefault "kak.desktop";
image-viewer = lib.mkDefault "pqiv.desktop";
video-player = lib.mkDefault "mpv.desktop";
web-browser = lib.mkDefault ({
firefox = lib.mkDefault "firefox.desktop";
qutebrowser = lib.mkDefault "org.qutebrowser.qutebrowser.desktop";
}.${pkgs.uservars.browser});
document-viewer = lib.mkDefault "org.pwmt.zathura.desktop";
file-manager = lib.mkDefault "thunar.desktop";
email-client = lib.mkDefault "thunderbird.desktop";
torrent-client = lib.mkDefault "torrent.desktop";
};
wayland.windowManager.sway.extraConfig = lib.optionalString (osConfig.networking.hostName or "" == "monolith") ''
exec steam
exec obs --startreplaybuffer

View file

@ -1,63 +1,24 @@
{ config, pkgs, lib, font, ... }:
let inherit (pkgs.uservars) browser;
in {
config = {
xdg.desktopEntries = {
kak = {
name = "Kakoune";
genericName = "Text Editor";
comment = "Edit text files";
exec = "kak %F";
terminal = true;
type = "Application";
icon = "kak.desktop";
categories = [ "Utility" "TextEditor" ];
startupNotify = true;
mimeType = [
"text/english"
"text/plain"
"text/x-makefile"
"text/x-c++hdr"
"text/x-c++src"
"text/x-chdr"
"text/x-csrc"
"text/x-java"
"text/x-moc"
"text/x-pascal"
"text/x-tcl"
"text/x-tex"
"application/x-shellscript"
"text/x-c"
"text/x-c++"
];
settings = {
Keywords = "Text;editor;";
TryExec = "kak";
};
};
neomutt = {
name = "Neomutt";
genericName = "Email Client";
comment = "View and Send Emails";
exec = "neomutt %U";
terminal = true;
type = "Application";
icon = "mutt";
categories = [ "Network" "Email" ];
startupNotify = false;
mimeType = [ "x-scheme-handler/mailto" ];
settings = { Keywords = "Mail;E-mail;"; };
};
down_meme = {
name = "DownMeme";
genericName = "Download memes";
exec = "down_meme";
terminal = true;
type = "Application";
icon = "download";
categories = [ "Network" ];
};
let
inherit (pkgs.uservars) browser;
cfg = config.xdg.defaultApplications;
in
{
options = {
xdg.defaultApplications = {
enable = lib.mkEnableOption "Whether vpn should be enabled";
text-editor = lib.mkOption { };
image-viewer = lib.mkOption { };
video-player = lib.mkOption { };
web-browser = lib.mkOption { };
document-viewer = lib.mkOption { };
torrent-client = lib.mkOption { };
file-manager = lib.mkOption { };
email-client = lib.mkOption { };
};
};
config = lib.mkIf (cfg.enable) {
# workaround to allow overriding mimeapps file
# btw, whatever it was that decided that damn file should always be written is an asshole
xdg.configFile."mimeapps.list".force = true;
@ -73,29 +34,24 @@ in {
(map (createMimeAssociation mime_prefix application) mime_suffixes));
mimes = simple
// (createMimeAssociations "text" "kak.desktop" text_suffixes)
// (createMimeAssociations "image" "pqiv.desktop" image_suffixes)
// (createMimeAssociations "video" "mpv.desktop" video_suffixes);
browser_desktop = {
firefox = "firefox.desktop";
qutebrowser = "org.qutebrowser.qutebrowser.desktop";
}.${browser};
// (createMimeAssociations "text" cfg.text-editor text_suffixes)
// (createMimeAssociations "image" cfg.image-viewer image_suffixes)
// (createMimeAssociations "video" cfg.video-player video_suffixes);
simple = {
"inode/directory" = "thunar.desktop";
"inode/directory" = cfg.file-manager;
"application/pdf" = "org.pwmt.zathura.desktop";
"application/epub+zip" = "org.pwmt.zathura.desktop";
"application/pdf" = cfg.document-viewer;
"application/epub+zip" = cfg.document-viewer;
"text/html" = browser_desktop;
"x-scheme-handler/http" = browser_desktop;
"x-scheme-handler/https" = browser_desktop;
"text/html" = cfg.web-browser;
"x-scheme-handler/http" = cfg.web-browser;
"x-scheme-handler/https" = cfg.web-browser;
"x-scheme-handler/magnet" = "torrent.desktop";
"application/x-bittorrent" = "torrent.desktop";
"x-scheme-handler/magnet" = cfg.torrent-client;
"application/x-bittorrent" = cfg.torrent-client;
"x-scheme-handler/mailto" = "thunderbird.desktop";
"x-scheme-handler/mailto" = cfg.email-client;
};
text_suffixes = [