58 lines
1.5 KiB
Nix
58 lines
1.5 KiB
Nix
{ lib, config, pkgs, ... }:
|
|
|
|
with lib;
|
|
let
|
|
toml = pkgs.formats.toml { };
|
|
cfg = config.my.services.spotify-player;
|
|
|
|
tomlConfig =
|
|
if cfg.configFile != null
|
|
then cfg.configFile
|
|
else toml.generate "app.toml" cfg.config;
|
|
|
|
configFolder = pkgs.runCommand "spotify-player-config" { } ''
|
|
mkdir $out
|
|
ln -s "${tomlConfig}" $out/app.toml
|
|
'';
|
|
in
|
|
{
|
|
options.my.services.spotify-player = {
|
|
enable = mkEnableOption "spotify_player";
|
|
config = mkOption {
|
|
inherit (toml) type;
|
|
default = { };
|
|
};
|
|
configFile = mkOption {
|
|
type = with types; nullOr path;
|
|
default = null;
|
|
};
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.spotify-player;
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
{
|
|
assertion = cfg.config == { } || cfg.configFile == null;
|
|
message = "At least one of the options 'config' or 'configFile' must be set.";
|
|
}
|
|
{
|
|
assertion = cfg.config != { } || cfg.configFile != null;
|
|
message = "Only one of the options 'config' or 'configFile' may be set.";
|
|
}
|
|
];
|
|
systemd.user.services.spotify-player = {
|
|
after = [ "graphical-session.target" "network.target" ];
|
|
partOf = [ "graphical-session.target" ];
|
|
wantedBy = [ "graphical-session.target" ];
|
|
serviceConfig = {
|
|
Type = "forking";
|
|
Restart = "always";
|
|
RestartSec = "1s";
|
|
ExecStart = "${getExe cfg.package} --daemon --config-folder ${configFolder}";
|
|
};
|
|
};
|
|
};
|
|
}
|