nixos/mopidy: test & cleanup (#356021)

This commit is contained in:
Felix Bühler 2024-11-24 16:01:21 +01:00 committed by GitHub
commit b675ca747f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 35 deletions

View File

@ -1,24 +1,20 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with pkgs;
with lib;
let let
uid = config.ids.uids.mopidy; uid = config.ids.uids.mopidy;
gid = config.ids.gids.mopidy; gid = config.ids.gids.mopidy;
cfg = config.services.mopidy; cfg = config.services.mopidy;
mopidyConf = writeText "mopidy.conf" cfg.configuration; mopidyConf = pkgs.writeText "mopidy.conf" cfg.configuration;
mopidyEnv = buildEnv { mopidyEnv = pkgs.buildEnv {
name = "mopidy-with-extensions-${mopidy.version}"; name = "mopidy-with-extensions-${pkgs.mopidy.version}";
ignoreCollisions = true; ignoreCollisions = true;
paths = closePropagation cfg.extensionPackages; paths = lib.closePropagation cfg.extensionPackages;
pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ]; pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ];
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = '' postBuild = ''
makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \ makeWrapper ${lib.getExe pkgs.mopidy} $out/bin/mopidy \
--prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages} --prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages}
''; '';
}; };
in { in {
@ -27,49 +23,47 @@ in {
services.mopidy = { services.mopidy = {
enable = mkEnableOption "Mopidy, a music player daemon"; enable = lib.mkEnableOption "Mopidy, a music player daemon";
dataDir = mkOption { dataDir = lib.mkOption {
default = "/var/lib/mopidy"; default = "/var/lib/mopidy";
type = types.str; type = lib.types.str;
description = '' description = ''
The directory where Mopidy stores its state. The directory where Mopidy stores its state.
''; '';
}; };
extensionPackages = mkOption { extensionPackages = lib.mkOption {
default = []; default = [];
type = types.listOf types.package; type = lib.types.listOf lib.types.package;
example = literalExpression "[ pkgs.mopidy-spotify ]"; example = lib.literalExpression "[ pkgs.mopidy-spotify ]";
description = '' description = ''
Mopidy extensions that should be loaded by the service. Mopidy extensions that should be loaded by the service.
''; '';
}; };
configuration = mkOption { configuration = lib.mkOption {
default = ""; default = "";
type = types.lines; type = lib.types.lines;
description = '' description = ''
The configuration that Mopidy should use. The configuration that Mopidy should use.
''; '';
}; };
extraConfigFiles = mkOption { extraConfigFiles = lib.mkOption {
default = []; default = [];
type = types.listOf types.str; type = lib.types.listOf lib.types.str;
description = '' description = ''
Extra config file read by Mopidy when the service starts. Extra config file read by Mopidy when the service starts.
Later files in the list overrides earlier configuration. Later files in the list overrides earlier configuration.
''; '';
}; };
}; };
}; };
###### implementation ###### implementation
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = { systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = {
user = "mopidy"; user = "mopidy";
@ -82,7 +76,7 @@ in {
wants = [ "network-online.target" ]; wants = [ "network-online.target" ];
description = "mopidy music player daemon"; description = "mopidy music player daemon";
serviceConfig = { serviceConfig = {
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}"; ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
User = "mopidy"; User = "mopidy";
}; };
}; };
@ -90,7 +84,7 @@ in {
systemd.services.mopidy-scan = { systemd.services.mopidy-scan = {
description = "mopidy local files scanner"; description = "mopidy local files scanner";
serviceConfig = { serviceConfig = {
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan"; ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
User = "mopidy"; User = "mopidy";
Type = "oneshot"; Type = "oneshot";
}; };
@ -105,7 +99,5 @@ in {
}; };
users.groups.mopidy.gid = gid; users.groups.mopidy.gid = gid;
}; };
} }

View File

@ -619,6 +619,7 @@ in {
mongodb = handleTest ./mongodb.nix {}; mongodb = handleTest ./mongodb.nix {};
moodle = handleTest ./moodle.nix {}; moodle = handleTest ./moodle.nix {};
moonraker = handleTest ./moonraker.nix {}; moonraker = handleTest ./moonraker.nix {};
mopidy = handleTest ./mopidy.nix {};
morph-browser = handleTest ./morph-browser.nix { }; morph-browser = handleTest ./morph-browser.nix { };
morty = handleTest ./morty.nix {}; morty = handleTest ./morty.nix {};
mosquitto = handleTest ./mosquitto.nix {}; mosquitto = handleTest ./mosquitto.nix {};

17
nixos/tests/mopidy.nix Normal file
View File

@ -0,0 +1,17 @@
import ./make-test-python.nix (
{ pkgs, ... }:
{
name = "mopidy";
nodes.machine =
{ ... }:
{
services.mopidy.enable = true;
};
testScript = ''
machine.wait_for_unit("mopidy")
machine.wait_for_open_port(6680)
'';
}
)

View File

@ -8,6 +8,7 @@
glib-networking, glib-networking,
gobject-introspection, gobject-introspection,
pipewire, pipewire,
nixosTests,
}: }:
pythonPackages.buildPythonApplication rec { pythonPackages.buildPythonApplication rec {
@ -34,9 +35,7 @@ pythonPackages.buildPythonApplication rec {
]; ];
propagatedBuildInputs = propagatedBuildInputs =
[ [ gobject-introspection ]
gobject-introspection
]
++ ( ++ (
with pythonPackages; with pythonPackages;
[ [
@ -50,13 +49,15 @@ pythonPackages.buildPythonApplication rec {
++ lib.optional (!stdenv.hostPlatform.isDarwin) dbus-python ++ lib.optional (!stdenv.hostPlatform.isDarwin) dbus-python
); );
propagatedNativeBuildInputs = [ propagatedNativeBuildInputs = [ gobject-introspection ];
gobject-introspection
];
# There are no tests # There are no tests
doCheck = false; doCheck = false;
passthru.tests = {
inherit (nixosTests) mopidy;
};
meta = with lib; { meta = with lib; {
homepage = "https://www.mopidy.com/"; homepage = "https://www.mopidy.com/";
description = "Extensible music server that plays music from local disk, Spotify, SoundCloud, and more"; description = "Extensible music server that plays music from local disk, Spotify, SoundCloud, and more";