diff --git a/flake.lock b/flake.lock index 14e3cb3..a0cc932 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,27 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1783102699, + "narHash": "sha256-7inE9/GtbWf3MkV6wj2lRr0RixOpWBZboAKTPAnRDxY=", + "owner": "ipetkov", + "repo": "crane", + "rev": "7605d0ca1a69331596d4ec0f2577fc566d17b3ad", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1780749050, - "narHash": "sha256-3av0pIjlOWQ6rDbNOmpUSvbNnJkGORQKKjb4LtCZsIY=", + "lastModified": 1782959384, + "narHash": "sha256-xnJJk+ct+D2+wdRxj1wk36w5zV9RVESwRqcklPdt3fM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a799d3e3886da994fa307f817a6bc705ae538eeb", + "rev": "65179426c83bb3f6bc14898b42ea1c6f01d374b0", "type": "github" }, "original": { @@ -18,6 +33,7 @@ }, "root": { "inputs": { + "crane": "crane", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 0535b04..675d11b 100644 --- a/flake.nix +++ b/flake.nix @@ -3,30 +3,52 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + crane.url = "github:ipetkov/crane"; }; outputs = { self, nixpkgs, + crane, }: let - # Spotify only ships on this so it's fine - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - config.allowUnfree = true; - }; + systems = [ + "x86_64-linux" + "aarch64-darwin" + ]; + forEachSystem = nixpkgs.lib.genAttrs systems; + pkgsForSystem = system: + import nixpkgs { + inherit system; + config.allowUnfree = true; + }; in { - devShells.${system} = { - default = pkgs.callPackage ./nix/shell.nix {inherit self;}; - }; + devShells = forEachSystem (system: { + default = (pkgsForSystem system).callPackage ./nix/shell.nix { + inherit self; + }; + }); - packages.${system} = { - cef = pkgs.callPackage ./nix/cef.nix {}; - extendify-native = pkgs.callPackage ./nix/native.nix {inherit self;}; - spotify-extendify = pkgs.callPackage ./nix/spotify-extendify.nix {inherit self;}; - default = self.packages.${system}.spotify-extendify; - }; + packages = forEachSystem ( + system: let + pkgs = pkgsForSystem system; + craneLib = crane.mkLib pkgs; + in { + cef = pkgs.callPackage ./nix/cef.nix {}; + extendify-native = pkgs.callPackage ./nix/native.nix { + inherit self craneLib; + }; + spotify-extendify = pkgs.callPackage ./nix/spotify-extendify.nix { + inherit self; + }; + default = self.packages.${system}.spotify-extendify; + } + ); - formatter.${system} = pkgs.callPackage ./nix/fmt.nix {}; + formatter = forEachSystem ( + system: let + pkgs = pkgsForSystem system; + in + pkgs.callPackage ./nix/fmt.nix {} + ); }; } diff --git a/nix/cef.nix b/nix/cef.nix index 2e84727..0f8f0e8 100644 --- a/nix/cef.nix +++ b/nix/cef.nix @@ -1,10 +1,50 @@ { cef-binary, + fetchurl, stdenv, -}: -cef-binary.override { + stdenvNoCC, +}: let + selectSystem = attrs: + attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system ${stdenv.hostPlatform.system}"); + + platformString = selectSystem { + x86_64-linux = "linux64"; + aarch64-darwin = "macosarm64"; + }; + version = "144.0.11"; gitRevision = "e135be2"; chromiumVersion = "144.0.7559.97"; - srcHashes.${stdenv.hostPlatform.system} = "sha256-almKJ18g//Wi2CDRX1yibODvR6TF0DlUl1EnDNlIHBY="; -} + srcHashes = { + x86_64-linux = "sha256-almKJ18g//Wi2CDRX1yibODvR6TF0DlUl1EnDNlIHBY="; + aarch64-darwin = "sha256-Q94fht0yAkwAIqv29I1ZkpaS7WiYvJIcHWFcmBSvqHw="; + }; +in + if stdenv.hostPlatform.isLinux + then + cef-binary.override { + inherit version gitRevision chromiumVersion srcHashes; + } + else if stdenv.hostPlatform.system == "aarch64-darwin" + then + stdenvNoCC.mkDerivation { + name = "darwin-cef"; + + src = fetchurl { + url = "https://cef-builds.spotifycdn.com/cef_binary_${version}+g${gitRevision}+chromium-${chromiumVersion}_${platformString}_minimal.tar.bz2"; + hash = srcHashes.${stdenv.hostPlatform.system}; + }; + + dontBuild = true; + dontConfigure = true; + + unpackPhase = '' + tar --strip-components=1 -xjf $src + ''; + + installPhase = '' + mkdir -p $out + cp -r ./* $out/ + ''; + } + else throw "Unsupported system: ${stdenv.hostPlatform.system}" diff --git a/nix/native.nix b/nix/native.nix index 2ece199..e23ade6 100644 --- a/nix/native.nix +++ b/nix/native.nix @@ -1,5 +1,4 @@ { - rustPlatform, clang, pkg-config, openssl, @@ -7,44 +6,58 @@ lib, self, stdenv, -}: -rustPlatform.buildRustPackage { - pname = "extendify-native"; - version = (lib.importTOML ../crates/extendify-native/Cargo.toml).package.version; + craneLib, +}: let + commonArgs = { + pname = "extendify-native"; + version = (lib.importTOML ../crates/extendify-native/Cargo.toml).package.version; + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + ../crates + ../Cargo.lock + ../Cargo.toml + ]; + }; - src = lib.fileset.toSource { - root = ../.; - fileset = lib.fileset.unions [ - ../crates - ../Cargo.lock - ../Cargo.toml + strictDeps = true; + + nativeBuildInputs = [ + clang + pkg-config ]; - }; - cargoLock = { - lockFile = ../Cargo.lock; - allowBuiltinFetchGit = true; + buildInputs = [ + openssl + ]; }; - nativeBuildInputs = [ - clang - pkg-config - ]; + cargoArtifacts = craneLib.buildDepsOnly ( + commonArgs + // { + name = "${commonArgs.pname}-deps"; + } + ); +in + craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; - buildInputs = [ - openssl - ]; + env = { + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; + CEF_PATH = self.packages.${stdenv.hostPlatform.system}.cef; + }; - env = { - LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; - CEF_PATH = self.packages.${stdenv.hostPlatform.system}.cef; - }; - - meta = { - homepage = "https://github.com/extendify-mod/extendify"; - # wtf is the license - # license = lib.licenses.gpl3; - maintainers = [lib.maintainers.fazzi]; - platforms = ["x86_64-linux"]; - }; -} + meta = { + homepage = "https://github.com/extendify-mod/extendify"; + # wtf is the license + # license = lib.licenses.gpl3; + maintainers = [lib.maintainers.fazzi]; + platforms = [ + "x86_64-linux" + "aarch64-darwin" + ]; + }; + } + ) diff --git a/nix/spotify-extendify.nix b/nix/spotify-extendify.nix index c9b0bcc..fbeee5a 100644 --- a/nix/spotify-extendify.nix +++ b/nix/spotify-extendify.nix @@ -5,30 +5,42 @@ makeWrapper, self, lib, -}: -symlinkJoin { - name = "spotify-extendify"; - inherit (spotify) version; +}: let + exe = + if stdenv.isDarwin + then "Applications/Spotify.app/MacOS/Spotify" + else "bin/spotify"; + preloadVar = + if stdenv.isDarwin + then "DYLD_INSERT_LIBRARIES" + else "LD_PRELOAD"; +in + symlinkJoin { + name = "spotify-extendify"; + inherit (spotify) version; - paths = [ - spotify - self.packages.${stdenv.hostPlatform.system}.extendify-native - ]; + paths = [ + spotify + self.packages.${stdenv.hostPlatform.system}.extendify-native + ]; - buildInputs = [makeWrapper]; + buildInputs = [makeWrapper]; - postBuild = '' - wrapProgram $out/bin/spotify \ - --set LD_PRELOAD $out/lib/libextendify_native.so - ''; + postBuild = '' + wrapProgram $out/${exe} \ + --set ${preloadVar} $out/lib/libextendify_native.so + ''; - meta = { - mainProgram = "spotify"; - description = spotify.meta.description + "(patched with Extendify)"; - homepage = "https://github.com/extendify-mod/extendify"; - # wtf is the license - # license = lib.licenses.gpl3; - maintainers = [lib.maintainers.fazzi]; - platforms = ["x86_64-linux"]; - }; -} + meta = { + mainProgram = "spotify"; + description = spotify.meta.description + "(patched with Extendify)"; + homepage = "https://github.com/extendify-mod/extendify"; + # wtf is the license + # license = lib.licenses.gpl3; + maintainers = [lib.maintainers.fazzi]; + platforms = [ + "x86_64-linux" + "aarch64-darwin" + ]; + }; + }