Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botamusique: init at unstable-2021-01-02 #112972

Merged
merged 3 commits into from Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 30 additions & 11 deletions pkgs/development/python-modules/pymumble/default.nix
@@ -1,31 +1,50 @@
{ buildPythonPackage,
fetchFromGitHub,
isPy27,
lib,
opuslib,
protobuf,
{ buildPythonPackage
, fetchFromGitHub
, fetchpatch
, isPy27
, lib
, opuslib
, protobuf
, pytestCheckHook
, pycrypto
}:

buildPythonPackage rec {
pname = "pymumble";
version = "0.3.1";
version = "1.6";
disabled = isPy27;

src = fetchFromGitHub {
owner = "azlux";
repo = "pymumble";
rev = "1dd6d6d4df2fdef33202f17e2acf3ba9678a5737";
sha256 = "1r1sch8xrpbzffsb72lhp5xjr3ac3xb599n44vsfmaam3xklz6vz";
rev = version;
sha256 = "04nc66d554a98mbmdgzgsg6ncaz0jsn4zdr3mr14w6wnhrxpjkrs";
};
patches = [
# Compatibility with pycryptodome (which is what our pycrypto really is)
# See https://github.com/azlux/pymumble/pull/99
(fetchpatch {
url = "https://github.com/azlux/pymumble/pull/99/commits/b85548a0e1deaac820954b1c0b308af214311a14.patch";
sha256 = "0w9dpc87rny6vmhi634pih1p97b67jm26qajscpa9wp6nphdlxlj";
})
];

postPatch = ''
# Changes all `library==x.y.z` statements to just `library`
# So that we aren't constrained to a specific version
sed -i 's/\(.*\)==.*/\1/' requirements.txt
infinisil marked this conversation as resolved.
Show resolved Hide resolved
'';

propagatedBuildInputs = [ opuslib protobuf ];

checkInputs = [ pytestCheckHook pycrypto ];

pythonImportsCheck = [ "pymumble_py3" ];

meta = with lib; {
description = "Python 3 version of pymumble, Mumble library used for multiple uses like making mumble bot.";
homepage = "https://github.com/azlux/pymumble";
license = licenses.gpl3;
maintainers = with maintainers; [ thelegy ];
license = licenses.gpl3Only;
maintainers = with maintainers; [ thelegy infinisil ];
};
}
24 changes: 24 additions & 0 deletions pkgs/development/python-modules/pyradios/default.nix
@@ -0,0 +1,24 @@
{ lib, buildPythonPackage, fetchPypi, appdirs, requests }:
buildPythonPackage rec {
pname = "pyradios";
version = "0.0.22";

src = fetchPypi {
inherit pname version;
sha256 = "1bgfb8vz7jybswss16pdzns0qpqfrwa9f2g8qrh1r4mig4xh2dmi";
};

propagatedBuildInputs = [
appdirs
requests
];

doCheck = false;

meta = with lib; {
description = "Python client for the https://api.radio-browser.info";
homepage = "https://github.com/andreztz/pyradios";
license = licenses.mit;
maintainers = with maintainers; [ infinisil ];
};
}
150 changes: 150 additions & 0 deletions pkgs/tools/audio/botamusique/default.nix
@@ -0,0 +1,150 @@
{ pkgs
, lib
, stdenv
, fetchFromGitHub
, python3Packages
, ffmpeg
, makeWrapper

# For the update script
, coreutils
, nix-prefetch-git
, jq
, nodePackages
}:
let
nodejs = pkgs.nodejs-12_x;
nodeEnv = import ../../../development/node-packages/node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
SuperSandro2000 marked this conversation as resolved.
Show resolved Hide resolved
};
botamusiqueNodePackages = import ./node-packages.nix {
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
};

srcJson = lib.importJSON ./src.json;
src = fetchFromGitHub {
owner = "azlux";
repo = "botamusique";
inherit (srcJson) rev sha256;
};

nodeDependencies = (botamusiqueNodePackages.shell.override (old: {
src = src + "/web";
})).nodeDependencies;

# Python needed to instantiate the html templates
buildPython = python3Packages.python.withPackages (ps: [ ps.jinja2 ]);
in
stdenv.mkDerivation rec {
pname = "botamusique";
version = "unstable-${lib.substring 0 10 srcJson.date}";

inherit src;

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
];

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 \
--replace "configuration.default.ini" "$out/share/botamusique/configuration.default.ini"
'';

nativeBuildInputs = [
python3Packages.wrapPython
nodejs
makeWrapper
];

pythonPath = with python3Packages; [
pymumble
packaging
magic
requests
youtube-dl
flask
mutagen
pillow
pyradios
];

buildPhase = ''
runHook preBuild

# Generates artifacts in ./static
(
cd web
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
export PATH="${nodeDependencies}/bin:$PATH"

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 \
--prefix PATH : ${lib.makeBinPath [ ffmpeg ]}

runHook postInstall
'';

passthru.updateScript = pkgs.writeShellScript "botamusique-updater" ''
export PATH=${lib.makeBinPath [ coreutils nix-prefetch-git jq nodePackages.node2nix ]}

nix-prefetch-git https://github.com/azlux/botamusique > ${toString ./src.json}
path=$(jq '.path' -r < ${toString ./src.json})

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' exit

# botamusique doesn't have a version in its package.json
# But that's needed for node2nix
jq < "$path"/web/package.json > "$tmp/package.json" \
--arg version "0.0.0" \
'.version |= $version'

node2nix \
--input "$tmp"/package.json \
--lock "$path"/web/package-lock.json \
--no-copy-node-env \
--development \
--composition /dev/null \
--output ${toString ./node-packages.nix}
'';

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 ];
};
}
12 changes: 12 additions & 0 deletions pkgs/tools/audio/botamusique/no-runtime-update.patch
@@ -0,0 +1,12 @@
diff --git a/util.py b/util.py
index bfec1ed..5147757 100644
--- a/util.py
+++ b/util.py
@@ -132,6 +132,7 @@ def check_update(current_version):


def update(current_version):
+ return "Can't update Nix installation at runtime"
global log

target = var.config.get('bot', 'target_version')