summaryrefslogtreecommitdiff
path: root/home-manager/modules/default-apps.nix
blob: 3c7a2727ec5329a5567bcbeca1e1ac497503ccf0 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{ config, lib, ... }: 
let
  cfg = config.default-applications;
  mkCommand = name: default: lib.mkOption {
    type = lib.types.str;
    default = default;
    description = "The default ${name}'s command'";
  };
  mkDesktopFile = name: default: lib.mkOption {
    type = lib.types.str;
    default = default;
    description = "The default ${name}'s .desktop file";
  };
  # Empty entries mess things up when a mimetype has more than one app.
  removeEmpty = desktop-files: builtins.filter (name: name != "") desktop-files;
in {
  options.default-applications = {
    web-browser = {
      command = mkCommand "web browser" "librewolf";
      desktop-file = mkDesktopFile "web browser" "librewolf.desktop";
    };
    text-editor = {
      command = mkCommand "text editor" "neovide";
      desktop-file = mkDesktopFile "text editor" "neovide.desktop";
    };
    image-viewer = {
      command = mkCommand "image viewer" "imv";
      desktop-file = mkDesktopFile "image viewer" "imv.desktop";
    };
    video-viewer = {
      command = mkCommand "video viewer" "mpv";
      desktop-file = mkDesktopFile "video viewer" "mpv.desktop";
    };
    audio-player = {
      command = mkCommand "audio player" "";
      desktop-file = mkDesktopFile "audio player" "";
    };
    terminal-emulator = {
      command = mkCommand "terminal emulator" "foot";
      runTuiCommand = mkCommand "(when running a tui program) terminal emulator" "foot";
      runCliCommand = mkCommand "(when running a cli command) terminal emulator" "foot -H";
      openDirCommand = mkCommand "(when opening a dir) terminal emulator" "foot -D";
      desktop-file = mkDesktopFile "terminal emulator" "foot.desktop";
    };
    file-manager = {
      command = mkCommand "file manager" "";
      desktop-file = mkDesktopFile "file manager" "";
    };
  };
  config = {
    xdg.mimeApps = {
      enable = true;
      defaultApplications = {
        # Web Browser
        "text/html" = (removeEmpty [ cfg.web-browser.desktop-file cfg.text-editor.desktop-file ]);
        "text/xml" = [ cfg.web-browser.desktop-file ];
        "application/xhtml+xml" = [ cfg.web-browser.desktop-file ];
        "application/javascript" = [ cfg.web-browser.desktop-file ];
        "application/rss+xml" = [ cfg.web-browser.desktop-file ];
        "application/atom+xml" = [ cfg.web-browser.desktop-file ];
        "application/pdf" = [ cfg.web-browser.desktop-file ];
        "application/x-www-form-urlencoded" = [ cfg.web-browser.desktop-file ];
        "multipart/form-data" = [ cfg.web-browser.desktop-file ];

        # Text Editor
        "text/nix" = [ cfg.text-editor.desktop-file ];
        "text/plain" = [ cfg.text-editor.desktop-file ];
        "text/x-python" = [ cfg.text-editor.desktop-file ];
        "text/x-c" = [ cfg.text-editor.desktop-file ];
        "text/x-java-source" = [ cfg.text-editor.desktop-file ];
        "text/x-shellscript" = [ cfg.text-editor.desktop-file ];
        "text/x-markdown" = [ cfg.text-editor.desktop-file ];
        "text/css" = [ cfg.text-editor.desktop-file ];
        "application/json" = [ cfg.text-editor.desktop-file ];
        "application/xml" = [ cfg.text-editor.desktop-file ];
        "application/x-yaml" = [ cfg.text-editor.desktop-file ];
        "application/x-perl" = [ cfg.text-editor.desktop-file ];
        "application/x-php" = [ cfg.text-editor.desktop-file ];
        "application/x-sql" = [ cfg.text-editor.desktop-file ];
        "application/x-sh" = [ cfg.text-editor.desktop-file ];
        "application/x-cmake" = [ cfg.text-editor.desktop-file ];
        "application/x-latex" = [ cfg.text-editor.desktop-file ];
        "application/x-tex" = [ cfg.text-editor.desktop-file ];
        "text/x-log" = [ cfg.text-editor.desktop-file ];
        "text/csv" = [ cfg.text-editor.desktop-file ];

        # Image Viewer
        "image/jpeg" = [ cfg.image-viewer.desktop-file ];
        "image/jpg" = [ cfg.image-viewer.desktop-file ];
        "image/png" = [ cfg.image-viewer.desktop-file ];
        "image/gif" = [ cfg.image-viewer.desktop-file ];
        "image/bmp" = [ cfg.image-viewer.desktop-file ];
        "image/webp" = [ cfg.image-viewer.desktop-file ];
        "image/tiff" = [ cfg.image-viewer.desktop-file ];
        "image/x-xbitmap" = [ cfg.image-viewer.desktop-file ];
        "image/x-xpixmap" = [ cfg.image-viewer.desktop-file ];
        "image/x-portable-pixmap" = [ cfg.image-viewer.desktop-file ];
        "image/x-portable-graymap" = [ cfg.image-viewer.desktop-file ];
        "image/svg+xml" = (removeEmpty [ cfg.image-viewer.desktop-file cfg.web-browser.desktop-file ]);
        "image/heif" = [ cfg.image-viewer.desktop-file ];
        "image/heic" = [ cfg.image-viewer.desktop-file ];

        # Video Viewer
        "video/mp4" = [ cfg.video-viewer.desktop-file ];
        "video/x-msvideo" = [ cfg.video-viewer.desktop-file ];
        "video/x-matroska" = [ cfg.video-viewer.desktop-file ];
        "video/webm" = [ cfg.video-viewer.desktop-file ];
        "video/ogg" = [ cfg.video-viewer.desktop-file ];
        "video/mpeg" = [ cfg.video-viewer.desktop-file ];
        "video/quicktime" = [ cfg.video-viewer.desktop-file ];
        "video/x-flv" = [ cfg.video-viewer.desktop-file ];
        "application/vnd.rn-realmedia" = [ cfg.video-viewer.desktop-file ];
        "application/x-mplayer2" = [ cfg.video-viewer.desktop-file ];
      
        # Audio Player
        "audio/mpeg" = [ cfg.audio-player.desktop-file ];
        "audio/og" = [ cfg.audio-player.desktop-file ];
        "audio/wa" = [ cfg.audio-player.desktop-file ];
        "audio/fla" = [ cfg.audio-player.desktop-file ];
        "audio/aa" = [ cfg.audio-player.desktop-file ];
        "audio/x-ms-wm" = [ cfg.audio-player.desktop-file ];
        "audio/x-matrosk" = [ cfg.audio-player.desktop-file ];

        # Terminal Emulator and File Manager
        "inode/directory" = (removeEmpty [ cfg.file-manager.desktop-file "open-terminal-here.desktop" ]);
      };
    };
    # Allows terminals to work instead of file managers
    home.file."open-terminal-here" = {
      target = ".local/share/applications/open-terminal-here.desktop";
      text = ''
        [Desktop Entry]
        Name=Open Terminal Here
        Comment=Open terminal in this directory
        Exec=${cfg.terminal-emulator.openDirCommand} %f
        Icon=utilities-terminal
        Type=Application
        Terminal=false
        MimeType=inode/directory;
        NoDisplay=true
      '';
    };
  };
}