diff --git a/README.md b/README.md index 23062ec..7365d8d 100644 --- a/README.md +++ b/README.md @@ -244,27 +244,24 @@ nix-build --expr '(import {}).callPackage ./nix {}' }; ``` -2. Import module in your `configuration.nix` or `home-manager.nix` - +2. Import module in your `configuration.nix`: ```nix imports = [ - yandex-music.nixosModule + yandex-music.nixosModules.default ]; ``` -3. Add package `yandex-music` + or in `home-manager.nix`: + ```nix + imports = [ + yandex-music.homeManagerModules.default + ]; + ``` - For `configuration.nix`: + +3. Enable `yandex-music` ```nix - environment.systemPackages = with pkgs; [ - yandex-music - ]; - ``` - For Home Manager: - - ```nix - home.packages = with pkgs; [ - yandex-music - ]; + programs.yandex-music.enable = true; + programs.yandex-music.tray.enable = true; # to enable tray support ``` diff --git a/build_tarball.sh b/build_tarball.sh index 2ef0874..f9be65e 100644 --- a/build_tarball.sh +++ b/build_tarball.sh @@ -34,7 +34,7 @@ build_tarball(){ install -Dm644 "${TEMPDIR}/app/favicon.png" "${app_dir}/usr/share/pixmaps/yandex-music.png" install -Dm644 "${TEMPDIR}/app/favicon.png" "${app_dir}/usr/share/icons/hicolor/48x48/apps/yandex-music.png" install -Dm644 "${TEMPDIR}/app/favicon.svg" "${app_dir}/usr/share/icons/hicolor/scalable/apps/yandex-music.svg" - + install -Dm644 "./templates/desktop" "${app_dir}/usr/share/applications/yandex-music.desktop" install -Dm644 "./templates/default.conf" "${app_dir}/usr/lib/yandex-music/default.conf" install -Dm644 "./LICENSE.md" "${app_dir}/usr/share/licenses/yandex-music/LICENSE" @@ -42,6 +42,7 @@ build_tarball(){ install -Dm755 "./templates/yandex-music.sh" "${app_dir}/usr/bin/yandex-music" sed -i "s|%electron_path%|/usr/lib/yandex-music/electron/electron|g" "${app_dir}/usr/bin/yandex-music" + sed -i "s|%asar_path%|/usr/lib/yandex-music/yandex-music.asar|g" "${app_dir}/usr/bin/yandex-music" cd "${app_dir}" tar -czf "${OUTPUT_DIR}/yandex-music_${version}_${arch}.tar.gz" * @@ -128,4 +129,4 @@ fi if [ ${arm64} -eq 1 ]; then download_electron_binary "arm64" build_tarball "arm64" -fi \ No newline at end of file +fi diff --git a/flake.nix b/flake.nix index 1b4ace6..f916e27 100644 --- a/flake.nix +++ b/flake.nix @@ -7,35 +7,33 @@ }; outputs = { self, ymExe, nixpkgs, flake-utils }: - let - yandex-music-with = pkgs: pkgs.callPackage ./nix { - inherit ymExe; - }; - in - flake-utils.lib.eachDefaultSystem - (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - packages = rec { - yandex-music = yandex-music-with pkgs; - yandex-music-noflakes = pkgs.callPackage ./nix {}; - default = yandex-music; - }; - } - ) // { - nixosModules = rec { - yandex-music = { - nixpkgs.overlays = [ - (final: prev: { - yandex-music = yandex-music-with prev; - }) - ]; + let + yandex-music-with = pkgs: pkgs.callPackage ./nix { + inherit ymExe; }; - default = yandex-music; - }; + modules = isHm: rec { + yandex-music = { + imports = [ (import ./nix/module.nix { inherit isHm yandex-music-with; }) ]; + }; + default = yandex-music; + }; + in + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + packages = rec { + yandex-music = yandex-music-with pkgs; + yandex-music-noflakes = pkgs.callPackage ./nix { }; + default = yandex-music; + }; + } + ) // { + nixosModules = modules false; + homeManagerModules = modules true; - nixosModule = self.nixosModules.default; - }; + nixosModule = self.nixosModules.default; + }; } diff --git a/nix/default.nix b/nix/default.nix index d1e66df..35363f9 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -10,6 +10,8 @@ , electron , ymExe ? null +, electronArguments ? "" +, trayEnabled ? false }: let version_info = with builtins; fromJSON (readFile ../utility/version_info.json); @@ -32,6 +34,7 @@ stdenvNoCC.mkDerivation utility = ./../utility; icons = ./../icons; desktopItem = ../templates/desktop; + ymScript = ../templates/yandex-music.sh; src = if ymExe != null then ymExe @@ -54,10 +57,17 @@ stdenvNoCC.mkDerivation mkdir -p "$out/share/nodejs" mv app/yandex-music.asar "$out/share/nodejs" - # use makeWrapper on electron binary to make it call our asar package - makeWrapper "${electron}/bin/electron" "$out/bin/yandex-music" \ - --add-flags "$out/share/nodejs/yandex-music.asar" \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland}}" + CONFIG_FILE="$out/share/yandex-music.conf" + echo "TRAY_ENABLED=${if trayEnabled then "1" else "0"}" >> "$CONFIG_FILE" + echo "ELECTRON_ARGS=\"${electronArguments}\"" >> "$CONFIG_FILE" + + + install -Dm755 "$ymScript" "$out/bin/yandex-music" + sed -i "s|%electron_path%|${electron}/bin/electron|g" "$out/bin/yandex-music" + sed -i "s|%asar_path%|$out/share/nodejs/yandex-music.asar|g" "$out/bin/yandex-music" + + wrapProgram "$out/bin/yandex-music" \ + --set-default YANDEX_MUSIC_CONFIG "$CONFIG_FILE" install -Dm644 "./app/favicon.png" "$out/share/pixmaps/yandex-music.png" install -Dm644 "./app/favicon.png" "$out/share/icons/hicolor/48x48/apps/yandex-music.png" diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..f81c461 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,53 @@ +{ yandex-music-with +, isHm ? false +}: +{ lib, pkgs, config, ... }: +let + cfg = config.programs.yandex-music; + +in +{ + imports = [{ + nixpkgs.overlays = [ + (final: prev: { + yandex-music = yandex-music-with prev; + }) + ]; + }]; + + options = { + programs.yandex-music = { + enable = lib.mkEnableOption "yandex music application"; + tray.enable = lib.mkEnableOption "tray icon for yandex music application"; + electronArguments = lib.mkOption { + description = "Extra electron arguments"; + example = "--no-sandbox --trace-warnings"; + type = lib.types.str; + default = ""; + }; + package = lib.mkOption { + description = "Finalized package of yandex music application"; + type = lib.types.package; + default = pkgs.yandex-music.override { + trayEnabled = cfg.tray.enable; + electronArguments = cfg.electronArguments; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable ( + if isHm then + { + home.packages = [ + cfg.package + ]; + } + else + { + environment.systemPackages = [ + cfg.package + ]; + } + ); +} diff --git a/templates/PKGBUILD b/templates/PKGBUILD index 9a9b308..537c2a4 100644 --- a/templates/PKGBUILD +++ b/templates/PKGBUILD @@ -36,4 +36,5 @@ package() { install -Dm755 "$srcdir/yandex-music-linux/templates/yandex-music.sh" "$pkgdir/usr/bin/yandex-music" sed -i "s|%electron_path%|/usr/bin/electron29|g" "$pkgdir/usr/bin/yandex-music" + sed -i "s|%asar_path%|/usr/lib/yandex-music/yandex-music.asar|g" "$pkgdir/usr/bin/yandex-music" } diff --git a/templates/yandex-music.sh b/templates/yandex-music.sh index 1107b6e..321263c 100644 --- a/templates/yandex-music.sh +++ b/templates/yandex-music.sh @@ -24,4 +24,4 @@ ELECTRON_BIN=${ELECTRON_CUSTOM_BIN:-%electron_path%} export TRAY_ENABLED=${TRAY_ENABLED:-0} -exec "${ELECTRON_BIN}" "/usr/lib/yandex-music/yandex-music.asar" $ELECTRON_ARGS $WAYLAND_FLAGS \ No newline at end of file +exec "${ELECTRON_BIN}" "%asar_path%" $ELECTRON_ARGS $WAYLAND_FLAGS