aciceri / nixfleet

A complete, declarative and reproducible configuration of my entire Nix fleet.
14 stars 0 forks source link

question about spotify-adblock #16

Closed NL-TCH closed 1 year ago

NL-TCH commented 1 year ago

Hey @aciceri i found your repository via the following issue: https://github.com/NixOS/nixpkgs/issues/209784

i copied your spotify folder (including default.nix and spotify-adblocked.nix) and refered to those via my configuration.nix:

imports =
    [
      ./spotify
    ];

but the build is failing, do you have any resolution or fix? i am quite new to the packaging and overriding of nix packages.

the nixos-rebuild switch log:

trying https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_64.snap
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   545  100   545    0     0   1154      0 --:--:-- --:--:-- --:--:--  1154
copying path '/nix/store/jwvnb6sb49vc7wv7l1x3a5swb98czv6m-wrap-gapps-hook' from 'https://cache.nixos.org'...
building '/nix/store/10rz0g8dkdv40dgkj40hsgq51qxvc1mm-set-environment.drv'...
building '/nix/store/4gc32bpkb9n62d0x0hj7z5fkbj5fs9hs-source.drv'...

trying https://github.com/dasj/spotifywm/archive/8624f539549973c124ed18753881045968881745.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2494    0  2494    0     0   2579      0 --:--:-- --:--:-- --:--:--  2579
unpacking source archive /build/8624f539549973c124ed18753881045968881745.tar.gz
building '/nix/store/lnm68frc0z3rddhpqandvzj2kbd7lrwq-etc-profile.drv'...
building '/nix/store/fj3lcxx78267p5mhkrcmaqd82ly68i7y-source.drv'...

trying https://github.com/abba23/spotify-adblock/archive/v1.0.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 32372    0 32372    0     0  25676      0 --:--:--  0:00:01 --:--:-- 25676
unpacking source archive /build/v1.0.2.tar.gz
building '/nix/store/g3mjn65npkb266ng9s47vbs91cxpgj3p-spotifywm.drv'...
unpacking sources
unpacking source archive /nix/store/9m6wlhrdmas4czlhm5wbya70br20s1d3-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/bash
g++ -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11 -DSONAME="spotifywm.so" -o spotifywm.so spotifywm.cpp
g++  -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11  spotifywm.cpp spotifywm.so   -o spotifywm
installing
/nix/store/5wdlffjhcr4i43sfajxcvx3lvnkryh5y-stdenv-linux/setup: line 1604: $'\r': command not found
error: builder for '/nix/store/g3mjn65npkb266ng9s47vbs91cxpgj3p-spotifywm.drv' failed with exit code 127;
       last 10 log lines:
       > source root is source
       > patching sources
       > configuring
       > no configure script, doing nothing
       > building
       > build flags: SHELL=/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/bash
       > g++ -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11 -DSONAME="spotifywm.so" -o spotifywm.so spotifywm.cpp
       > g++  -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11  spotifywm.cpp spotifywm.so   -o spotifywm
       > installing
       > /nix/store/5wdlffjhcr4i43sfajxcvx3lvnkryh5y-stdenv-linux/setup: line 1604: $'\r': command not found
       For full logs, run 'nix log /nix/store/g3mjn65npkb266ng9s47vbs91cxpgj3p-spotifywm.drv'.
error: 1 dependencies of derivation '/nix/store/bhya9m7xl13cqzmrjy537r4hv2kiv969-spotify-1.1.84.716.gc5f8b819.drv' failed to build
building '/nix/store/ml6w0y8kp1a7zv44a7rch4fnfr8wc6sz-system-generators.drv'...
error: 1 dependencies of derivation '/nix/store/391xlslm453srlv865zl94mjsnr1if4c-system-path.drv' failed to build
building '/nix/store/q2chnsjbx2pq3x6zazri7xm7yrvbis36-system-shutdown.drv'...
building '/nix/store/qixs4f184cws0dihy3g541wi59ksl4r7-unit-firewall.service.drv'...
error: 1 dependencies of derivation '/nix/store/mfisgvj955wpdd03chx7d8d8z1f0i12r-nixos-system-nixos-23.05.997.ddf4688dc7a.drv' failed to build
aciceri commented 1 year ago

Mmmm it builds for me, three things:

NL-TCH commented 1 year ago

