fork/home-manager
git clone https://git.julia.blue/fork/home-manager
7b8d43fb
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6desktopEntry = { 7imports = [ 8( mkRemovedOptionModule [ "extraConfig" ] 9"The `extraConfig` option of `xdg.desktopEntries` has been removed following a change in Nixpkgs." ) 10( mkRemovedOptionModule [ "fileValidation" ] 11"Validation of the desktop file is always enabled." ) 12]; 13options = { 14# Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function, 15# our options and defaults follow its parameters, with the following exceptions: 16 17# `desktopName` on makeDesktopItem is controlled by `name`. 18# This is what we'd commonly consider the name of the application. 19# `name` on makeDesktopItem is controlled by this module's key in the attrset. 20# This is the file's filename excluding ".desktop". 21 22# `extraConfig` on makeDesktopItem is controlled by `settings`, 23# to match what's commonly used by other home manager modules. 24 25# Descriptions are taken from the desktop entry spec: 26# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys 27 28type = mkOption { 29description = "The type of the desktop entry." ; 30default = "Application" ; 31type = types . enum [ "Application" "Link" "Directory" ]; 32}; 33 34exec = mkOption { 35description = "Program to execute, possibly with arguments." ; 36type = types . nullOr types . str ; 37default = null ; 38}; 39 40icon = mkOption { 41description = "Icon to display in file manager, menus, etc." ; 42type = with types ; nullOr ( either str path ); 43default = null ; 44}; 45 46comment = mkOption { 47description = "Tooltip for the entry." ; 48type = types . nullOr types . str ; 49default = null ; 50}; 51 52terminal = mkOption { 53description = "Whether the program runs in a terminal window." ; 54type = types . bool ; 55default = false ; 56}; 57 58name = mkOption { 59description = "Specific name of the application." ; 60type = types . str ; 61}; 62 63genericName = mkOption { 64description = "Generic name of the application." ; 65type = types . nullOr types . str ; 66default = null ; 67}; 68 69mimeType = mkOption { 70description = "The MIME type(s) supported by this application." ; 71type = types . nullOr ( types . listOf types . str ); 72default = null ; 73}; 74 75categories = mkOption { 76description = 77"Categories in which the entry should be shown in a menu." ; 78type = types . nullOr ( types . listOf types . str ); 79default = null ; 80}; 81 82startupNotify = mkOption { 83description = '' 84If true, it is KNOWN that the application will send a "remove" 85message when started with the `DESKTOP_STARTUP_ID` 86environment variable set. If false, it is KNOWN that the application 87does not work with startup notification at all.'' ; 88type = types . nullOr types . bool ; 89default = null ; 90}; 91 92noDisplay = mkOption { 93description = '' 94Means "this application exists, but don't display it in the menus". 95This can be useful to e.g. associate this application with MIME types. 96'' ; 97type = types . nullOr types . bool ; 98default = null ; 99}; 100 101prefersNonDefaultGPU = mkOption { 102description = '' 103If true, the application prefers to be run on a more powerful discrete GPU if available. 104'' ; 105type = types . nullOr types . bool ; 106default = null ; 107}; 108 109settings = mkOption { 110type = types . attrsOf types . str ; 111description = '' 112Extra key-value pairs to add to the `[Desktop Entry]` section. 113This may override other values. 114'' ; 115default = { }; 116example = literalExpression '' 117{ 118Keywords = "calc;math"; 119DBusActivatable = "false"; 120} 121'' ; 122}; 123 124actions = mkOption { 125type = types . attrsOf ( types . submodule ({ name , ...} :{ 126options . name = mkOption { 127type = types . str ; 128default = name ; 129defaultText = literalExpression "<name>" ; 130description = "Name of the action." ; 131}; 132options . exec = mkOption { 133type = types . nullOr types . str ; 134description = "Program to execute, possibly with arguments." ; 135default = null ; 136}; 137options . icon = mkOption { 138type = with types ; nullOr ( either str path ); 139default = null ; 140description = "Icon to display in file manager, menus, etc." ; 141}; 142})); 143default = { }; 144defaultText = literalExpression "{ }" ; 145example = literalExpression '' 146{ 147"New Window" = { 148exec = "''${pkgs.firefox}/bin/firefox --new-window %u"; 149}; 150} 151'' ; 152description = 153"The set of actions made available to application launchers." ; 154}; 155 156# Required for the assertions 157# TODO: Remove me once https://github.com/NixOS/nixpkgs/issues/96006 is fixed 158assertions = mkOption { 159type = types . listOf types . unspecified ; 160default = [ ]; 161visible = false ; 162internal = true ; 163}; 164}; 165}; 166 167#passes config options to makeDesktopItem in expected format 168makeFile = name :config : 169pkgs . makeDesktopItem { 170inherit name ; 171inherit ( config ) 172type exec icon comment terminal genericName startupNotify noDisplay 173prefersNonDefaultGPU actions ; 174desktopName = config . name ; 175mimeTypes = optionals ( config . mimeType != null ) config . mimeType ; 176categories = optionals ( config . categories != null ) config . categories ; 177extraConfig = config . settings ; 178}; 179in { 180meta . maintainers = [ hm . maintainers . cwyc ]; 181 182options . xdg . desktopEntries = mkOption { 183description = '' 184Desktop Entries allow applications to be shown in your desktop environment's app launcher. 185 186You can define entries for programs without entries or override existing entries. 187 188See <https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys> for more information on options. 189'' ; 190default = { }; 191type = types . attrsOf ( types . submodule desktopEntry ); 192example = literalExpression '' 193{ 194firefox = { 195name = "Firefox"; 196genericName = "Web Browser"; 197exec = "firefox %U"; 198terminal = false; 199categories = [ "Application" "Network" "WebBrowser" ]; 200mimeType = [ "text/html" "text/xml" ]; 201}; 202} 203'' ; 204}; 205 206config = mkIf ( config . xdg . desktopEntries != { }) { 207assertions = [ 208( hm . assertions . assertPlatform "xdg.desktopEntries" pkgs platforms . linux ) 209] ++ flatten ( catAttrs "assertions" ( attrValues config . xdg . desktopEntries )); 210 211home . packages = ( map hiPrio # we need hiPrio to override existing entries 212( attrsets . mapAttrsToList makeFile config . xdg . desktopEntries )); 213}; 214 215}