1{
2 fetchurl,
3 stdenv,
4 lib,
5 buildFHSEnv,
6 appimageTools,
7 writeShellScript,
8 anki,
9 undmg,
10 zstd,
11 cacert,
12 commandLineArgs ? [ ],
13}:
14
15let
16 pname = "anki-bin";
17 # Update hashes for both Linux and Darwin!
18 version = "25.02.5";
19
20 sources = {
21 linux = fetchurl {
22 url = "https://github.com/ankitects/anki/releases/download/${version}/anki-${version}-linux-qt6.tar.zst";
23 hash = "sha256-wYFqT1g+rtoqOR7+Bb5mIJLZ5JdT2M1kcHqJUCuNElA=";
24 };
25
26 # For some reason anki distributes completely separate dmg-files for the aarch64 version and the x86_64 version
27 darwin-x86_64 = fetchurl {
28 url = "https://github.com/ankitects/anki/releases/download/${version}/anki-${version}-mac-intel-qt6.dmg";
29 hash = "sha256-PDlu+oFKWHraPdTuGDCUkO0bhPtkNVibo11B1QkCICw=";
30 };
31 darwin-aarch64 = fetchurl {
32 url = "https://github.com/ankitects/anki/releases/download/${version}/anki-${version}-mac-apple-qt6.dmg";
33 hash = "sha256-RqcGHXN29GDGGuFbrQCBmj3cctzoRQZ8svR5hMYPhxs=";
34 };
35 };
36
37 unpacked = stdenv.mkDerivation {
38 inherit pname version;
39
40 nativeBuildInputs = [ zstd ];
41 src = sources.linux;
42
43 installPhase = ''
44 runHook preInstall
45
46 xdg-mime () {
47 echo Stubbed!
48 }
49 export -f xdg-mime
50
51 PREFIX=$out bash install.sh
52
53 runHook postInstall
54 '';
55 };
56
57 meta = with lib; {
58 inherit (anki.meta)
59 license
60 homepage
61 description
62 mainProgram
63 longDescription
64 ;
65 platforms = [
66 "x86_64-linux"
67 "x86_64-darwin"
68 "aarch64-darwin"
69 ];
70 maintainers = with maintainers; [
71 mahmoudk1000
72 cything
73 ];
74 };
75
76 passthru = {
77 inherit sources;
78 };
79
80 fhsEnvAnki = buildFHSEnv (
81 appimageTools.defaultFhsEnvArgs
82 // {
83 inherit pname version;
84
85 profile = ''
86 # anki vendors QT and mixing QT versions usually causes crashes
87 unset QT_PLUGIN_PATH
88 # anki uses the system ssl cert, without it plugins do not download/update
89 export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
90 '';
91
92 # Dependencies of anki
93 targetPkgs =
94 pkgs:
95 (with pkgs; [
96 xorg.libxkbfile
97 xorg.libxshmfence
98 xcb-util-cursor-HEAD
99 krb5
100 zstd
101 ]);
102
103 runScript = writeShellScript "anki-wrapper.sh" ''
104 exec ${unpacked}/bin/anki ${lib.strings.escapeShellArgs commandLineArgs} "$@"
105 '';
106
107 extraInstallCommands = ''
108 ln -s ${pname} $out/bin/anki
109
110 mkdir -p $out/share
111 cp -R ${unpacked}/share/applications \
112 ${unpacked}/share/man \
113 ${unpacked}/share/pixmaps \
114 $out/share/
115 '';
116
117 inherit meta passthru;
118 }
119 );
120in
121
122if stdenv.hostPlatform.isLinux then
123 fhsEnvAnki
124else
125 stdenv.mkDerivation {
126 inherit pname version passthru;
127
128 src = if stdenv.hostPlatform.isAarch64 then sources.darwin-aarch64 else sources.darwin-x86_64;
129
130 nativeBuildInputs = [ undmg ];
131 sourceRoot = ".";
132
133 installPhase = ''
134 mkdir -p $out/Applications/
135 cp -a Anki.app $out/Applications/
136 '';
137
138 inherit meta;
139 }