hey, thanks for the fast answer! i indeed changed the home.packages to environment.systemPackages i have tried a lot of things and variations but the build keeps failing with the same error (used the packages spotifywm, used the sourcecode of the official winrm package in the nixrepo, applied your fix with installPhase = "mkdir -p $out/lib && cp spotifywm.so $out/lib/"; but it seems to keep failing.

really weird.

(also updated the snap spotify package and used a newer version of the official spotify pkgs nix source code)

thanks again for the help, but the error seems to be in the installphase which i have changed multiple times with multiple install phases.

i got more output, but the same error:

building '/nix/store/75b106lablhy8jg3b4ciwc9w972wl058-spotifywm.drv'...
unpacking sources
unpacking source archive /nix/store/9m6wlhrdmas4czlhm5wbya70br20s1d3-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/7q1b1bsmxi91zci6g8714rcljl620y7f-bash-5.2-p15/bin/bash
g++ -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11 -DSONAME="spotifywm.so" -o spotifywm.so spotifywm.cpp
g++  -Wall -Wextra -O3 -shared -fPIC -static-libgcc -lX11  spotifywm.cpp spotifywm.so   -o spotifywm
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/z8908a1ckyjzhrva1djliffmvm6gx8d6-spotifywm
shrinking /nix/store/z8908a1ckyjzhrva1djliffmvm6gx8d6-spotifywm/lib/spotifywm.so
checking for references to /build/ in /nix/store/z8908a1ckyjzhrva1djliffmvm6gx8d6-spotifywm...
patching script interpreter paths in /nix/store/z8908a1ckyjzhrva1djliffmvm6gx8d6-spotifywm
stripping (with command strip and flags -S -p) in  /nix/store/z8908a1ckyjzhrva1djliffmvm6gx8d6-spotifywm/lib
building '/nix/store/nag1k0aq4c54cxy29hdhll6fmr0jc6hg-spotify-1.2.11.916.geb595a67.drv'...
unpacking sources
/nix/store/5wdlffjhcr4i43sfajxcvx3lvnkryh5y-stdenv-linux/setup: line 1604: $'\r': command not found

or is the new error from the installphase of spotify-adblocked?

aciceri commented 1 year ago

This seems to be a new error, I mean, it's the same error but when building spotify-adblocked, spotify-wm was built this time. But are you on Darwin or not? Is it possible that your editor adds carriage returns (\r) in the installPhase string?

Have you also updated nixpkgs?

NL-TCH commented 1 year ago
  1. is the error in the install or unpack phase of spotify-adblock?
  2. i have not updated nixpkgs, is it needed, how?
NL-TCH commented 1 year ago

the logs state:

nix-store --read-log /nix/store/5vxs4s9nr3g7bpcifj5q25q723f1l1gn-spotify-1.1.84.716.gc5f8b819.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
/nix/store/5wdlffjhcr4i43sfajxcvx3lvnkryh5y-stdenv-linux/setup: line 1604: $'\r': command not found

i use vscode to edit the .nix files and i am using windows to edit, and a VM (with shared folders) to execute.

the unpack phase looks as following:

  unpackPhase = ''
    runHook preUnpack
    unsquashfs "$src" '/usr/share/spotify' '/usr/bin/spotify' '/meta/snap.yaml'
    cd squashfs-root
    if ! grep -q 'grade: stable' meta/snap.yaml; then
      # Unfortunately this check is not reliable: At the moment (2018-07-26) the
      # latest version in the "edge" channel is also marked as stable.
      echo "The snap package is marked as unstable:"
      grep 'grade: ' meta/snap.yaml
      echo "You probably chose the wrong revision."
      exit 1
    fi
    if ! grep -q '${version}' meta/snap.yaml; then
      echo "Package version differs from version found in snap metadata:"
      grep 'version: ' meta/snap.yaml
      echo "While the nix package specifies: ${version}."
      echo "You probably chose the wrong revision or forgot to update the nix version."
      exit 1
    fi
    runHook postUnpack
  '';
aciceri commented 1 year ago

If you use VScode from Windows I highly suspect that it's replacing carriage returns with newline in your sources when you save files. I had a similar problem in the past using VSCode with WSL on Windows.

is the error in the install or unpack phase of spotify-adblock?

Oh you are right, this time the error occurs during the unpack phase.

i have not updated nixpkgs, is it needed, how?

I'm quite sure that the reason is carriage returns. However it depends, if your configuration is a flake then you have nixpkgs between your inputs and you can update it with something like nix flake lock --update-input nixpkgs. Otherwise use if you are using channels the command should be nix-channel --update.

Try to do what they say here. You want to read LF, not CRLF.

NL-TCH commented 1 year ago

hahaha that was it, the linebreak from CRLF to LF did the job

wow it was a rabbithole into nix packaging but thank you so much for the time and effort!! do you have a 'buy me a coffee' link?

aciceri commented 1 year ago

Glad it worked! :rocket:

do you have a 'buy me a coffee' link?

I'm honored by the offer, it's the first that someone asks me this. I'm enabling sponsoring on GH just for you :smile: (I've no idea how it works, my request is pending now).

