0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2024-12-23 14:12:59 +03:00

Add support for NixOS

Additionally - fix some shellcheck warnings in repack.sh

Change-Id: I2cbc6516c54a4f4e4ecef817ed9fe90b0a460faa
This commit is contained in:
Yury Shvedov 2024-01-14 15:35:58 +03:00
parent bc6875ee33
commit d2b1fbf4aa
5 changed files with 223 additions and 34 deletions

View File

@ -11,3 +11,8 @@
## Самостоятельная сборка
Скачайте файл `repack.sh` и .exe файл клиента. Запустите скрипт с помощью `bash repack.sh <path_to_exe>`. В процессе выберите сборку для нужных архитектур (x64, arm64). Зависимости которые могут понадобиться: `nodejs`, `jq`, `npm`, `7z`, `npm asar`, `rpm-tools`
## NixOs
Запустите `nix run` в корне этого репозитория, чтобы запустить приложение. Так
же вы можете использовать поле `modules` из flake этого репозитория. Добавив его
в модули вашей системы, вы получите пакет `yandex_music` в коллекции pkgs.

29
default.nix Normal file
View File

@ -0,0 +1,29 @@
{ fetchurl
, runCommand
, writeShellApplication
, p7zip
, asar
, electron
, jq
, ymExe
}:
let
app = runCommand "yandex_music_app"
{
nativeBuildInputs = [ p7zip asar jq ];
repack = ./repack.sh;
src = ymExe;
} ''
bash "$repack" -xl "$src"
mv ./app "$out"
'';
in
writeShellApplication {
name = "yandex_music";
runtimeInputs = [ electron ];
text = ''
electron ${app}
'';
}

71
flake.lock Normal file
View File

@ -0,0 +1,71 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"id": "flake-utils",
"type": "indirect"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1704874635,
"narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"ymExe": "ymExe"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"ymExe": {
"flake": false,
"locked": {
"narHash": "sha256-9ANAW3/Cp/QAep36ax2EhjyB9Y6NrKyV1QgsHq5WPDs=",
"type": "file",
"url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.6.exe"
},
"original": {
"type": "file",
"url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.6.exe"
}
}
},
"root": "root",
"version": 7
}

35
flake.nix Normal file
View File

@ -0,0 +1,35 @@
{
description = "Native Yandex Music desktop client";
inputs = {
ymExe = {
url = https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.6.exe;
flake = false;
};
};
outputs = { self, ymExe, nixpkgs, flake-utils }:
let
yandex_music_with = pkgs: pkgs.callPackage ./. {
inherit ymExe;
};
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
in
{
packages = rec {
yandex_music = yandex_music_with pkgs;
default = yandex_music;
};
}
) // {
modules = [{
nixpkgs.overlays = [
(final: prev: {
yandex_music = yandex_music_with prev;
})
];
}];
};
}

117
repack.sh
View File

