SpotX-Official / SpotX-Bash

SpotX Mac and Linux adblocker for the Spotify desktop client, in Bash
MIT License
1.7k stars 58 forks source link

Feature request: don't require write permissions (nixos) #38

Closed JohnFinn closed 2 months ago

JohnFinn commented 2 months ago

I guess instead of performing write operations on files, we could simply copy them and perform write operations on copies instead. This would enable the program to not require root access.

I believe the feature won't introduce any disk space overhead. (had a quick look at the code and there is already copy mechanism for backup and later uninstallation)

Also uninstallation process will potentially get simpler as it won't require any operations on the files we wrote something to.

jetfir3 commented 2 months ago

So you want the script to make a 1:1 copy of the entire Spotify app into a user-writable directory and then patch that instead? And then the user would run the Spotify installation from the new user directory location instead of the default location?

Or am I not understanding?

JohnFinn commented 2 months ago

Yes, that's what I meant

jetfir3 commented 2 months ago

The original intention of the script is to patch the stock Spotify client in its default location.

If a user doesn't want to grant write access to the default Spotify directories, the user could make their own copy of the Spotify app into a directory of their choice then point the script to that directory instead of the default locations, using the -P [path] option.

Would this not essentially do what you want?

cp -r $spotifyDirectory $HOME
spotX.sh -P $HOME/spotify
JohnFinn commented 2 months ago

Works, thanks

JohnFinn commented 2 months ago

Just discovered that in this setup if I delete the original spotify installation, the copy stops working

jetfir3 commented 2 months ago

Just discovered that in this setup if I delete the original spotify installation, the copy stops working

this doesn't seem like standard behavior, perhaps it may depend on your distro and Spotify setup.

Debian, Ubuntu and any APT-based distro with installs via official DEB do not require Spotify in the default location. Arch (and Arch-based distros) using spotify-launcher already has the client installed into $HOME. macOS can run the Spotify.app from any directory the user has access to.

Of course, once the copy is made, the Spotify binary would need to be run directly from the new copied location (or new symlinks made to point to that location).

I don't flatpak so can't speak on that.

JohnFinn commented 2 months ago

this doesn't seem like standard behavior, perhaps it may depend on your distro and Spotify setup.

I think so too. I use nixos, and it does a lot of stuff to isolate packages

jetfir3 commented 2 months ago

I use nixos, and it does a lot of stuff to isolate packages

Hmm, I see. Not familiar with nixos (just had to Google it). Seems that "easy-mode" would be to leave the original install in-place and deal with the loss of the additional ~200MB of space required for the original + copy (assuming the spotx-patched copy did indeed work after testing).

Just curious... What's the default install path for the Spotify client on nixos (specifically, where is xpui.spa located)? Is writing to the default install directory possible when write-permission is given?

I know SpotX-Bash works for both system and user-installed flatpaks but if the installs are more like "snaps" and create read-only containers which are mounted then obviously modifying those directories would not be possible without first unpacking.

JohnFinn commented 2 months ago

What's the default install path for the Spotify client on nixos (specifically, where is xpui.spa located)?

It is /nix/store/knd5h9pjd6f1a9l6lz8j62lxpdrr2419-spotify-1.2.25.1011.g0348b2ea/share/spotify/Apps

Is writing to the default install directory possible when write-permission is given?

Didn't check but even if it is, it doesn't seem like a proper way of working with nixos, since it would break the very feature of reproducibility nix is trying to achieve

oskardotglobal commented 1 month ago

A very dirty fix for this problem: You can override the installation script inside the spotify nix package to call the spotx installation script just before the postinstall hook. This is not really the nix way, but it seems to work.

In your configuration.nix:

nixpkgs.overlays = [
  (final: prev: {
    spotify =
      prev.spotify
      // {
        installPhase =
          builtins.replaceStrings [
            "runHook postInstall"
            ''
              bash <(curl -sSL https://spotx-official.github.io/run.sh) -P "$out/share/spotify"
              runHook postInstall
            ''
          ]
          prev.spotify.installPhase;
      };
  })
];