From 6bd0a92f95492301ef8c0403d1abf5b127c3245a Mon Sep 17 00:00:00 2001 From: Nydragon Date: Thu, 19 Dec 2024 23:15:34 +0100 Subject: [PATCH] feat: add mpd for beets' play plugin --- flake.nix | 3 +- home/terminal/beets.nix | 68 +++++++++++++++++++++++++++++++++++++++-- modules/users/ny.nix | 1 + 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 2817217..4d0e7a8 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Nydragon's NixOS configuration"; + description = "Nydragon's system configuration"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; @@ -56,6 +56,7 @@ { pkgs, inputs', ... }: { formatter = pkgs.nixfmt-rfc-style; + devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ pre-commit diff --git a/home/terminal/beets.nix b/home/terminal/beets.nix index 238134a..1eadfb9 100644 --- a/home/terminal/beets.nix +++ b/home/terminal/beets.nix @@ -1,6 +1,13 @@ -{ pkgs, lib, ... }: +{ + pkgs, + lib, + osConfig, + config, + ... +}: let inherit (lib) concatStringsSep listToAttrs; + inherit (lib.my) getExe; plugins = [ "convert" "chroma" @@ -14,10 +21,46 @@ let "missing" "unimported" "badfiles" + "embedart" + "play" ]; + + mkConf = + a: + let + mkGroup = name: values: '' + ${name} { + ${lib.concatStringsSep "\n\t" values} + }''; + stringify = lib.mapAttrsToList ( + name: value: + if lib.isAttrs value then + mkGroup name (stringify value) + else if (lib.isInt value || lib.isFloat value) then + ''${name} "${toString value}"'' + else + ''${name} "${value}"'' + ); + in + concatStringsSep "\n" (stringify a); + + mpdSocket = "/run/user/${toString osConfig.users.users.${config.home.username}.uid}/mpd/socket"; in { config = { + services.mpd = { + enable = true; + extraConfig = mkConf { + auto_update = "yes"; + log_file = "syslog"; + bind_to_address = mpdSocket; + audio_output = { + type = "pipewire"; + name = "PipeWire Sound Server"; + }; + }; + }; + programs.beets = { package = pkgs.beets.override { pluginOverrides = listToAttrs ( @@ -36,6 +79,26 @@ in format = "flac"; never_convert_lossy_files = "yes"; }; + play = { + command = + let + mpc = "${getExe pkgs.mpc} --host=\"${mpdSocket}\""; + ncmpcpp = getExe pkgs.ncmpcpp; + + command = pkgs.writers.writeFishBin "play-command" '' + set playlist "$argv[1]"; + ${mpc} clear; + ${mpc} load "$playlist"; + rm "$playlist"; + ${mpc} play; + ${ncmpcpp} $args; + ''; + in + "${command}/bin/play-command"; + }; + embedart = { + maxwidth = 500; + }; fetchart = { auto = true; cover_format = "jpg"; @@ -67,7 +130,8 @@ in languages = "en"; }; item_fields = { - disc_and_track = "u'%02i.%02i' % (disc, track) if disctotal > 1 else u'%02i' % (track)"; + disc_and_track = # python + "u'%02i.%02i' % (disc, track) if disctotal > 1 else u'%02i' % (track)"; primary_albumartist = # python '' if albumartist.lower().strip().startswith(albumartists[0].lower().strip()): diff --git a/modules/users/ny.nix b/modules/users/ny.nix index eeb8512..8c9fa71 100644 --- a/modules/users/ny.nix +++ b/modules/users/ny.nix @@ -7,6 +7,7 @@ "wheel" ]; shell = pkgs.fish; + uid = 1000; }; programs.fish.enable = true; }