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 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 ./pipewire.nix
./rtp-sink.nix ./rtp-sink.nix
./mimeapps.nix ./mimeapps.nix
./desktop-entries.nix
./chat.nix ./chat.nix
./email.nix ./email.nix
./syncthing.nix ./syncthing.nix
@ -153,6 +154,21 @@
indicator = true; 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") '' wayland.windowManager.sway.extraConfig = lib.optionalString (osConfig.networking.hostName or "" == "monolith") ''
exec steam exec steam
exec obs --startreplaybuffer exec obs --startreplaybuffer

View file

@ -1,63 +1,24 @@
{ config, pkgs, lib, font, ... }: { config, pkgs, lib, font, ... }:
let inherit (pkgs.uservars) browser; let
in { inherit (pkgs.uservars) browser;
config = { cfg = config.xdg.defaultApplications;
xdg.desktopEntries = { in
kak = { {
name = "Kakoune"; options = {
genericName = "Text Editor"; xdg.defaultApplications = {
comment = "Edit text files"; enable = lib.mkEnableOption "Whether vpn should be enabled";
exec = "kak %F"; text-editor = lib.mkOption { };
terminal = true; image-viewer = lib.mkOption { };
type = "Application"; video-player = lib.mkOption { };
icon = "kak.desktop"; web-browser = lib.mkOption { };
categories = [ "Utility" "TextEditor" ]; document-viewer = lib.mkOption { };
startupNotify = true; torrent-client = lib.mkOption { };
mimeType = [ file-manager = lib.mkOption { };
"text/english" email-client = lib.mkOption { };
"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" ];
};
}; };
};
config = lib.mkIf (cfg.enable) {
# workaround to allow overriding mimeapps file # workaround to allow overriding mimeapps file
# btw, whatever it was that decided that damn file should always be written is an asshole # btw, whatever it was that decided that damn file should always be written is an asshole
xdg.configFile."mimeapps.list".force = true; xdg.configFile."mimeapps.list".force = true;
@ -73,29 +34,24 @@ in {
(map (createMimeAssociation mime_prefix application) mime_suffixes)); (map (createMimeAssociation mime_prefix application) mime_suffixes));
mimes = simple mimes = simple
// (createMimeAssociations "text" "kak.desktop" text_suffixes) // (createMimeAssociations "text" cfg.text-editor text_suffixes)
// (createMimeAssociations "image" "pqiv.desktop" image_suffixes) // (createMimeAssociations "image" cfg.image-viewer image_suffixes)
// (createMimeAssociations "video" "mpv.desktop" video_suffixes); // (createMimeAssociations "video" cfg.video-player video_suffixes);
browser_desktop = {
firefox = "firefox.desktop";
qutebrowser = "org.qutebrowser.qutebrowser.desktop";
}.${browser};
simple = { simple = {
"inode/directory" = "thunar.desktop"; "inode/directory" = cfg.file-manager;
"application/pdf" = "org.pwmt.zathura.desktop"; "application/pdf" = cfg.document-viewer;
"application/epub+zip" = "org.pwmt.zathura.desktop"; "application/epub+zip" = cfg.document-viewer;
"text/html" = browser_desktop; "text/html" = cfg.web-browser;
"x-scheme-handler/http" = browser_desktop; "x-scheme-handler/http" = cfg.web-browser;
"x-scheme-handler/https" = browser_desktop; "x-scheme-handler/https" = cfg.web-browser;
"x-scheme-handler/magnet" = "torrent.desktop"; "x-scheme-handler/magnet" = cfg.torrent-client;
"application/x-bittorrent" = "torrent.desktop"; "application/x-bittorrent" = cfg.torrent-client;
"x-scheme-handler/mailto" = "thunderbird.desktop"; "x-scheme-handler/mailto" = cfg.email-client;
}; };
text_suffixes = [ text_suffixes = [