From fba9ba64b37a27c67268ce1db492c7b4ab423130 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 14 Nov 2024 23:39:47 +0100 Subject: [PATCH 1/5] nixos/mopidy: remove "with" statment --- nixos/modules/services/audio/mopidy.nix | 50 +++++++++++-------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/nixos/modules/services/audio/mopidy.nix b/nixos/modules/services/audio/mopidy.nix index 3e0241c10b81..a83c4fbc0006 100644 --- a/nixos/modules/services/audio/mopidy.nix +++ b/nixos/modules/services/audio/mopidy.nix @@ -1,24 +1,20 @@ { config, lib, pkgs, ... }: - -with pkgs; -with lib; - let uid = config.ids.uids.mopidy; gid = config.ids.gids.mopidy; cfg = config.services.mopidy; - mopidyConf = writeText "mopidy.conf" cfg.configuration; + mopidyConf = pkgs.writeText "mopidy.conf" cfg.configuration; - mopidyEnv = buildEnv { - name = "mopidy-with-extensions-${mopidy.version}"; + mopidyEnv = pkgs.buildEnv { + name = "mopidy-with-extensions-${pkgs.mopidy.version}"; ignoreCollisions = true; - paths = closePropagation cfg.extensionPackages; - pathsToLink = [ "/${mopidyPackages.python.sitePackages}" ]; - nativeBuildInputs = [ makeWrapper ]; + paths = lib.closePropagation cfg.extensionPackages; + pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' - makeWrapper ${mopidy}/bin/mopidy $out/bin/mopidy \ - --prefix PYTHONPATH : $out/${mopidyPackages.python.sitePackages} + makeWrapper ${pkgs.mopidy}/bin/mopidy $out/bin/mopidy \ + --prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages} ''; }; in { @@ -27,49 +23,47 @@ in { 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"; - type = types.str; + type = lib.types.str; description = '' The directory where Mopidy stores its state. ''; }; - extensionPackages = mkOption { + extensionPackages = lib.mkOption { default = []; - type = types.listOf types.package; - example = literalExpression "[ pkgs.mopidy-spotify ]"; + type = lib.types.listOf lib.types.package; + example = lib.literalExpression "[ pkgs.mopidy-spotify ]"; description = '' Mopidy extensions that should be loaded by the service. ''; }; - configuration = mkOption { + configuration = lib.mkOption { default = ""; - type = types.lines; + type = lib.types.lines; description = '' The configuration that Mopidy should use. ''; }; - extraConfigFiles = mkOption { + extraConfigFiles = lib.mkOption { default = []; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; description = '' Extra config file read by Mopidy when the service starts. Later files in the list overrides earlier configuration. ''; }; - }; - }; ###### implementation - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { systemd.tmpfiles.settings."10-mopidy".${cfg.dataDir}.d = { user = "mopidy"; @@ -82,7 +76,7 @@ in { wants = [ "network-online.target" ]; description = "mopidy music player daemon"; serviceConfig = { - ExecStart = "${mopidyEnv}/bin/mopidy --config ${concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}"; + ExecStart = "${mopidyEnv}/bin/mopidy --config ${lib.concatStringsSep ":" ([mopidyConf] ++ cfg.extraConfigFiles)}"; User = "mopidy"; }; }; @@ -90,7 +84,7 @@ in { systemd.services.mopidy-scan = { description = "mopidy local files scanner"; 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"; Type = "oneshot"; }; @@ -105,7 +99,5 @@ in { }; users.groups.mopidy.gid = gid; - }; - } From 8f6ffd06a4ec118c2d84d64b5c65d42482f2dac2 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 14 Nov 2024 23:40:14 +0100 Subject: [PATCH 2/5] nixos/mopidy: add test --- nixos/tests/all-tests.nix | 1 + nixos/tests/mopidy.nix | 12 ++++++++++++ pkgs/applications/audio/mopidy/mopidy.nix | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 nixos/tests/mopidy.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 47c1ce41671b..e828b0cad61e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -619,6 +619,7 @@ in { mongodb = handleTest ./mongodb.nix {}; moodle = handleTest ./moodle.nix {}; moonraker = handleTest ./moonraker.nix {}; + mopidy = handleTest ./mopidy.nix {}; morph-browser = handleTest ./morph-browser.nix { }; morty = handleTest ./morty.nix {}; mosquitto = handleTest ./mosquitto.nix {}; diff --git a/nixos/tests/mopidy.nix b/nixos/tests/mopidy.nix new file mode 100644 index 000000000000..bbc46b525ce5 --- /dev/null +++ b/nixos/tests/mopidy.nix @@ -0,0 +1,12 @@ +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) + ''; +}) diff --git a/pkgs/applications/audio/mopidy/mopidy.nix b/pkgs/applications/audio/mopidy/mopidy.nix index 579cbbf98dc0..01e582f3923e 100644 --- a/pkgs/applications/audio/mopidy/mopidy.nix +++ b/pkgs/applications/audio/mopidy/mopidy.nix @@ -8,6 +8,7 @@ glib-networking, gobject-introspection, pipewire, + nixosTests, }: pythonPackages.buildPythonApplication rec { @@ -57,6 +58,8 @@ pythonPackages.buildPythonApplication rec { # There are no tests doCheck = false; + passthru.tests = { inherit (nixosTests) mopidy; }; + meta = with lib; { homepage = "https://www.mopidy.com/"; description = "Extensible music server that plays music from local disk, Spotify, SoundCloud, and more"; From dddc9d800a911d7bcb58bc379a6e0bcff972c49c Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 14 Nov 2024 23:45:07 +0100 Subject: [PATCH 3/5] nixos/mopidy: fmt --- nixos/tests/mopidy.nix | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/nixos/tests/mopidy.nix b/nixos/tests/mopidy.nix index bbc46b525ce5..e8447af8c75a 100644 --- a/nixos/tests/mopidy.nix +++ b/nixos/tests/mopidy.nix @@ -1,12 +1,17 @@ -import ./make-test-python.nix ({ pkgs, ... }: { - name = "mopidy"; +import ./make-test-python.nix ( + { pkgs, ... }: + { + name = "mopidy"; - nodes.machine = { ... }: { - services.mopidy.enable = true; - }; + nodes.machine = + { ... }: + { + services.mopidy.enable = true; + }; - testScript = '' - machine.wait_for_unit("mopidy") - machine.wait_for_open_port(6680) - ''; -}) + testScript = '' + machine.wait_for_unit("mopidy") + machine.wait_for_open_port(6680) + ''; + } +) From 73ede0a42d6aa6f133fc5574cf23b02b0338a7ff Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Thu, 14 Nov 2024 23:45:15 +0100 Subject: [PATCH 4/5] mopidy: fmt --- pkgs/applications/audio/mopidy/mopidy.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/audio/mopidy/mopidy.nix b/pkgs/applications/audio/mopidy/mopidy.nix index 01e582f3923e..4771ade230c9 100644 --- a/pkgs/applications/audio/mopidy/mopidy.nix +++ b/pkgs/applications/audio/mopidy/mopidy.nix @@ -35,9 +35,7 @@ pythonPackages.buildPythonApplication rec { ]; propagatedBuildInputs = - [ - gobject-introspection - ] + [ gobject-introspection ] ++ ( with pythonPackages; [ @@ -51,14 +49,14 @@ pythonPackages.buildPythonApplication rec { ++ lib.optional (!stdenv.hostPlatform.isDarwin) dbus-python ); - propagatedNativeBuildInputs = [ - gobject-introspection - ]; + propagatedNativeBuildInputs = [ gobject-introspection ]; # There are no tests doCheck = false; - passthru.tests = { inherit (nixosTests) mopidy; }; + passthru.tests = { + inherit (nixosTests) mopidy; + }; meta = with lib; { homepage = "https://www.mopidy.com/"; From 9262fc48f95daf53b1cc6297f53eace38656aeb3 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 16 Nov 2024 00:56:23 +0100 Subject: [PATCH 5/5] nixos/mopidy: use lib.getExe --- nixos/modules/services/audio/mopidy.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/audio/mopidy.nix b/nixos/modules/services/audio/mopidy.nix index a83c4fbc0006..8ed701f9c9e4 100644 --- a/nixos/modules/services/audio/mopidy.nix +++ b/nixos/modules/services/audio/mopidy.nix @@ -13,7 +13,7 @@ let pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' - makeWrapper ${pkgs.mopidy}/bin/mopidy $out/bin/mopidy \ + makeWrapper ${lib.getExe pkgs.mopidy} $out/bin/mopidy \ --prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages} ''; };