@ -72,20 +72,50 @@ in {
} ;
} ;
config = mkIf cfg . enable {
assertions =
[ ( hm . assertions . assertPlatform " x d g . m i m e A p p s " pkgs platforms . linux ) ] ;
# Deprecated but still used by some applications.
xdg . dataFile . " a p p l i c a t i o n s / m i m e a p p s . l i s t " . source =
config . xdg . configFile . " m i m e a p p s . l i s t " . source ;
xdg . configFile . " m i m e a p p s . l i s t " . text =
let joinValues = mapAttrs ( n : concatStringsSep " ; " ) ;
in generators . toINI { } {
" A d d e d A s s o c i a t i o n s " = joinValues cfg . associations . added ;
" R e m o v e d A s s o c i a t i o n s " = joinValues cfg . associations . removed ;
" D e f a u l t A p p l i c a t i o n s " = joinValues cfg . defaultApplications ;
} ;
} ;
config = mkMerge [
{
# Given a package that installs .desktop files in the usual location,
# return a mapping from mime types to lists of desktop file names. This is
# suitable for use with `xdg.mimeApps.defaultApplications`.
lib . xdg . mimeAssociations = let
processLines = str :
zipAttrs
( filter ( e : e != null ) ( map processLine ( splitString " \n " str ) ) ) ;
processLine = str :
let
entry = splitString " ; " str ;
k = elemAt entry 0 ;
v = elemAt entry 1 ;
in if length entry == 2 then { ${ k } = v ; } else null ;
associations = ps :
pkgs . runCommand " m i m e - a s s o c " { inherit ps ; } ''
for p in $ ps ; do
for path in " $ p " /share/applications /* . d e s k t o p ; d o
name = " ' ' ${ path ##*/}"
sed - n " / ^ M i m e T y p e = / { s / . * = / / ; s / ; / ; $ n a m e \n / g ; p ; } " " $ p a t h "
done
done > " $ o u t "
'' ;
in p : processLines ( builtins . readFile ( associations p ) ) ;
}
( mkIf cfg . enable {
assertions =
[ ( hm . assertions . assertPlatform " x d g . m i m e A p p s " pkgs platforms . linux ) ] ;
# Deprecated but still used by some applications.
xdg . dataFile . " a p p l i c a t i o n s / m i m e a p p s . l i s t " . source =
config . xdg . configFile . " m i m e a p p s . l i s t " . source ;
xdg . configFile . " m i m e a p p s . l i s t " . text =
let joinValues = mapAttrs ( n : concatStringsSep " ; " ) ;
in generators . toINI { } {
" A d d e d A s s o c i a t i o n s " = joinValues cfg . associations . added ;
" R e m o v e d A s s o c i a t i o n s " = joinValues cfg . associations . removed ;
" D e f a u l t A p p l i c a t i o n s " = joinValues cfg . defaultApplications ;
} ;
} )
] ;
}