about summary refs log tree commit diff
path: root/pkgs/applications/audio/aaxtomp3
diff options
context:
space:
mode:
authorColin Arnott <colin@urandom.co.uk>2023-01-08 03:39:10 +0000
committerColin Arnott <colin@urandom.co.uk>2023-01-11 04:09:35 +0000
commit3cff1da83480ee70413ff2339d56ee9327fc58b1 (patch)
tree38b024b97124855ce9ed672ba2edfbad60463a17 /pkgs/applications/audio/aaxtomp3
parent71a885bf3ba24482a1c582033071a0fc9d71d6d7 (diff)
aaxtomp3: use resholve not PATH
Instead of wrapping out binary, we can patch the script to point
directly into /nix/store/. While doing this, we added a few dependencies
we missed and found an osh parsing bug that has been reported upstream.

See oilshell/oil#1446
Diffstat (limited to 'pkgs/applications/audio/aaxtomp3')
-rw-r--r--pkgs/applications/audio/aaxtomp3/default.nix72
-rw-r--r--pkgs/applications/audio/aaxtomp3/osh.patch15
2 files changed, 64 insertions, 23 deletions
diff --git a/pkgs/applications/audio/aaxtomp3/default.nix b/pkgs/applications/audio/aaxtomp3/default.nix
index 358dfce0d4f05..94fea0c8b9d14 100644
--- a/pkgs/applications/audio/aaxtomp3/default.nix
+++ b/pkgs/applications/audio/aaxtomp3/default.nix
@@ -1,31 +1,22 @@
-{ coreutils
+{ bash
+, bc
+, coreutils
 , fetchFromGitHub
 , ffmpeg
 , findutils
+, gawk
 , gnugrep
 , gnused
 , jq
 , lame
 , lib
-, makeWrapper
 , mediainfo
 , mp4v2
-, stdenv
+, ncurses
+, resholve
 }:
-let
-  runtimeInputs = [
-    coreutils
-    ffmpeg
-    findutils
-    gnugrep
-    gnused
-    jq
-    lame
-    mediainfo
-    mp4v2
-  ];
-in
-stdenv.mkDerivation rec {
+
+resholve.mkDerivation rec {
   pname = "aaxtomp3";
   version = "1.3";
 
@@ -36,17 +27,52 @@ stdenv.mkDerivation rec {
     hash = "sha256-7a9ZVvobWH/gPxa3cFiPL+vlu8h1Dxtcq0trm3HzlQg=";
   };
 
-  dontBuild = false;
+  # use whitespace to show osh arithmetic is not file redirection
+  # see: https://github.com/oilshell/oil/issues/1446
+  patches = [./osh.patch];
 
-  nativeBuildInputs = [ makeWrapper ];
+  postPatch = ''
+    substituteInPlace AAXtoMP3 \
+      --replace 'AAXtoMP3' 'aaxtomp3'
+    substituteInPlace interactiveAAXtoMP3 \
+      --replace 'AAXtoMP3' 'aaxtomp3' \
+      --replace 'call="./aaxtomp3"' 'call="$AAXTOMP3"'
+  '';
 
   installPhase = ''
-    install -Dm755 AAXtoMP3 $out/bin/aaxtomp3
-    wrapProgram $out/bin/aaxtomp3 --prefix PATH : ${lib.makeBinPath runtimeInputs}
-    install -Dm755 interactiveAAXtoMP3 $out/bin/interactiveaaxtomp3
-    wrapProgram $out/bin/interactiveaaxtomp3 --prefix PATH : ${lib.makeBinPath runtimeInputs}
+    install -Dm 755 AAXtoMP3 $out/bin/aaxtomp3
+    install -Dm 755 interactiveAAXtoMP3 $out/bin/interactiveaaxtomp3
   '';
 
+  solutions.default = {
+    scripts = [
+      "bin/aaxtomp3"
+      "bin/interactiveaaxtomp3"
+    ];
+    interpreter = "${bash}/bin/bash";
+    inputs = [
+      bc
+      coreutils
+      ffmpeg
+      findutils
+      gawk
+      gnugrep
+      gnused
+      jq
+      lame
+      mediainfo
+      mp4v2
+      ncurses
+    ];
+    keep."$call" = true;
+    fix = {
+      "$AAXTOMP3" = [ "${placeholder "out"}/bin/aaxtomp3" ];
+      "$FIND" = [ "find" ];
+      "$GREP" = [ "grep" ];
+      "$SED" = [ "sed" ];
+    };
+  };
+
   meta = with lib; {
     description = "Convert Audible's .aax filetype to MP3, FLAC, M4A, or OPUS";
     homepage = "https://krumpetpirate.github.io/AAXtoMP3";
diff --git a/pkgs/applications/audio/aaxtomp3/osh.patch b/pkgs/applications/audio/aaxtomp3/osh.patch
new file mode 100644
index 0000000000000..548486c7b1736
--- /dev/null
+++ b/pkgs/applications/audio/aaxtomp3/osh.patch
@@ -0,0 +1,15 @@
+diff --git a/AAXtoMP3 b/AAXtoMP3
+index 90566ad..71e94da 100755
+--- a/AAXtoMP3
++++ b/AAXtoMP3
+@@ -200,8 +200,8 @@ progressbar() {
+ 
+   #draw progressbar with one # for every 5% and blank spaces for the missing part.
+   progressbar=""
+-  for (( n=0; n<(percentage/5); n++ )) ; do progressbar="$progressbar#"; done
+-  for (( n=0; n<(20-(percentage/5)); n++ )) ; do progressbar="$progressbar "; done
++  for (( n=0; n< (percentage/5); n++ )) ; do progressbar="$progressbar#"; done
++  for (( n=0; n< (20-(percentage/5)); n++ )) ; do progressbar="$progressbar "; done
+ 
+   #print progressbar
+   echo -ne "Chapter splitting: |$progressbar| $print_percentage% ($part/$total chapters)\r"