fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . kodi ; 7 8stylesheetCommonHeader = '' 9<?xml version="1.0"?> 10<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> 11<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> 12<xsl:strip-space elements="*"/> 13'' ; 14 15stylesheetCommonFooter = "</xsl:stylesheet>" ; 16 17stylesheetNestedTags = '' 18<xsl:template match="attr[attrs]"> 19<xsl:variable name="elementName" select="@name"/> 20<xsl:element name="{$elementName}"> 21<xsl:apply-templates select="attrs" /> 22</xsl:element> 23</xsl:template> 24<xsl:template match="attr[list[attrs]]"> 25<xsl:variable name="elementName" select="@name"/> 26<xsl:for-each select="list/attrs"> 27<xsl:element name="{$elementName}"> 28<xsl:apply-templates select="." /> 29</xsl:element> 30</xsl:for-each> 31</xsl:template> 32<xsl:template match="attr[not(attrs|list)]"> 33<xsl:variable name="elementName" select="@name"/> 34<xsl:element name="{$elementName}"> 35<xsl:if test="$elementName='path'"> 36<!-- needed in sources.xml but will be used for all "path" tags --> 37<xsl:attribute name="pathversion">1</xsl:attribute> 38</xsl:if> 39<xsl:value-of select="*/@value" /> 40</xsl:element> 41</xsl:template> 42'' ; 43 44stylesheetTagsAsSettingWithId = '' 45<xsl:template match='attr'> 46<setting> 47<xsl:attribute name="id"> 48<xsl:value-of select="@name" /> 49</xsl:attribute> 50<xsl:value-of select="*/@value" /> 51</setting> 52</xsl:template> 53'' ; 54 55stylesheetAdvancedSettingsRootTag = '' 56<xsl:template match='/'> 57<xsl:comment> Generated by Home Manager. </xsl:comment> 58<advancedsettings version="1.0"> 59<xsl:apply-templates/> 60</advancedsettings> 61</xsl:template> 62'' ; 63 64stylesheetSourcesRootTag = '' 65<xsl:template match='/'> 66<xsl:comment> Generated by Home Manager. </xsl:comment> 67<sources> 68<xsl:apply-templates/> 69</sources> 70</xsl:template> 71'' ; 72 73stylesheetAddonSettingsRootTag = '' 74<xsl:template match='/'> 75<xsl:comment> Generated by Home Manager. </xsl:comment> 76<settings version="2"> 77<xsl:apply-templates/> 78</settings> 79</xsl:template> 80'' ; 81 82attrsetToXml = attrs :name :stylesheet : 83pkgs . runCommand name { 84# Package splicing for libxslt does not work correctly leading to errors 85# when cross-compiling. Use the version from buildPackages explicitly to 86# fix this. 87nativeBuildInputs = [ pkgs . buildPackages . libxslt . bin ]; 88xml = builtins . toXML attrs ; 89passAsFile = [ "xml" ]; 90} '' 91xsltproc ${ stylesheet } - < " $ xmlPath " > " $ out " 92'' ; 93 94attrsetToAdvancedSettingsXml = attrs :name : 95let 96stylesheet = builtins . toFile "stylesheet.xsl" '' 97${ stylesheetCommonHeader } 98${ stylesheetAdvancedSettingsRootTag } 99${ stylesheetNestedTags } 100${ stylesheetCommonFooter } 101'' ; 102in attrsetToXml attrs name stylesheet ; 103 104attrsetToSourcesXml = attrs :name : 105let 106stylesheet = builtins . toFile "stylesheet.xsl" '' 107${ stylesheetCommonHeader } 108${ stylesheetSourcesRootTag } 109${ stylesheetNestedTags } 110${ stylesheetCommonFooter } 111'' ; 112in attrsetToXml attrs name stylesheet ; 113 114attrsetToAddonSettingsXml = attrs :name : 115let 116stylesheet = builtins . toFile "stylesheet.xsl" '' 117${ stylesheetCommonHeader } 118${ stylesheetAddonSettingsRootTag } 119${ stylesheetTagsAsSettingWithId } 120${ stylesheetCommonFooter } 121'' ; 122in attrsetToXml attrs name stylesheet ; 123 124in { 125meta . maintainers = [ hm . maintainers . dwagenk ]; 126 127options . programs . kodi = { 128enable = mkEnableOption "Kodi" ; 129 130package = mkOption { 131type = types . package ; 132default = pkgs . kodi ; 133defaultText = literalExpression "pkgs.kodi" ; 134example = literalExpression 135"pkgs.kodi.withPackages (exts: [ exts.pvr-iptvsimple ])" ; 136description = '' 137The `kodi` package to use. 138Can be used to specify extensions. 139'' ; 140}; 141 142datadir = mkOption { 143type = types . path ; 144default = " ${ config . home . homeDirectory } /.kodi" ; 145defaultText = 146literalExpression ''"''${config.home.homeDirectory}/.kodi"'' ; 147example = literalExpression ''"''${config.xdg.dataHome}/kodi"'' ; 148description = "Directory to store configuration and metadata." ; 149}; 150 151settings = mkOption { 152type = with types ; 153let 154valueType = either str ( attrsOf valueType ) // { 155description = "attribute sets of strings" ; 156}; 157in nullOr valueType ; 158default = null ; 159example = literalExpression '' 160{ videolibrary.showemptytvshows = "true"; } 161'' ; 162description = '' 163Configuration to write to the `advancedsettings.xml` 164file in kodis userdata directory. Settings specified here will be 165immutable from inside kodi and be hidden from the GUI settings dialog. 166 167See <https://kodi.wiki/view/Advancedsettings.xml> as 168reference for how settings need to be specified. 169 170The innermost attributes must be of type str. 171'' ; 172}; 173 174sources = mkOption { 175type = with types ; 176let 177valueType = oneOf [ str ( attrsOf valueType ) ( listOf valueType ) ] // { 178description = "attribute sets or lists of strings" ; 179}; 180in nullOr valueType ; 181default = null ; 182example = literalExpression '' 183{ 184video = { 185default = "movies"; 186source = [ 187{ name = "videos"; path = "/path/to/videos"; allowsharing = "true"; } 188{ name = "movies"; path = "/path/to/movies"; allowsharing = "true"; } 189]; 190}; 191} 192'' ; 193description = '' 194Contents to populate the file `sources.xml` in kodis 195userdata directory. 196 197See <https://kodi.wiki/view/Sources.xml> as 198reference for how sources need to be specified. 199 200Kodi will still show the dialogs to modify sources in the GUI and they 201appear to be mutable. This however is not the case and the sources will 202stay as specified via Home Manager. 203 204The innermost attributes must be of type str. 205'' ; 206}; 207 208addonSettings = mkOption { 209type = with types ; nullOr ( attrsOf ( attrsOf str )); 210default = null ; 211example = literalExpression '' 212{ "service.xbmc.versioncheck".versioncheck_enable = "false"; } 213'' ; 214description = '' 215Attribute set with the plugin namespace as toplevel key and the plugins 216settings as lower level key/value pairs. 217 218Kodi will still show the settings of plugins configured via this 219mechanism in the GUI and they appear to be mutable. This however is 220not the case and the settings will stay as specified via Home Manager. 221'' ; 222}; 223}; 224 225config = mkIf cfg . enable ( mkMerge [ 226{ 227assertions = [ 228( lib . hm . assertions . assertPlatform "programs.kodi" pkgs 229lib . platforms . linux ) 230]; 231 232home . packages = [ cfg . package ]; 233home . sessionVariables = { KODI_DATA = cfg . datadir ; }; 234} 235 236( mkIf ( cfg . settings != null ) { 237home . file . " ${ cfg . datadir } /userdata/advancedsettings.xml" . source = 238attrsetToAdvancedSettingsXml cfg . settings "kodi-advancedsettings.xml" ; 239}) 240 241( mkIf ( cfg . sources != null ) { 242home . file . " ${ cfg . datadir } /userdata/sources.xml" . source = 243attrsetToSourcesXml cfg . sources "kodi-sources.xml" ; 244}) 245 246( mkIf ( cfg . addonSettings != null ) { 247home . file = mapAttrs' ( k :v : 248attrsets . nameValuePair 249( " ${ cfg . datadir } /userdata/addon_data/ ${ k } /settings.xml" ) { 250source = attrsetToAddonSettingsXml v "kodi-addon- ${ k } -settings.xml" ; 251}) cfg . addonSettings ; 252}) 253]); 254}