fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , options , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . mopidy ; 8 9# The configuration format of Mopidy. It seems to use configparser with 10# some quirky handling of its types. You can see how they're handled in 11# `mopidy/config/types.py` from the source code. 12toMopidyConf = generators . toINI { 13mkKeyValue = generators . mkKeyValueDefault { 14mkValueString = v : 15if isList v then 16"\n " + concatStringsSep "\n " v 17else 18generators . mkValueStringDefault { } v ; 19} " = " ; 20}; 21 22mopidyEnv = pkgs . buildEnv { 23name = "mopidy-with-extensions- ${ pkgs . mopidy . version } " ; 24paths = closePropagation cfg . extensionPackages ; 25pathsToLink = [ "/ ${ pkgs . mopidyPackages . python . sitePackages } " ]; 26buildInputs = [ pkgs . makeWrapper ]; 27postBuild = '' 28makeWrapper ${ pkgs . mopidy } /bin/mopidy $ out /bin/mopidy \ 29--prefix PYTHONPATH : $ out / ${ pkgs . mopidyPackages . python . sitePackages } 30'' ; 31}; 32 33# Nix-representable format for Mopidy config. 34mopidyConfFormat = { } :{ 35type = with types ; 36let 37valueType = nullOr ( oneOf [ bool float int str ( listOf valueType ) ]) 38// { 39description = "Mopidy config value" ; 40}; 41in attrsOf ( attrsOf valueType ); 42 43generate = name :value :pkgs . writeText name ( toMopidyConf value ); 44}; 45 46settingsFormat = mopidyConfFormat { }; 47 48configFilePaths = concatStringsSep ":" 49([ " ${ config . xdg . configHome } /mopidy/mopidy.conf" ] ++ cfg . extraConfigFiles ); 50 51in { 52meta . maintainers = [ hm . maintainers . foo-dogsquared ]; 53 54options . services . mopidy = { 55enable = mkEnableOption "Mopidy music player daemon" ; 56 57extensionPackages = mkOption { 58type = with types ; listOf package ; 59default = [ ]; 60example = literalExpression 61"with pkgs; [ mopidy-spotify mopidy-mpd mopidy-mpris ]" ; 62description = '' 63Mopidy extensions that should be loaded by the service. 64'' ; 65}; 66 67settings = mkOption { 68type = settingsFormat . type ; 69default = { }; 70example = literalExpression '' 71{ 72file = { 73media_dirs = [ 74"$XDG_MUSIC_DIR|Music" 75"~/library|Library" 76]; 77follow_symlinks = true; 78excluded_file_extensions = [ 79".html" 80".zip" 81".jpg" 82".jpeg" 83".png" 84]; 85}; 86 87# Please don't put your mopidy-spotify configuration in the public. :) 88# Think of your Spotify Premium subscription! 89spotify = { 90client_id = "CLIENT_ID"; 91client_secret = "CLIENT_SECRET"; 92}; 93} 94'' ; 95description = '' 96Configuration written to 97{file}`$XDG_CONFIG_HOME/mopidy/mopidy.conf`. 98 99See <https://docs.mopidy.com/en/latest/config/> for 100more details. 101'' ; 102}; 103 104extraConfigFiles = mkOption { 105default = [ ]; 106type = types . listOf types . path ; 107description = '' 108Extra configuration files read by Mopidy when the service starts. 109Later files in the list override earlier configuration files and 110structured settings. 111'' ; 112}; 113}; 114 115config = mkIf cfg . enable { 116assertions = 117[ ( hm . assertions . assertPlatform "services.mopidy" pkgs platforms . linux ) ]; 118 119xdg . configFile . "mopidy/mopidy.conf" . source = 120settingsFormat . generate "mopidy- ${ config . home . username } " cfg . settings ; 121 122systemd . user . services . mopidy = { 123Unit = { 124Description = "mopidy music player daemon" ; 125Documentation = [ "https://mopidy.com/" ]; 126After = [ "network.target" "sound.target" ]; 127}; 128 129Service = { 130ExecStart = " ${ mopidyEnv } /bin/mopidy --config ${ configFilePaths } " ; 131}; 132 133Install . WantedBy = [ "default.target" ]; 134}; 135 136systemd . user . services . mopidy-scan = { 137Unit = { 138Description = "mopidy local files scanner" ; 139Documentation = [ "https://mopidy.com/" ]; 140After = [ "network.target" "sound.target" ]; 141}; 142 143Service = { 144ExecStart = 145" ${ mopidyEnv } /bin/mopidy --config ${ configFilePaths } local scan" ; 146Type = "oneshot" ; 147}; 148 149Install . WantedBy = [ "default.target" ]; 150}; 151}; 152}