-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Librespot is a Spotify client. While there is already a module for spotifyd, which uses Librespot as a library, this adds one for the upstream frontend.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ config, lib, nixosConfig, pkgs, ... }: | ||
|
||
let | ||
inherit (lib) types; | ||
|
||
cfg = config.services.librespot; | ||
in { | ||
options.services.librespot = { | ||
enable = lib.mkEnableOption "Librespot (Spotify Connect speaker daemon)"; | ||
|
||
package = lib.mkPackageOption pkgs "librespot" { }; | ||
|
||
settings = lib.mkOption { | ||
description = '' | ||
Command-line arguments to pass to librespot. | ||
Boolean values render as a flag if true, and nothing if false. | ||
Null values are ignored. | ||
All other values are rendered as options with an argument. | ||
''; | ||
type = types.submodule { | ||
freeformType = let t = types; | ||
in t.attrsOf (t.nullOr (t.oneOf [ t.bool t.str t.int t.path ])); | ||
|
||
options = { | ||
cache = lib.mkOption { | ||
default = "${config.xdg.cacheHome}/librespot"; | ||
defaultText = "$XDG_CACHE_HOME/librespot"; | ||
type = types.nullOr types.path; | ||
description = | ||
"Path to a directory where files will be cached after downloading."; | ||
}; | ||
|
||
system-cache = lib.mkOption { | ||
default = "${config.xdg.stateHome}/librespot"; | ||
defaultText = "$XDG_STATE_HOME/librespot"; | ||
type = types.nullOr types.path; | ||
description = | ||
"Path to a directory where system files (credentials, volume) will be cached."; | ||
}; | ||
}; | ||
}; | ||
default = { }; | ||
}; | ||
|
||
generatedArgs = lib.mkOption { | ||
type = types.listOf types.str; | ||
visible = true; | ||
readOnly = true; | ||
description = '' | ||
Generated command line for the librespot service. | ||
''; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
services.librespot = { | ||
generatedArgs = lib.pipe cfg.settings [ | ||
builtins.attrNames | ||
(builtins.concatMap (k: | ||
let v = cfg.settings.${k}; | ||
in if v == null || v == false then | ||
[ ] | ||
else if v == true then | ||
[ "--${k}" ] | ||
else | ||
[ "--${k}=${toString v}" ])) | ||
]; | ||
}; | ||
|
||
home.packages = [ cfg.package ]; | ||
|
||
systemd.user.services.librespot = { | ||
Unit = { Description = "Librespot (an open source Spotify client)"; }; | ||
|
||
Install.WantedBy = [ "default.target" ]; | ||
|
||
Service = { | ||
ExecStart = pkgs.writeShellScript "librespot" '' | ||
exec '${cfg.package}/bin/librespot' ${ | ||
lib.escapeShellArgs cfg.generatedArgs | ||
} | ||
''; | ||
Restart = "always"; | ||
RestartSec = 12; | ||
}; | ||
}; | ||
}; | ||
} |