fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6inherit ( builtins ) typeOf stringLength ; 7 8cfg = config . programs . mpv ; 9 10mpvOption = with types ; either str ( either int ( either bool float )); 11mpvOptionDup = with types ; either mpvOption ( listOf mpvOption ); 12mpvOptions = with types ; attrsOf mpvOptionDup ; 13mpvProfiles = with types ; attrsOf mpvOptions ; 14mpvBindings = with types ; attrsOf str ; 15mpvDefaultProfiles = with types ; listOf str ; 16 17renderOption = option : 18rec { 19int = toString option ; 20float = int ; 21bool = lib . hm . booleans . yesNo option ; 22string = option ; 23}.${ typeOf option }; 24 25renderOptionValue = value : 26let 27rendered = renderOption value ; 28length = toString ( stringLength rendered ); 29in "% ${ length } % ${ rendered } " ; 30 31renderOptions = generators . toKeyValue { 32mkKeyValue = 33generators . mkKeyValueDefault { mkValueString = renderOptionValue ; } "=" ; 34listsAsDuplicateKeys = true ; 35}; 36 37renderScriptOptions = generators . toKeyValue { 38mkKeyValue = 39generators . mkKeyValueDefault { mkValueString = renderOption ; } "=" ; 40listsAsDuplicateKeys = true ; 41}; 42 43renderProfiles = generators . toINI { 44mkKeyValue = 45generators . mkKeyValueDefault { mkValueString = renderOptionValue ; } "=" ; 46listsAsDuplicateKeys = true ; 47}; 48 49renderBindings = bindings : 50concatStringsSep "\n" 51( mapAttrsToList ( name :value :" ${ name } ${ value } " ) bindings ); 52 53renderDefaultProfiles = profiles : 54renderOptions { profile = concatStringsSep "," profiles ; }; 55 56mpvPackage = if cfg . scripts == [ ] then 57cfg . package 58else 59pkgs . wrapMpv pkgs . mpv-unwrapped { scripts = cfg . scripts ; }; 60 61in { 62options = { 63programs . mpv = { 64enable = mkEnableOption "mpv" ; 65 66package = mkOption { 67type = types . package ; 68default = pkgs . mpv ; 69example = literalExpression 70"pkgs.wrapMpv (pkgs.mpv-unwrapped.override { vapoursynthSupport = true; }) { youtubeSupport = true; }" ; 71description = '' 72Package providing mpv. 73'' ; 74}; 75 76finalPackage = mkOption { 77type = types . package ; 78readOnly = true ; 79visible = false ; 80description = '' 81Resulting mpv package. 82'' ; 83}; 84 85scripts = mkOption { 86type = with types ; listOf package ; 87default = [ ]; 88example = literalExpression "[ pkgs.mpvScripts.mpris ]" ; 89description = '' 90List of scripts to use with mpv. 91'' ; 92}; 93 94scriptOpts = mkOption { 95description = '' 96Script options added to 97{file}`$XDG_CONFIG_HOME/mpv/script-opts/`. See 98{manpage}`mpv(1)` 99for the full list of options of builtin scripts. 100'' ; 101type = types . attrsOf mpvOptions ; 102default = { }; 103example = { 104osc = { 105scalewindowed = 2.0 ; 106vidscale = false ; 107visibility = "always" ; 108}; 109}; 110}; 111 112config = mkOption { 113description = '' 114Configuration written to 115{file}`$XDG_CONFIG_HOME/mpv/mpv.conf`. See 116{manpage}`mpv(1)` 117for the full list of options. 118'' ; 119type = mpvOptions ; 120default = { }; 121example = literalExpression '' 122{ 123profile = "gpu-hq"; 124force-window = true; 125ytdl-format = "bestvideo+bestaudio"; 126cache-default = 4000000; 127} 128'' ; 129}; 130 131profiles = mkOption { 132description = '' 133Sub-configuration options for specific profiles written to 134{file}`$XDG_CONFIG_HOME/mpv/mpv.conf`. See 135{option}`programs.mpv.config` for more information. 136'' ; 137type = mpvProfiles ; 138default = { }; 139example = literalExpression '' 140{ 141fast = { 142vo = "vdpau"; 143}; 144"protocol.dvd" = { 145profile-desc = "profile for dvd:// streams"; 146alang = "en"; 147}; 148} 149'' ; 150}; 151 152defaultProfiles = mkOption { 153description = '' 154Profiles to be applied by default. Options set by them are overridden 155by options set in [](#opt-programs.mpv.config). 156'' ; 157type = mpvDefaultProfiles ; 158default = [ ]; 159example = [ "gpu-hq" ]; 160}; 161 162bindings = mkOption { 163description = '' 164Input configuration written to 165{file}`$XDG_CONFIG_HOME/mpv/input.conf`. See 166{manpage}`mpv(1)` 167for the full list of options. 168'' ; 169type = mpvBindings ; 170default = { }; 171example = literalExpression '' 172{ 173WHEEL_UP = "seek 10"; 174WHEEL_DOWN = "seek -10"; 175"Alt+0" = "set window-scale 0.5"; 176} 177'' ; 178}; 179}; 180}; 181 182config = mkIf cfg . enable ( mkMerge [ 183{ 184assertions = [{ 185assertion = ( cfg . scripts == [ ]) || ( cfg . package == pkgs . mpv ); 186message = '' 187The programs.mpv "package" option is mutually exclusive with "scripts" option.'' ; 188}]; 189} 190{ 191home . packages = [ mpvPackage ]; 192programs . mpv . finalPackage = mpvPackage ; 193} 194( mkIf ( cfg . config != { } || cfg . profiles != { }) { 195xdg . configFile . "mpv/mpv.conf" . text = '' 196${ optionalString ( cfg . defaultProfiles != [ ]) 197( renderDefaultProfiles cfg . defaultProfiles )} 198${ optionalString ( cfg . config != { }) ( renderOptions cfg . config )} 199${ optionalString ( cfg . profiles != { }) ( renderProfiles cfg . profiles )} 200'' ; 201}) 202( mkIf ( cfg . bindings != { }) { 203xdg . configFile . "mpv/input.conf" . text = renderBindings cfg . bindings ; 204}) 205{ 206xdg . configFile = mapAttrs' ( name :value : 207nameValuePair "mpv/script-opts/ ${ name } .conf" { 208text = renderScriptOptions value ; 209}) cfg . scriptOpts ; 210} 211]); 212 213meta . maintainers = with maintainers ; [ tadeokondrak thiagokokada chuangzhu ]; 214}