2023-05-24 13:37:59 +00:00
|
|
|
{ lib
|
2021-03-20 04:20:00 +00:00
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, python3Packages
|
2024-01-13 08:15:51 +00:00
|
|
|
, ffmpeg-headless
|
2021-03-20 04:20:00 +00:00
|
|
|
, makeWrapper
|
2021-05-28 09:39:13 +00:00
|
|
|
, nixosTests
|
2023-05-24 13:37:59 +00:00
|
|
|
, nodejs
|
|
|
|
, npmHooks
|
|
|
|
, fetchNpmDeps
|
2021-03-20 04:20:00 +00:00
|
|
|
|
|
|
|
# For the update script
|
|
|
|
, coreutils
|
2021-12-06 16:07:01 +00:00
|
|
|
, curl
|
2021-03-20 04:20:00 +00:00
|
|
|
, nix-prefetch-git
|
2023-05-24 13:37:59 +00:00
|
|
|
, prefetch-npm-deps
|
2021-03-20 04:20:00 +00:00
|
|
|
, jq
|
2023-05-24 13:37:59 +00:00
|
|
|
, writeShellScript
|
2021-03-20 04:20:00 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
srcJson = lib.importJSON ./src.json;
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "azlux";
|
|
|
|
repo = "botamusique";
|
|
|
|
inherit (srcJson) rev sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Python needed to instantiate the html templates
|
|
|
|
buildPython = python3Packages.python.withPackages (ps: [ ps.jinja2 ]);
|
|
|
|
in
|
2023-05-24 13:37:59 +00:00
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "botamusique";
|
2021-12-06 16:07:01 +00:00
|
|
|
version = srcJson.version;
|
2021-03-20 04:20:00 +00:00
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
npmDeps = fetchNpmDeps {
|
|
|
|
src = "${src}/web";
|
|
|
|
hash = srcJson.npmDepsHash;
|
|
|
|
};
|
|
|
|
|
|
|
|
npmRoot = "web";
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
patches = [
|
|
|
|
# botamusique by default resolves relative state paths by first checking
|
|
|
|
# whether it exists in the working directory, then falls back to using the
|
|
|
|
# installation directory. With Nix however, the installation directory is
|
|
|
|
# not writable, so that won't work. So we change this so that it uses
|
|
|
|
# relative paths unconditionally, whether they exist or not.
|
|
|
|
./unconditional-relative-state-paths.patch
|
|
|
|
|
|
|
|
# We can't update the package at runtime with NixOS, so this patch makes
|
|
|
|
# the !update command mention that
|
|
|
|
./no-runtime-update.patch
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
# Fix passing of invalid "git" version into version.parse, which results
|
|
|
|
# in an InvalidVersion exception. The upstream fix is insufficient, so
|
|
|
|
# we carry the correct patch downstream for now.
|
|
|
|
./catch-invalid-versions.patch
|
2021-03-20 04:20:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# However, the function that's patched above is also used for
|
|
|
|
# configuration.default.ini, which is in the installation directory
|
|
|
|
# after all. So we need to counter-patch it here so it can find it absolutely
|
|
|
|
substituteInPlace mumbleBot.py \
|
2023-07-15 17:15:38 +00:00
|
|
|
--replace "configuration.default.ini" "$out/share/botamusique/configuration.default.ini" \
|
|
|
|
--replace "version = 'git'" "version = '${version}'"
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
NODE_OPTIONS = "--openssl-legacy-provider";
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper
|
2021-12-06 16:07:01 +00:00
|
|
|
nodejs
|
2023-05-24 13:37:59 +00:00
|
|
|
npmHooks.npmConfigHook
|
2021-12-06 16:07:01 +00:00
|
|
|
python3Packages.wrapPython
|
2021-03-20 04:20:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
pythonPath = with python3Packages; [
|
|
|
|
flask
|
2021-12-06 16:07:01 +00:00
|
|
|
magic
|
2021-03-20 04:20:00 +00:00
|
|
|
mutagen
|
2021-12-06 16:07:01 +00:00
|
|
|
packaging
|
2021-03-20 04:20:00 +00:00
|
|
|
pillow
|
2021-12-06 16:07:01 +00:00
|
|
|
pymumble
|
2021-03-20 04:20:00 +00:00
|
|
|
pyradios
|
2021-12-06 16:07:01 +00:00
|
|
|
requests
|
|
|
|
yt-dlp
|
2021-03-20 04:20:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
# Generates artifacts in ./static
|
|
|
|
(
|
|
|
|
cd web
|
|
|
|
npm run build
|
|
|
|
)
|
|
|
|
|
|
|
|
# Fills out http templates
|
|
|
|
${buildPython}/bin/python scripts/translate_templates.py --lang-dir lang/ --template-dir templates/
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/share $out/bin
|
|
|
|
cp -r . $out/share/botamusique
|
|
|
|
chmod +x $out/share/botamusique/mumbleBot.py
|
|
|
|
wrapPythonProgramsIn $out/share/botamusique "$out $pythonPath"
|
|
|
|
|
|
|
|
# Convenience binary and wrap with ffmpeg dependency
|
|
|
|
makeWrapper $out/share/botamusique/mumbleBot.py $out/bin/botamusique \
|
2024-01-13 08:15:51 +00:00
|
|
|
--prefix PATH : ${lib.makeBinPath [ ffmpeg-headless ]}
|
2021-03-20 04:20:00 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
passthru.updateScript = writeShellScript "botamusique-updater" ''
|
|
|
|
export PATH=${lib.makeBinPath [ coreutils curl nix-prefetch-git jq prefetch-npm-deps ]}
|
2021-12-06 16:07:01 +00:00
|
|
|
set -ex
|
|
|
|
|
|
|
|
OWNER=azlux
|
|
|
|
REPO=botamusique
|
2023-05-24 13:37:59 +00:00
|
|
|
VERSION="$(curl https://api.github.com/repos/$OWNER/$REPO/releases/latest | jq -r '.tag_name')"
|
2021-03-20 04:20:00 +00:00
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
nix-prefetch-git --rev "$VERSION" --url https://github.com/$OWNER/$REPO | \
|
2023-05-24 13:37:59 +00:00
|
|
|
jq > "${toString ./src.json}" \
|
2021-12-06 16:07:01 +00:00
|
|
|
--arg version "$VERSION" \
|
|
|
|
'.version |= $version'
|
2023-05-24 13:37:59 +00:00
|
|
|
path="$(jq '.path' -r < "${toString ./src.json}")"
|
2021-03-20 04:20:00 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
tmp="$(mktemp -d)"
|
2021-03-20 04:20:00 +00:00
|
|
|
trap 'rm -rf "$tmp"' exit
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
npmHash="$(prefetch-npm-deps $path/web/package-lock.json)"
|
|
|
|
jq '. + { npmDepsHash: "'"$npmHash"'" }' < "${toString ./src.json}" > "$tmp/src.json"
|
|
|
|
mv "$tmp/src.json" "${toString ./src.json}"
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
passthru.tests = {
|
|
|
|
inherit (nixosTests) botamusique;
|
|
|
|
};
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Bot to play youtube / soundcloud / radio / local music on Mumble";
|
|
|
|
homepage = "https://github.com/azlux/botamusique";
|
|
|
|
license = licenses.mit;
|
|
|
|
platforms = platforms.all;
|
|
|
|
maintainers = with maintainers; [ infinisil ];
|
2024-01-02 11:29:13 +00:00
|
|
|
mainProgram = "botamusique";
|
2021-03-20 04:20:00 +00:00
|
|
|
};
|
|
|
|
}
|