@ -1,10 +1,11 @@
#!/bin/bash
set -e
prompt_yes_no() {
local question="$1"
local response
while true; do
read -p "$question (y/n): " response
read -rp "$question (y/n): " response
case $response in
[Yy]*)
return 0 # Returning success status code
@ -19,12 +20,47 @@ prompt_yes_no() {
done
}
SCRIPTDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
usage() {
echo "Usage: $(basename "$0") [-xh] YANDEX_MUSIC_EXE"
echo
echo " Options:"
echo " -x Extract and fix only to ./app folder"
echo " -l Do not update license"
echo " -h Show this help and exit"
}
extract_only=
exe_location=
update_license=1
while getopts :xlh name; do
case $name in
x) extract_only=1 ;;
l) update_license= ;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if [ "$OPTIND" -le "$#" ]; then
shift "$(( OPTIND - 1))"
exe_location="$1"
fi
if [ -z "$exe_location" ]; then
echo "No exe file specified"
usage
exit 1
fi
# unpacking
exe_location=$1
7z x $exe_location -oExtracted
7z x "$exe_location" -oExtracted
cp "./Extracted/\$PLUGINSDIR/app-64.7z" "./app-64.7z"
rm -rf ./Extracted
7z x "./app-64.7z" -oExtracted
@ -34,21 +70,19 @@ rm ./app-64.7z
asar extract "./app.asar" "./app"
rm "./app.asar"
# managing npm dependencies
cd ./app
npm uninstall @yandex-chats/signer
npm uninstall electron-notarize
npm install @electron/notarize --save-dev
npm install --save-dev @electron-forge/cli
npx electron-forge import
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install jq to proceed." >&2
exit 1
if [ -z "$update_license" ]; then
# updating license
if ! command -v jq &>/dev/null; then
echo "Error: jq is not installed. Please install jq to proceed." >&2
exit 1
fi
jq --arg license "UNLICENSED" '. + {license: $license}' package.json > tmp_package.json
mv tmp_package.json package.json
echo "Updated license field in package.json"
version=$(jq -r .version package.json)
fi
jq --arg license "UNLICENSED" '. + {license: $license}' package.json > tmp_package.json
mv tmp_package.json package.json
echo "Updated license field in package.json"
version=$(jq -r .version package.json)
# fixing secretKey issue
echo "Fixing SecretKey"
@ -67,6 +101,17 @@ find "./" -type f -name "*.html" -print0 | while IFS= read -r -d $'\0' file; do
done
echo "Title Fixed"
if [ -n "$extract_only" ]; then
exit 0
fi
# managing npm dependencies
npm uninstall @yandex-chats/signer
npm uninstall electron-notarize
npm install @electron/notarize --save-dev
npm install --save-dev @electron-forge/cli
npx electron-forge import
# set some building parameters from config
forge_config="module.exports = {
packagerConfig: {
@ -105,49 +150,53 @@ forge_config="module.exports = {
};
"
echo Writing Forge Config...
echo $forge_config > ./forge.config.js
echo "$forge_config" > ./forge.config.js
build_x64=0
build_arm64=0
prompt_yes_no "Build for x64?"
build_x64=$?
if prompt_yes_no "Build for x64?"; then
build_x64=1
fi
prompt_yes_no "Build for arm64?"
build_arm64=$?
if prompt_yes_no "Build for arm64?"; then
build_arm64=1
fi
# building
if [ "$build_x64" -eq 0 ]; then
if [ "$build_x64" -eq 1 ]; then
npx electron-forge make --arch="x64"
fi
if [ "$build_arm64" -eq 0 ]; then
if [ "$build_arm64" -eq 1 ]; then
npx electron-forge make --arch="arm64"
fi
# moving packages and rename them
cd ../
mkdir out
if [ "$build_x64" -eq 0 ]; then
if [ "$build_x64" -eq 1 ]; then
debpath=$(find "./app/out/make/deb/x64/" -type f -print -quit)
rpmpath=$(find "./app/out/make/rpm/x64/" -type f -print -quit)
zippath=$(find "./app/out/make/zip/linux/x64/" -type f -print -quit)
newdeb="./out/yandexmusic.$version.x64.deb"
newrpm="./out/yandexmusic.$version.x64.rpm"
newzip="./out/yandexmusic.$version.x64.zip"
mv $debpath $newdeb
mv $rpmpath $newrpm
mv $zippath $newzip
mv "$debpath" "$newdeb"
mv "$rpmpath" "$newrpm"
mv "$zippath" "$newzip"
fi
if [ "$build_arm64" -eq 0 ]; then
if [ "$build_arm64" -eq 1 ]; then
debpath=$(find "./app/out/make/deb/arm64/" -type f -print -quit)
rpmpath=$(find "./app/out/make/rpm/arm64/" -type f -print -quit)
zippath=$(find "./app/out/make/zip/linux/arm64/" -type f -print -quit)
newdeb="./out/yandexmusic.$version.arm64.deb"
newrpm="./out/yandexmusic.$version.arm64.rpm"
newzip="./out/yandexmusic.$version.arm64.zip"
mv $debpath $newdeb
mv $rpmpath $newrpm
mv $zippath $newzip
mv "$debpath" "$newdeb"
mv "$rpmpath" "$newrpm"
mv "$zippath" "$newzip"
fi
rm -rf ./app
rm -rf ./app