From 58b3150d3ad076853e3ec6de3aac114f30f9f0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 26 Oct 2023 22:03:27 -0300 Subject: [PATCH] mime: extract declaration from implementation Maybe this should be made into a separate package later. --- user/desktop-entries.nix | 58 +++++++++++++++++++++ user/gnome.nix | 11 ++++ user/home.nix | 16 ++++++ user/mimeapps.nix | 106 ++++++++++++--------------------------- 4 files changed, 116 insertions(+), 75 deletions(-) create mode 100644 user/desktop-entries.nix diff --git a/user/desktop-entries.nix b/user/desktop-entries.nix new file mode 100644 index 0000000..cb42d40 --- /dev/null +++ b/user/desktop-entries.nix @@ -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" ]; + }; + }; +} diff --git a/user/gnome.nix b/user/gnome.nix index fa2140f..fe16c72 100644 --- a/user/gnome.nix +++ b/user/gnome.nix @@ -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"; + }; } diff --git a/user/home.nix b/user/home.nix index 8ddd299..cac61f5 100644 --- a/user/home.nix +++ b/user/home.nix @@ -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 diff --git a/user/mimeapps.nix b/user/mimeapps.nix index 1a5113e..bbd78c7 100644 --- a/user/mimeapps.nix +++ b/user/mimeapps.nix @@ -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 = [