A recent PR I made to an OSS library (mopidy-tidal) added a flake.nix for development.
While I was at it I thought I might as well expose an actual package: after all I need to pull this into my own system, and it’s easier just to pull in a package I know builds.
I’ve not done this before (tried to provide a package output for others / nixpkgs to pull) so I thought I’d ask for criticism. Here’s the flake:
{
description = "Mopidy Extension for Tidal music service integration.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = nixpkgs.lib.systems.flakeExposed;
perSystem = {
pkgs,
system,
...
}: let
pyProject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
version = pyProject.project.version;
python = pkgs.python313;
buildInputs =
[
(python.withPackages (ps: [ps.gst-python ps.pygobject3]))
]
++ (with pkgs; [
# dev
uv
pre-commit
ruff
# deps
mopidy # for its build inputs, and local testing
gobject-introspection
glib-networking
# integration tests
mpc
mopidy-mpd
# local testing
mopidy-local
mopidy-iris
])
++ (with pkgs.gst_all_1; [
gst-plugins-bad
gst-plugins-base
gst-plugins-good
gst-plugins-ugly
gst-plugins-rs
]);
in {
devShells.default = pkgs.mkShell {
inherit buildInputs;
env = {
UV_PROJECT_ENVIRONMENT = ".direnv/venv";
# libsoup_3 is broken, and why wouldn't you use curl?
GST_PLUGIN_FEATURE_RANK = "curlhttpsrc:MAX";
};
shellHook = ''
# pre-commit install
[ ! -d $UV_PROJECT_ENVIRONMENT ] && uv venv $UV_PROJECT_ENVIRONMENT --python ${python}/bin/python
source $UV_PROJECT_ENVIRONMENT/bin/activate
'';
};
packages.default = pkgs.python3Packages.buildPythonApplication {
pname = "mopidy-tidal";
inherit version;
pyproject = true;
src = ./.;
build-system = [pkgs.python3Packages.uv-build];
nativeCheckInputs = with pkgs.python3Packages; [
pytestCheckHook
pytest-asyncio
pytest-cov # since default pytest invocation includes --cov
pytest-mock
pytest-httpserver
pytest-cases
trustme
httpx
];
dependencies = [
pkgs.mopidy
pkgs.python3Packages.tidalapi
];
};
};
};
}
(I’m really interested in criticism of the packages output, but feel free to criticise the rest).
Reasoning here was:
- I could use uv2nix, but I’ve not seen it in nixpkgs (presumably to keep the closure small?)
- there’s no point naming it anything as far as I can see, this lib will only ever have one package
Is it worthwhile submitting a PR to nixpkgs to consume the flake directly?