-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
default.nix
104 lines (87 loc) · 2.44 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{ pkgs, lib, stdenv, fetchFromGitHub, fetchurl
, runtimeShell
, php82, php82Packages
, ffmpeg_5-headless, mp4v2, fdk_aac, fdk-aac-encoder
, useLibfdkFfmpeg ? false
}:
let
m4bToolPhp = php82.buildEnv {
extensions = ({ enabled, all }: enabled ++ (with all; [
dom mbstring tokenizer xmlwriter openssl
]));
extraConfig = ''
date.timezone = UTC
error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE & ~E_DEPRECATED
'';
};
m4bToolPhpPackages = php82Packages;
m4bToolComposer = pkgs.callPackage ./composer.nix {
php = m4bToolPhp;
phpPackages = m4bToolPhpPackages;
};
m4bToolFfmpeg = if useLibfdkFfmpeg then ffmpeg_5-headless.overrideAttrs (prev: rec {
configureFlags = prev.configureFlags ++ [
"--enable-libfdk-aac"
"--enable-nonfree"
];
buildInputs = prev.buildInputs ++ [
fdk_aac
];
}) else ffmpeg_5-headless;
in
m4bToolComposer.overrideAttrs (prev: rec {
pname = "m4b-tool";
version = "0.5";
buildInputs = [
m4bToolPhp m4bToolFfmpeg mp4v2 fdk-aac-encoder
];
nativeBuildInputs = [
m4bToolPhp m4bToolPhpPackages.composer
];
postInstall = ''
# Fix the version
sed -i 's!@package_version@!${version}!g' bin/m4b-tool.php
'';
postFixup = ''
# Wrap it
rm -rf $out/bin
mkdir -p $out/bin
# makeWrapper fails for this on macOS
cat >$out/bin/m4b-tool <<EOF
#!${runtimeShell}
export PATH=${lib.makeBinPath buildInputs}
export M4B_TOOL_DISABLE_TONE=true
exec ${m4bToolPhp}/bin/php $out/share/php/sandreas-m4b-tool/bin/m4b-tool.php "\$@"
EOF
chmod +x $out/bin/m4b-tool
'';
doInstallCheck = true;
installCheckPhase = let
exampleAudiobook = fetchurl {
name = "audiobook";
url = "https://archive.org/download/M4bCollectionOfLibrivoxAudiobooks/ArtOfWar-64kb.m4b";
sha256 = "00cvbk2a4iyswfmsblx2h9fcww2mvb4vnlf22gqgi1ldkw67b5w7";
};
in ''
# Run the unit test suite
php vendor/bin/phpunit tests
# Check that the audiobook split actually works
(
mkdir -p audiobook
cd audiobook
cp ${exampleAudiobook} audiobook.m4b
$out/bin/m4b-tool split -vvv -o . audiobook.m4b
if ! grep -q 'The Nine Situations' audiobook.chapters.txt; then
exit 1
fi
if [ ! -f '006-11 The Nine Situations.m4b' ]; then
exit 1
fi
)
rm -rf audiobook
'';
passthru = {
dependencies = buildInputs;
devDependencies = nativeBuildInputs;
};
})