Similar to the above comment, I think the best way to learn the specifics of functions like buildPythonApplication is to read the docs, but I will point out why your current derivation is broken.
The part where you’re including python3Packages is wrong:
propagatedBuildInputs = [
pkgs.playerctl
(python3Packages (python-pkgs: with python-pkgs; [
pandas
requests
syncedlyrics
pillow
pygobject3
]))
];
If you try building the derivation as-is, you get the following error:
error: attempt to call something which is not a function but a set: { APScheduler = «thunk»; BTrees = «thunk»; Babel = «thunk»; BlinkStick = «thunk»; ColanderAlchemy = «thunk»; CommonMark = «thunk»; ConfigArgParse = «thunk»; EasyProcess = «thunk»; Fabric = «thunk»; FormEncode = «thunk»; «8861 attributes elided» }
at /root/test/waybar-media-player-bad.nix:10:8:
9| pkgs.playerctl
10| (python3Packages (python-pkgs: with python-pkgs; [
| ^
11| pandas
This is because in nix, the way you call functions is function arg1 argN
, eg
nix-repl> map (x: x * 2) [1 2 3]
[2 4 6]
So you’re trying to call python3Packages as a function, when really you’re just trying to access its attributes. To do so, you can use something like this:
{pkgs}:
pkgs.python3Packages.buildPythonApplication rec {
pname = "waybar-mediaplayer-script";
version = "0.0.1";
pyproject = false;
propagatedBuildInputs = with pkgs;
with pkgs.python3Packages; [
playerctl
pandas
requests
syncedlyrics
pillow
pygobject3
];
dontUnpack = true;
installPhase = ''
install -Dm755 "${./${pname}}" "$out/bin/${pname}"
'';
}
Or if you don’t want to conflate the scope of python packages and system packages:
propagatedBuildInputs = with pkgs; [
playerctl
python3Packages.pandas
python3Packages.requests
python3Packages.syncedlyrics
python3Packages.pillow
python3Packages.pygobject3
];
Regardless, this will create a proper list of build inputs and should allow you to build the derivation.
Also, for completeness and in case you didn’t know, you’ll need a default.nix file to pull and pass in nixpkgs:
# cat default.nix
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05";
pkgs = import nixpkgs {};
in {
waybar-media-player = pkgs.callPackage ./waybar-media-player.nix {};
}
This should let you build your derivation:
$ nix-build
/nix/store/phqb1ij55vympnrznr0k6khky1hkdklm-waybar-mediaplayer-script-0.0.1
$ ./result/bin/waybar-mediaplayer-script
script doing stuff!