@@ -0,0 +1,200 @@
1+{ lib, stdenv, curl, gnugrep, jq, xorg, alsa-lib, freetype, p7zip, autoPatchelfHook, writeShellScript, zlib, libjack2, makeWrapper }:
3+ versionForFile = v: builtins.replaceStrings ["."] [""] v;
5+ mkPianoteq = { name, src, version, archdir, ... }:
6+ stdenv.mkDerivation rec {
9+ pname = "pianoteq-${name}";
12+ ${p7zip}/bin/7z x $src
15+ nativeBuildInputs = [
22+ xorg.libX11 # libX11.so.6
23+ xorg.libXext # libXext.so.6
24+ alsa-lib # libasound.so.2
25+ freetype # libfreetype.so.6
30+ mv -t $out/bin Pianoteq*/${archdir}/*
31+ for f in $out/bin/Pianoteq*; do
32+ if [ -x "$f" ] && [ -f "$f" ]; then
33+ wrapProgram "$f" --prefix LD_LIBRARY_PATH : ${
34+ lib.makeLibraryPath (buildInputs ++ [
47+ homepage = "https://www.modartt.com/pianoteq";
48+ description = "Software synthesizer that features real-time MIDI-control of digital physically modeled pianos and related instruments";
49+ license = licenses.unfree;
50+ platforms = [ "x86_64-linux" ]; # TODO extract binary according to each platform?
51+ maintainers = [ maintainers.mausch ];
55+ fetchWithCurlScript = { name, sha256, script, impureEnvVars ? [] }:
56+ stdenv.mkDerivation {
58+ builder = writeShellScript "builder.sh" ''
61+ curlVersion=$(${curl}/bin/curl -V | head -1 | cut -d' ' -f2)
63+ # Curl flags to handle redirects, not use EPSV, handle cookies for
64+ # servers to need them during redirects, and work on SSL without a
65+ # certificate (this isn't a security problem because we check the
66+ # cryptographic hash of the output anyway).
75+ --user-agent "curl/$curlVersion Nixpkgs/${lib.trivial.release}"
82+ nativeBuildInputs = [ curl ];
83+ outputHashAlgo = "sha256";
86+ impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ impureEnvVars ++ [
87+ # This variable allows the user to pass additional options to curl
92+ fetchPianoteqTrial = { name, sha256 }:
93+ fetchWithCurlScript {
96+ "''${curl[@]}" --silent --request POST \
98+ --header "modartt-json: request" \
99+ --header "origin: https://www.modartt.com" \
100+ --header "content-type: application/json; charset=UTF-8" \
101+ --header "accept: application/json, text/javascript, */*" \
102+ --data-raw '{"file": "${name}", "get": "url"}' \
103+ https://www.modartt.com/json/download -o /dev/null
105+ "''${curl[@]}" --silent --request POST \
107+ --header "modartt-json: request" \
108+ --header "origin: https://www.modartt.com" \
109+ --header "content-type: application/json; charset=UTF-8" \
110+ --header "accept: application/json, text/javascript, */*" \
111+ --data-raw '{"file": "${name}", "get": "url"}' \
112+ https://www.modartt.com/json/download
114+ url=$(echo $json | ${jq}/bin/jq -r .url)
115+ "''${curl[@]}" --progress-bar --cookie cookies -o $out "$url"
119+ fetchPianoteqWithLogin = { name, sha256 }:
120+ fetchWithCurlScript {
121+ inherit name sha256;
123+ impureEnvVars = [ "NIX_MODARTT_USERNAME" "NIX_MODARTT_PASSWORD" ];
126+ if [ -z "''${NIX_MODARTT_USERNAME}" -o -z "''${NIX_MODARTT_PASSWORD}" ]; then
127+ echo "Error: Downloading a personal Pianoteq instance requires the nix building process (nix-daemon in multi user mode) to have the NIX_MODARTT_USERNAME and NIX_MODARTT_PASSWORD env vars set." >&2
131+ "''${curl[@]}" -s -o /dev/null "https://www.modartt.com/user_area"
133+ ${jq}/bin/jq -n "{connect: 1, login: \"''${NIX_MODARTT_USERNAME}\", password: \"''${NIX_MODARTT_PASSWORD}\"}" > login.json
135+ "''${curl[@]}" --silent --request POST \
137+ --referer "https://www.modartt.com/user_area" \
138+ --header "modartt-json: request" \
139+ --header "origin: https://www.modartt.com" \
140+ --header "content-type: application/json; charset=UTF-8" \
141+ --header "accept: application/json, text/javascript, */*" \
142+ --data @login.json \
143+ https://www.modartt.com/json/session
146+ "''${curl[@]}" --silent --request POST \
148+ --header "modartt-json: request" \
149+ --header "origin: https://www.modartt.com" \
150+ --header "content-type: application/json; charset=UTF-8" \
151+ --header "accept: application/json, text/javascript, */*" \
152+ --data-raw '{"file": "${name}", "get": "url"}' \
153+ https://www.modartt.com/json/download
155+ url=$(echo $json | ${jq}/bin/jq -r .url)
157+ "''${curl[@]}" --progress-bar --cookie cookies -o $out "$url"
162+ # TODO currently can't install more than one because `lame` clashes
163+ stage-trial = mkPianoteq rec {
164+ name = "stage-trial";
166+ archdir = "x86-64bit";
167+ src = fetchPianoteqTrial {
168+ name = "pianoteq_stage_linux_trial_v${versionForFile version}.7z";
169+ sha256 = "12zbr54ng7cb4ngl1qrf5h0gs8c42d6d3j08492xr14m9x9y132k";
172+ standard-trial = mkPianoteq rec {
173+ name = "standard-trial";
175+ archdir = "x86-64bit";
176+ src = fetchPianoteqTrial {
177+ name = "pianoteq_linux_trial_v${versionForFile version}.7z";
178+ sha256 = "04sh45hm3y3y6kfj3p32fi6p95r9fc6xf4r5i74laylms4f6gr6d";
181+ stage-6 = mkPianoteq rec {
185+ src = fetchPianoteqWithLogin {
186+ name = "pianoteq_stage_linux_v${versionForFile version}.7z";
187+ sha256 = "0jy0hkdynhwv0zhrqkby0hdphgmcc09wxmy74rhg9afm1pzl91jy";
190+ stage-7 = mkPianoteq rec {
193+ archdir = "x86-64bit";
194+ src = fetchPianoteqWithLogin {
195+ name = "pianoteq_stage_linux_v${versionForFile version}.7z";
196+ sha256 = "05w7sv9v38r6ljz9xai816w5z2qqwx88hcfjm241fvgbs54125hx";
199+ # TODO other paid binaries, I don't own that so I don't know their hash.