Skip to content

Commit b675ca7

Browse files
authored
nixos/mopidy: test & cleanup (#356021)
2 parents d657cbc + 9262fc4 commit b675ca7

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed
Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
{ config, lib, pkgs, ... }:
2-
3-
with pkgs;
4-
with lib;
5-
62
let
73
uid = config.ids.uids.mopidy;
84
gid = config.ids.gids.mopidy;
95
cfg = config.services.mopidy;
106

11-
mopidyConf = writeText "mopidy.conf" cfg.configuration;
7+
mopidyConf = pkgs.writeText "mopidy.conf" cfg.configuration;
128

13-
mopidyEnv = buildEnv {
14-
name = "mopidy-with-extensions-${mopidy.version}";
9+
mopidyEnv = pkgs.buildEnv {
10+
name = "mopidy-with-extensions-${pkgs.mopidy.version}";
1511
ignoreCollisions = true;
16-
paths = closePropagation cfg.extensionPackages;
17-
pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ];
18-
nativeBuildInputs = [ makeWrapper ];
12+
paths = lib.closePropagation cfg.extensionPackages;
13+
pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ];
14+
nativeBuildInputs = [ pkgs.makeWrapper ];
1915
postBuild = ''
20-
makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \
21-
--prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages}
16+
makeWrapper ${lib.getExe pkgs.mopidy} $out/bin/mopidy \
17+
--prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages}
2218
'';
2319
};
2420
in {
@@ -27,49 +23,47 @@ in {
2723

2824
services.mopidy = {
2925

30-
enable = mkEnableOption "Mopidy, a music player daemon";
26+
enable = lib.mkEnableOption "Mopidy, a music player daemon";
3127

32-
dataDir = mkOption {
28+
dataDir = lib.mkOption {
3329
default = "/var/lib/mopidy";
34-
type = types.str;
30+
type = lib.types.str;
3531
description = ''
3632
The directory where Mopidy stores its state.
3733
'';
3834
};
3935

40-
extensionPackages = mkOption {
36+
extensionPackages = lib.mkOption {
4137
default = [];
42-
type = types.listOf types.package;
43-
example = literalExpression "[ pkgs.mopidy-spotify ]";
38+
type = lib.types.listOf lib.types.package;
39+
example = lib.literalExpression "[ pkgs.mopidy-spotify ]";
4440
description = ''
4541
Mopidy extensions that should be loaded by the service.
4642
'';
4743
};
4844

49-
configuration = mkOption {
45+
configuration = lib.mkOption {
5046
default = "";
51-
type = types.lines;
47+
type = lib.types.lines;
5248
description = ''
5349
The configuration that Mopidy should use.
5450
'';
5551
};
5652

57-
extraConfigFiles = mkOption {
53+
extraConfigFiles = lib.mkOption {
5854
default = [];
59-
type = types.listOf types.str;
55+
type = lib.types.listOf lib.types.str;
6056
description = ''
6157
Extra config file read by Mopidy when the service starts.
6258
Later files in the list overrides earlier configuration.
6359
'';
6460
};
65-
6661
};
67-
6862
};
6963

7064
###### implementation
7165

72-
config = mkIf cfg.enable {
66+
config = lib.mkIf cfg.enable {
7367

7468
systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = {
7569
user = "mopidy";
@@ -82,15 +76,15 @@ in {
8276
wants = [ "network-online.target" ];
8377
description = "mopidy music player daemon";
8478
serviceConfig = {
85-
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
79+
ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}";
8680
User = "mopidy";
8781
};
8882
};
8983

9084
systemd.services.mopidy-scan = {
9185
description = "mopidy local files scanner";
9286
serviceConfig = {
93-
ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
87+
ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)} local scan";
9488
User = "mopidy";
9589
Type = "oneshot";
9690
};
@@ -105,7 +99,5 @@ in {
10599
};
106100

107101
users.groups.mopidy.gid = gid;
108-
109102
};
110-
111103
}

nixos/tests/all-tests.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ in {
619619
mongodb = handleTest ./mongodb.nix {};
620620
moodle = handleTest ./moodle.nix {};
621621
moonraker = handleTest ./moonraker.nix {};
622+
mopidy = handleTest ./mopidy.nix {};
622623
morph-browser = handleTest ./morph-browser.nix { };
623624
morty = handleTest ./morty.nix {};
624625
mosquitto = handleTest ./mosquitto.nix {};

nixos/tests/mopidy.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ./make-test-python.nix (
2+
{ pkgs, ... }:
3+
{
4+
name = "mopidy";
5+
6+
nodes.machine =
7+
{ ... }:
8+
{
9+
services.mopidy.enable = true;
10+
};
11+
12+
testScript = ''
13+
machine.wait_for_unit("mopidy")
14+
machine.wait_for_open_port(6680)
15+
'';
16+
}
17+
)

pkgs/applications/audio/mopidy/mopidy.nix

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
glib-networking,
99
gobject-introspection,
1010
pipewire,
11+
nixosTests,
1112
}:
1213

1314
pythonPackages.buildPythonApplication rec {
@@ -34,9 +35,7 @@ pythonPackages.buildPythonApplication rec {
3435
];
3536

3637
propagatedBuildInputs =
37-
[
38-
gobject-introspection
39-
]
38+
[ gobject-introspection ]
4039
++ (
4140
with pythonPackages;
4241
[
@@ -50,13 +49,15 @@ pythonPackages.buildPythonApplication rec {
5049
++ lib.optional (!stdenv.hostPlatform.isDarwin) dbus-python
5150
);
5251

53-
propagatedNativeBuildInputs = [
54-
gobject-introspection
55-
];
52+
propagatedNativeBuildInputs = [ gobject-introspection ];
5653

5754
# There are no tests
5855
doCheck = false;
5956

57+
passthru.tests = {
58+
inherit (nixosTests) mopidy;
59+
};
60+
6061
meta = with lib; {
6162
homepage = "https://www.mopidy.com/";
6263
description = "Extensible music server that plays music from local disk, Spotify, SoundCloud, and more";

0 commit comments

Comments
 (0)