tpwrules / nixos-apple-silicon

Resources to install NixOS bare metal on Apple Silicon Macs
MIT License
743 stars 73 forks source link

Enable Widevine support #145

Open afilini opened 5 months ago

afilini commented 5 months ago

In case anybody is interested i threw together this quick nix shell to package arm64 widevine for nixos. This uses the great widevine-installer tool from AsahiLinux.

Unfortunately I don't have much time to work on a proper contribution to this project, so I figured I would just leave this here in case anybody wants to use it/take it and add it to this repo!

https://gist.github.com/afilini/7fb5624c850f39af4938f4a5d087f2dc

afilini commented 5 months ago

(Ideally I think this should be reworked into a nixpkgs pull req that uses widevine-installer on arm64 rather than downloading and extracting widevine from the .deb file like it currently does for x86)

bruhderek commented 5 months ago

@afilini Where do you put the script or how do you run it?

psanford commented 5 months ago

I turned this into an overlay if thats useful to anyone else: https://gist.github.com/psanford/1f70a0838c308d28478cf27a9b55c43d

I can confirm this works for me.

bruhderek commented 5 months ago

@psanford How? Did you cd into downloads and run nix-shell or something else? Also, what's the difference between your script and Afilini's?

psanford commented 5 months ago

You can run afilini's simply by running nix-shell shell.nix. You can add my overlay to your configuration.nix like so:

nixpkgs.overlays = [
 (import ./overlays/chromium-widevine-overlay.nix)
]

These are both pretty normal things in nix. I'd suggest you read the nix documentation for more details on how this works.

bruhderek commented 5 months ago

@psanford so the nix shell doesn’t work on its own?

cmacrae commented 5 months ago

@psanford so the nix shell doesn’t work on its own?

i'd take @psanford's advice on this:

These are both pretty normal things in nix. I'd suggest you read the nix documentation for more details on how this works.

bruhderek commented 5 months ago

@cmacrae I ran the nix shell, and nothing happened

3541 commented 5 months ago

This also works for Firefox by just setting MOZ_GMP_PATH to <widevine-path>/gmp-widevinecdm/system-installed, and adding the requisite preferences (https://github.com/AsahiLinux/widevine-installer/blob/main/conf/gmpwidevine.js).

Not sure of the best way to package this up, but I was able to make it work for myself by setting it in environment.sessionVariables and sticking the preferences in user.js.

diegobfernandez commented 5 months ago

@3541 I've added a comment to the overlay gist that shows how to modify it to include the preferences from widevine-installer without the need to set it in user.js.

TLMcNulty commented 3 months ago

To be clear about the steps:

I've created a file in a new directory, /etc/nixos/overlays, then per @psanford 's comment above, added:

nixpkgs.overlays = [
 (import ./overlays/chromium-widevine-overlay.nix)
]

To my configuration.nix, with the few changed lines from @diegobfernandez as I'd like to enable this for Firefox.

Running a sudo nixos-rebuild switch runs a lot of the widevine-installer installPhase logic, and I can see the MOZ_GMP_PATH set in my environment.

MOZ_GMP_PATH=/nix/store/7hdjbkwphkfxhv7s4k849j9172yyxdz0-widevine/gmp-widevinecdm/system-installed
> ls /nix/store/7hdjbkwphkfxhv7s4k849j9172yyxdz0-widevine/gmp-widevinecdm/system-installed 
libwidevinecdm.so  manifest.json

I don't have any seemingly relevant preferences in the about:preferences view in firefox, nor any GMP widevine type strings in about:config, and DRM type pages like Spotify's web player are still throwing widevine errors. I had some custom firefox confs loaded prior as I've been testing trying to get this working for a while, but checking at the moment it doesn't look like they're loaded, so I don't think my prior dirty conf is colliding.

Any of those that are more knowledgeable see anything wrong with my approach as described? Thanks.

I have previously run some of the widevine installation logic from the Asahi project. Perhaps that's messed up this overlay approach? https://gist.github.com/DavidBuchanan314/c6b97add51b97e4c3ee95dc890f9e3c8

epetousis commented 3 months ago

I turned this into a flake, I have published it in case this speeds up anyone's workflow at all: https://github.com/epetousis/nixos-aarch64-widevine

epetousis commented 3 months ago

I don't have any seemingly relevant preferences in the about:preferences view in firefox, nor any GMP widevine type strings in about:config

@TLMcNulty I believe this is standard behaviour since the profile has already been created, not 100% sure though. The widevine-installer repo has a .js file that is meant to define these preferences, but you can use them as a reference point for creating the options manually in about:config too: https://github.com/AsahiLinux/widevine-installer/blob/main/conf/gmpwidevine.js

TLMcNulty commented 3 months ago

I don't have any seemingly relevant preferences in the about:preferences view in firefox, nor any GMP widevine type strings in about:config

@TLMcNulty I believe this is standard behaviour since the profile has already been created, not 100% sure though. The widevine-installer repo has a .js file that is meant to define these preferences, but you can use them as a reference point for creating the options manually in about:config too: https://github.com/AsahiLinux/widevine-installer/blob/main/conf/gmpwidevine.js

Aye, that's what I understood. I included the logic I thought would put that in in the overlay, but don't see them loaded in firefox. The profile mention is a good one, I'll test that, and depending on whether or not that nets anything, test manually placing the prefs in.

TLMcNulty commented 3 months ago

Changing the profile did not auto-load anything. Manually defining the preferences listed in the gmpwidevine.js file DID allow streaming protected content in Spotify.

I don't know enough to troubleshoot the manual loading of the JS into Firefox prefs, but that doesn't matter so much to me now that it's working.

I also don't know if the manual fixup steps I ran prior, or the overlay is what put the conf onto the system correctly. If/when I rebuild from scratch I can tell. Either way, it's incredibly handy to have it in the DSL, as the configuration can now be safely stored.

I am in all of your debts, many blessings.