Loading nixos/modules/config/xdg/mime.nix +47 −14 Original line number Diff line number Diff line Loading @@ -32,15 +32,15 @@ in default = { }; example = { "application/pdf" = "firefox.desktop"; "text/xml" = [ "text/*" = [ "nvim.desktop" "codium.desktop" ]; }; description = '' Adds associations between mimetypes and applications. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. Globs in all variations are supported. ''; }; Loading @@ -49,15 +49,15 @@ in default = { }; example = { "application/pdf" = "firefox.desktop"; "image/png" = [ "image/*" = [ "sxiv.desktop" "gimp.desktop" ]; }; description = '' Sets the default applications for given mimetypes. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/default) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/default) for more information. Globs in all variations are supported. ''; }; Loading @@ -65,7 +65,7 @@ in type = associationOptions; default = { }; example = { "audio/mp3" = [ "audio/*" = [ "mpv.desktop" "umpv.desktop" ]; Loading @@ -73,22 +73,55 @@ in }; description = '' Removes associations between mimetypes and applications. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. Globs in all variations are supported. ''; }; }; config = lib.mkIf cfg.enable { environment.etc."xdg/mimeapps.list" = let generateMimeScript = title: attrs: lib.optionalString (attrs != { }) '' echo "[${title}]" >> $out '' + (lib.concatStringsSep "\n" ( lib.attrValues ( lib.mapAttrs ( k: v: ''generateMimeItem "${k}" "${if lib.isList v then lib.concatStringsSep ";" v else v}"'' ) attrs ) )); in lib.mkIf (cfg.addedAssociations != { } || cfg.defaultApplications != { } || cfg.removedAssociations != { }) { text = lib.generators.toINI { } { source = pkgs.runCommandLocal "mimeapps.list" { } '' function generateMimeItem() { mime=$1 app=$2 if [[ $mime == *"*"* ]]; then while read line; do if [[ $line == $mime ]]; then echo "$line=$app" >> $out fi done < ${pkgs.shared-mime-info}/share/mime/types else echo "$mime=$app" >> $out fi } ${lib.concatStringsSep "\n" ( lib.attrValues ( lib.mapAttrs generateMimeScript { "Added Associations" = cfg.addedAssociations; "Default Applications" = cfg.defaultApplications; "Removed Associations" = cfg.removedAssociations; }; } ) )} ''; }; environment.pathsToLink = [ "/share/mime" ]; Loading Loading
nixos/modules/config/xdg/mime.nix +47 −14 Original line number Diff line number Diff line Loading @@ -32,15 +32,15 @@ in default = { }; example = { "application/pdf" = "firefox.desktop"; "text/xml" = [ "text/*" = [ "nvim.desktop" "codium.desktop" ]; }; description = '' Adds associations between mimetypes and applications. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. Globs in all variations are supported. ''; }; Loading @@ -49,15 +49,15 @@ in default = { }; example = { "application/pdf" = "firefox.desktop"; "image/png" = [ "image/*" = [ "sxiv.desktop" "gimp.desktop" ]; }; description = '' Sets the default applications for given mimetypes. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/default) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/default) for more information. Globs in all variations are supported. ''; }; Loading @@ -65,7 +65,7 @@ in type = associationOptions; default = { }; example = { "audio/mp3" = [ "audio/*" = [ "mpv.desktop" "umpv.desktop" ]; Loading @@ -73,22 +73,55 @@ in }; description = '' Removes associations between mimetypes and applications. See the [ specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. [specifications](https://specifications.freedesktop.org/mime-apps-spec/latest/associations) for more information. Globs in all variations are supported. ''; }; }; config = lib.mkIf cfg.enable { environment.etc."xdg/mimeapps.list" = let generateMimeScript = title: attrs: lib.optionalString (attrs != { }) '' echo "[${title}]" >> $out '' + (lib.concatStringsSep "\n" ( lib.attrValues ( lib.mapAttrs ( k: v: ''generateMimeItem "${k}" "${if lib.isList v then lib.concatStringsSep ";" v else v}"'' ) attrs ) )); in lib.mkIf (cfg.addedAssociations != { } || cfg.defaultApplications != { } || cfg.removedAssociations != { }) { text = lib.generators.toINI { } { source = pkgs.runCommandLocal "mimeapps.list" { } '' function generateMimeItem() { mime=$1 app=$2 if [[ $mime == *"*"* ]]; then while read line; do if [[ $line == $mime ]]; then echo "$line=$app" >> $out fi done < ${pkgs.shared-mime-info}/share/mime/types else echo "$mime=$app" >> $out fi } ${lib.concatStringsSep "\n" ( lib.attrValues ( lib.mapAttrs generateMimeScript { "Added Associations" = cfg.addedAssociations; "Default Applications" = cfg.defaultApplications; "Removed Associations" = cfg.removedAssociations; }; } ) )} ''; }; environment.pathsToLink = [ "/share/mime" ]; Loading