aciceri commented 1 year ago

PS: let me know if the adblocker really works, please

NL-TCH commented 1 year ago

will do, i was developing on a VM, i'll login once i reload on my laptop thanks again!

NL-TCH commented 1 year ago

spotify.zip i've got it working with the newest spotify version (1.2.11 instead of your 1.1.84)

when i start a playlist and skip around no ads appear so i think it is working (for now)

aciceri commented 1 year ago

Great! However while probably nixpkgs isn't the best place for this package it would be nice putting it in NUR in my opinion. If you ever make a PR tag me please. I'll do the same in case.

NL-TCH commented 1 year ago

https://github.com/nix-community/NUR/pull/574

https://github.com/NL-TCH/nur-packages

pullrequest is in progress, i'll keep you up to date

aciceri commented 1 year ago

Great job! If you want you could try to not copy/paste the derivation in spotify-adblocked.nix from nixpkgs but use the one from nixpkgs overriding the installPhase with overrideAttrs. It would be a little cleaner in my opinion, this way you will be able to update nixpkgs with nix flake lock --update-input nixpkgs and you would get the newer spotify version from nixpkgs. Obviously it's on you checking if your overrode installPhase still works with the newer Spotify derivation from nixpkgs.

aciceri commented 1 year ago

An even better thing would be creating a new entirely derivation that depends on the the upstream Spotify derivation from nixpkgs. This way you would take advantage of the official binary cache downloading the already built spotify and having to build just your "wrapped derivation".

I quickly tried both the approach IIRC but in the end they weren't as easy as what I did. Also I didn't have further time to spend on this.

NL-TCH commented 1 year ago

is this what you mean? i have it working via the NUR with the override function instead of the derivation

(see the readme:) https://github.com/NL-TCH/nur-packages

aciceri commented 1 year ago

Exactly! The only thing I find unsatisfactory is that you had to rewrite the installPhase entirely and are not using prev. Usually with overrideAttrs you do something like

spotify.overrideAttrs (old: {
  installPhase = old.installPhase + ''
    # appended stuff here
  '';
})

Or the opposite:

spotify.overrideAttrs (old: {
  installPhase = ''
    # prepended stuff here
  '' + old.installPhase;
})

Otherwise if something in the upstream installPhase is changed you have to check it by hand and copy/paste it again to your code. In this case, when I quickly did this, I couldn't find any way to avoid copy/pasting the entire installPhase.

I could use builtins.(match|split|replaceStrings) to change old.installPhase injecting what you need in the middle of the phase but it looked too hacky and flaky. At that point it was better copy/pasting it.

Alternatively, the best option in my opinion would be creating an entirely new derivation that depends on the upstream spotify patching it. As said above you would leverage on the official binary cache.

Something like:

pkgs.runCommand "spotify-wrapped" { } ''
  cp -rf ${pkgs.spotify} $out
  patchelf /bin/spotify --magic-arg ${pkgs.spotifywm}  # argument is invented
''
NL-TCH commented 1 year ago

thanks for the feedback, i get exactly what you mean but this is way above my skillset and understanding.nix for now i am happy with the result (just started a few days ago with nix-os and nix-pkgs). if you want to help me with code feel free to make a pullrequest.

thanks for your time and expertise!

aciceri commented 1 year ago

Don't worry, if you started a few days ago you already learned a lot of stuff. If I'll have time I'll make a PR, meanwhile I'm using your NUR package now.

PS: if you want to offer me a coffee now you can! It should be possible making a one time donation by an arbitrary amount from my GH profile clicking on "sponsor".

NL-TCH commented 1 year ago

thanks for using my repo, its an honor. and i am looking forward to merging your PR (ofcourse if you have time)

btw, sinds when did github stop paypal sponsoring?! i don't have a credit card. you can send me your paypaladdress via discord if you want (discordusername: nl_tch)

aciceri commented 1 year ago

Nooooo :sob: I really wanted to have a sponsor on GH. I didn't know it doesn't support PayPal :disappointed: I like the idea of a sponsor visible on my GH profile.

I've quickly checked some alternatives like liberapay, patreon and others but can't choose, so probably I will not choose. Don't worry about that and happy hacking with Nix. I don't use Discord often but you can reach me almost 24/7 on Matrix @aciceri:nixos.dev

PS: otherwise i can give you my Ethereum address, but it's better using L2s, otherwise it's more for fees than for the coffee itself@aciceri:nixos.dev