diff --git a/flake.lock b/flake.lock index b6be346..7d65f42 100644 --- a/flake.lock +++ b/flake.lock @@ -34,10 +34,28 @@ "type": "github" } }, + "nixpkgs-bitwig": { + "flake": false, + "locked": { + "lastModified": 1590662809, + "narHash": "sha256-ndfEQE1FpjlAGbFDBzena4Gri/KKYaZxrO+Cq14uvHI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e0c0c1f08328a932fcc69bdf14c509646fd912c4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e0c0c1f08328a932fcc69bdf14c509646fd912c4", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-bitwig": "nixpkgs-bitwig" } }, "systems": { diff --git a/flake.nix b/flake.nix index 319f47b..0789ff9 100644 --- a/flake.nix +++ b/flake.nix @@ -2,9 +2,13 @@ description = "dotfiles"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.nixpkgs-bitwig = { + url = "github:NixOS/nixpkgs/e0c0c1f08328a932fcc69bdf14c509646fd912c4"; + flake = false; + }; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, nixpkgs-bitwig, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let @@ -15,6 +19,13 @@ allowUnfree = true; }; }; + pkgs-bitwig = import nixpkgs-bitwig + { + system = system; + config = { + allowUnfree = true; + }; + }; in { packages.mopidyWithExtensions = pkgs.buildEnv { @@ -36,6 +47,13 @@ extraPkgs = with pkgs; [ glib which ]; }; + packages.bitwig-studio3 = pkgs-bitwig.callPackage ./nix/bitwig-studio3.nix { + bitwig-studio1 = pkgs-bitwig.callPackage ./nix/bitwig-studio1.nix { + zenity = pkgs-bitwig.gnome3.zenity; + libxkbcommon = pkgs-bitwig.libxkbcommon_7; + }; + }; + devShells = { empty = import ./dev-shells/empty.nix { pkgs = pkgs; }; empty-multi = import ./dev-shells/empty-multi.nix { pkgs = pkgs; }; diff --git a/nix/bitwig-studio1.nix b/nix/bitwig-studio1.nix new file mode 100644 index 0000000..7657a34 --- /dev/null +++ b/nix/bitwig-studio1.nix @@ -0,0 +1,98 @@ +{ stdenv, fetchurl, alsaLib, bzip2, cairo, dpkg, freetype, gdk-pixbuf +, wrapGAppsHook, gtk2, gtk3, harfbuzz, jdk, lib, xorg +, libbsd, libjack2, libpng, ffmpeg +, libxkbcommon +, makeWrapper, pixman, autoPatchelfHook +, xdg_utils, zenity, zlib }: + +stdenv.mkDerivation rec { + pname = "bitwig-studio"; + version = "1.3.16"; + + src = fetchurl { + url = "https://downloads.bitwig.com/stable/${version}/bitwig-studio-${version}.deb"; + sha256 = "0n0fxh9gnmilwskjcayvjsjfcs3fz9hn00wh7b3gg0cv3qqhich8"; + }; + + nativeBuildInputs = [ dpkg makeWrapper autoPatchelfHook wrapGAppsHook ]; + + unpackCmd = "mkdir root ; dpkg-deb -x $curSrc root"; + + dontBuild = true; + dontWrapGApps = true; # we only want $gappsWrapperArgs here + + buildInputs = with xorg; [ + alsaLib bzip2.out cairo freetype gdk-pixbuf gtk2 gtk3 harfbuzz libX11 libXau + libXcursor libXdmcp libXext libXfixes libXrender libbsd libjack2 libpng libxcb + libxkbfile pixman xcbutil xcbutilwm zlib + ]; + + binPath = lib.makeBinPath [ + xdg_utils zenity ffmpeg + ]; + + installPhase = '' + mkdir -p $out + cp -r opt/bitwig-studio $out/libexec + + # Use NixOS versions of these libs instead of the bundled ones. + ( + cd $out/libexec/lib/bitwig-studio + rm libbz2.so* libxkbfile.so* libXcursor.so* libXau.so* \ + libXdmcp.so* libpng16.so* libxcb*.so* libharfbuzz.so* \ + libcairo.so* libfreetype.so* + ln -s ${bzip2.out}/lib/libbz2.so.1.0.6 libbz2.so.1.0 + ) + + # Use our OpenJDK instead of Bitwig’s bundled—and commercial!—one. + rm -rf $out/libexec/lib/jre + ln -s ${jdk.home}/jre $out/libexec/lib/jre + + mkdir -p $out/bin + ln -s $out/libexec/bitwig-studio $out/bin/bitwig-studio + + cp -r usr/share $out/share + substitute usr/share/applications/bitwig-studio.desktop \ + $out/share/applications/bitwig-studio.desktop \ + --replace /usr/bin/bitwig-studio $out/bin/bitwig-studio + ''; + + postFixup = '' + # Bitwig’s `libx11-windowing-system.so` has several problems: + # + # • has some old version of libxkbcommon linked statically (ಠ_ಠ), + # + # • hardcodes path to `/usr/share/X11/xkb`, + # + # • even if we redirected it with libredirect (after adding + # `eaccess()` to libredirect!), their version of libxkbcommon + # is unable to parse our xkeyboardconfig. Been there, done that. + # + # However, it suffices to override theirs with our libxkbcommon + # in LD_PRELOAD. :-) + + find $out -type f -executable \ + -not -name '*.so.*' \ + -not -name '*.so' \ + -not -path '*/resources/*' | \ + while IFS= read -r f ; do + wrapProgram $f \ + --prefix PATH : "${binPath}" \ + "''${gappsWrapperArgs[@]}" \ + --set LD_PRELOAD "${libxkbcommon.out}/lib/libxkbcommon.so" || true + done + ''; + + meta = with lib; { + description = "A digital audio workstation"; + longDescription = '' + Bitwig Studio is a multi-platform music-creation system for + production, performance and DJing, with a focus on flexible + editing tools and a super-fast workflow. + ''; + homepage = "https://www.bitwig.com/"; + license = licenses.unfree; + platforms = [ "x86_64-linux" ]; + maintainers = with maintainers; [ michalrus mrVanDalo ]; + }; +} diff --git a/nix/bitwig-studio3.nix b/nix/bitwig-studio3.nix new file mode 100644 index 0000000..5913659 --- /dev/null +++ b/nix/bitwig-studio3.nix @@ -0,0 +1,23 @@ +{ fetchurl, bitwig-studio1, pulseaudio, xorg }: + +bitwig-studio1.overrideAttrs (oldAttrs: rec { + name = "bitwig-studio-${version}"; + version = "3.1.3"; + + src = fetchurl { + url = "https://downloads.bitwig.com/stable/${version}/bitwig-studio-${version}.deb"; + sha256 = "11z5flmp55ywgxyccj3pzhijhaggi42i2pvacg88kcpj0cin57vl"; + }; + + buildInputs = oldAttrs.buildInputs ++ [ xorg.libXtst ]; + + runtimeDependencies = [ pulseaudio ]; + + installPhase = '' + ${oldAttrs.installPhase} + + # recover commercial jre + rm -f $out/libexec/lib/jre + cp -r opt/bitwig-studio/lib/jre $out/libexec/lib + ''; +})