2023-03-14 12:15:18 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2023-09-02 13:31:28 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
, buildEnv
|
2023-09-02 13:31:28 +00:00
|
|
|
, cargo
|
2019-01-13 05:52:39 +00:00
|
|
|
, fetchFromGitHub
|
2023-03-14 12:15:18 +00:00
|
|
|
, fetchYarnDeps
|
|
|
|
, installShellFiles
|
2017-11-13 13:13:17 +00:00
|
|
|
, lame
|
2021-01-14 16:16:49 +00:00
|
|
|
, mpv-unwrapped
|
2023-03-14 12:15:18 +00:00
|
|
|
, ninja
|
|
|
|
, nodejs
|
|
|
|
, nodejs-slim
|
2023-11-22 22:05:09 +00:00
|
|
|
, prefetch-yarn-deps
|
2023-03-14 12:15:18 +00:00
|
|
|
, protobuf
|
|
|
|
, python3
|
|
|
|
, qt6
|
|
|
|
, rsync
|
|
|
|
, rustPlatform
|
|
|
|
, writeShellScriptBin
|
|
|
|
, yarn
|
2023-09-02 13:31:28 +00:00
|
|
|
|
2023-04-20 11:16:48 +00:00
|
|
|
, AVKit
|
2019-01-05 23:51:25 +00:00
|
|
|
, CoreAudio
|
2023-09-02 13:31:28 +00:00
|
|
|
, swift
|
2016-03-15 09:59:12 +00:00
|
|
|
}:
|
2013-01-04 03:48:47 +00:00
|
|
|
|
2019-01-13 05:52:39 +00:00
|
|
|
let
|
2023-03-14 12:15:18 +00:00
|
|
|
pname = "anki";
|
2023-11-01 11:50:18 +00:00
|
|
|
version = "23.10.1";
|
|
|
|
rev = "fac9e0ee1436ba5ac3366c72dd9394a6e692b1cf";
|
2023-03-14 12:15:18 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ankitects";
|
|
|
|
repo = "anki";
|
|
|
|
rev = version;
|
2023-11-01 11:50:18 +00:00
|
|
|
hash = "sha256-leGdamjCehffv2ByL7JWdaUhxRA4ZEPRKxBphUVzfRw=";
|
2023-03-14 12:15:18 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
cargoDeps = rustPlatform.importCargoLock {
|
|
|
|
lockFile = ./Cargo.lock;
|
|
|
|
outputHashes = {
|
2023-11-01 11:50:18 +00:00
|
|
|
"fsrs-0.1.0" = "sha256-bnLmJk2aaWBdgdsiasRrDG4NiTDMCDCXotCSoc0ldlk=";
|
2023-04-12 11:19:00 +00:00
|
|
|
"linkcheck-0.4.1" = "sha256-S93J1cDzMlzDjcvz/WABmv8CEC6x78E+f7nzhsN7NkE=";
|
|
|
|
"percent-encoding-iri-2.2.0" = "sha256-kCBeS1PNExyJd4jWfDfctxq6iTdAq69jtxFQgCCQ8kQ=";
|
2019-01-13 05:52:39 +00:00
|
|
|
};
|
2020-06-07 03:59:51 +00:00
|
|
|
};
|
2019-01-13 05:52:39 +00:00
|
|
|
|
2023-09-02 13:31:28 +00:00
|
|
|
yarnOfflineCache = fetchYarnDeps {
|
|
|
|
yarnLock = "${src}/yarn.lock";
|
2023-11-01 11:50:18 +00:00
|
|
|
hash = "sha256-ckpKxALSpZAu5xyBOYzMcNDQDfCMaYAtSGONHTCBhw4=";
|
2023-09-02 13:31:28 +00:00
|
|
|
};
|
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
anki-build-python = python3.withPackages (ps: with ps; [
|
|
|
|
mypy-protobuf
|
|
|
|
]);
|
|
|
|
|
|
|
|
# anki shells out to git to check its revision, and also to update submodules
|
|
|
|
# We don't actually need the submodules, so we stub that out
|
|
|
|
fakeGit = writeShellScriptBin "git" ''
|
|
|
|
case "$*" in
|
|
|
|
"rev-parse --short=8 HEAD")
|
|
|
|
echo ${builtins.substring 0 8 rev}
|
|
|
|
;;
|
|
|
|
*"submodule update "*)
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized git: $@"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
|
|
|
|
# We don't want to run pip-sync, it does network-io
|
|
|
|
fakePipSync = writeShellScriptBin "pip-sync" ''
|
|
|
|
exit 0
|
|
|
|
'';
|
|
|
|
|
|
|
|
offlineYarn = writeShellScriptBin "yarn" ''
|
|
|
|
[[ "$1" == "install" ]] && exit 0
|
|
|
|
exec ${yarn}/bin/yarn --offline "$@"
|
|
|
|
'';
|
|
|
|
|
|
|
|
pyEnv = buildEnv {
|
|
|
|
name = "anki-pyenv-${version}";
|
|
|
|
paths = with python3.pkgs; [
|
|
|
|
pip
|
|
|
|
fakePipSync
|
|
|
|
anki-build-python
|
2015-12-27 14:01:04 +00:00
|
|
|
];
|
2023-03-14 12:15:18 +00:00
|
|
|
pathsToLink = [ "/bin" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# https://discourse.nixos.org/t/mkyarnpackage-lockfile-has-incorrect-entry/21586/3
|
|
|
|
anki-nodemodules = stdenv.mkDerivation {
|
|
|
|
pname = "anki-nodemodules";
|
2023-09-02 13:31:28 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
inherit version src yarnOfflineCache;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
nodejs-slim
|
2023-11-22 22:05:09 +00:00
|
|
|
prefetch-yarn-deps
|
2023-09-02 13:31:28 +00:00
|
|
|
yarn
|
2023-03-14 12:15:18 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
export HOME=$NIX_BUILD_TOP
|
|
|
|
yarn config --offline set yarn-offline-mirror $yarnOfflineCache
|
2023-11-22 22:05:09 +00:00
|
|
|
fixup-yarn-lock yarn.lock
|
2023-03-14 12:15:18 +00:00
|
|
|
yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
|
|
|
|
patchShebangs node_modules/
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mv node_modules $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
python3.pkgs.buildPythonApplication {
|
2023-09-02 13:31:28 +00:00
|
|
|
inherit pname version;
|
2023-03-14 12:15:18 +00:00
|
|
|
|
2023-11-01 11:50:18 +00:00
|
|
|
outputs = [ "out" "doc" "man" ];
|
2023-09-02 13:31:28 +00:00
|
|
|
|
|
|
|
inherit src;
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
patches = [
|
2023-11-01 11:50:18 +00:00
|
|
|
./patches/disable-auto-update.patch
|
|
|
|
./patches/remove-the-gl-library-workaround.patch
|
2023-09-02 13:31:28 +00:00
|
|
|
./patches/skip-formatting-python-code.patch
|
2023-03-14 12:15:18 +00:00
|
|
|
];
|
|
|
|
|
2023-09-02 13:31:28 +00:00
|
|
|
inherit cargoDeps yarnOfflineCache;
|
2023-03-14 12:15:18 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
fakeGit
|
|
|
|
offlineYarn
|
2023-11-22 22:05:09 +00:00
|
|
|
prefetch-yarn-deps
|
2023-03-14 12:15:18 +00:00
|
|
|
|
2023-05-12 14:17:16 +00:00
|
|
|
cargo
|
2023-09-02 13:31:28 +00:00
|
|
|
installShellFiles
|
2023-03-14 12:15:18 +00:00
|
|
|
ninja
|
|
|
|
qt6.wrapQtAppsHook
|
|
|
|
rsync
|
2023-09-02 13:31:28 +00:00
|
|
|
rustPlatform.cargoSetupHook
|
2023-04-20 11:16:48 +00:00
|
|
|
] ++ lib.optional stdenv.isDarwin swift;
|
2023-03-14 12:15:18 +00:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
qt6.qtbase
|
2023-04-16 08:46:15 +00:00
|
|
|
] ++ lib.optional stdenv.isLinux qt6.qtwayland;
|
2023-09-02 13:31:28 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
propagatedBuildInputs = with python3.pkgs; [
|
|
|
|
# This rather long list came from running:
|
|
|
|
# grep --no-filename -oE "^[^ =]*" python/{requirements.base.txt,requirements.bundle.txt,requirements.qt6_4.txt} | \
|
|
|
|
# sort | uniq | grep -v "^#$"
|
|
|
|
# in their repo at the git tag for this version
|
|
|
|
# There's probably a more elegant way, but the above extracted all the
|
|
|
|
# names, without version numbers, of their python dependencies. The hope is
|
|
|
|
# that nixpkgs versions are "close enough"
|
|
|
|
# I then removed the ones the check phase failed on (pythonCatchConflictsPhase)
|
2020-06-07 03:59:51 +00:00
|
|
|
beautifulsoup4
|
2023-03-14 12:15:18 +00:00
|
|
|
certifi
|
|
|
|
charset-normalizer
|
|
|
|
click
|
|
|
|
colorama
|
2020-06-07 03:59:51 +00:00
|
|
|
decorator
|
2023-03-14 12:15:18 +00:00
|
|
|
distro
|
|
|
|
flask
|
|
|
|
flask-cors
|
|
|
|
idna
|
|
|
|
importlib-metadata
|
|
|
|
itsdangerous
|
|
|
|
jinja2
|
2020-06-07 03:59:51 +00:00
|
|
|
jsonschema
|
2023-03-14 12:15:18 +00:00
|
|
|
markdown
|
|
|
|
markupsafe
|
|
|
|
orjson
|
|
|
|
pep517
|
|
|
|
pyparsing
|
|
|
|
pyqt6
|
|
|
|
pyqt6-sip
|
|
|
|
pyqt6-webengine
|
|
|
|
pyrsistent
|
|
|
|
pysocks
|
2023-09-02 13:31:28 +00:00
|
|
|
python3.pkgs.protobuf
|
2023-03-14 12:15:18 +00:00
|
|
|
requests
|
|
|
|
send2trash
|
|
|
|
six
|
|
|
|
soupsieve
|
|
|
|
urllib3
|
|
|
|
waitress
|
|
|
|
werkzeug
|
|
|
|
zipp
|
2023-04-20 11:16:48 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
AVKit
|
|
|
|
CoreAudio
|
|
|
|
];
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-09-02 13:31:28 +00:00
|
|
|
nativeCheckInputs = with python3.pkgs; [ pytest mock astroid ];
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-09-02 13:31:28 +00:00
|
|
|
# tests fail with to many open files
|
|
|
|
# TODO: verify if this is still true (I can't, no mac)
|
|
|
|
doCheck = !stdenv.isDarwin;
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
dontUseNinjaInstall = false;
|
2023-09-02 13:31:28 +00:00
|
|
|
dontWrapQtApps = true;
|
|
|
|
|
|
|
|
env = {
|
|
|
|
# Activate optimizations
|
|
|
|
RELEASE = true;
|
|
|
|
|
|
|
|
NODE_BINARY = lib.getExe nodejs;
|
|
|
|
PROTOC_BINARY = lib.getExe protobuf;
|
|
|
|
PYTHON_BINARY = lib.getExe python3;
|
|
|
|
YARN_BINARY = lib.getExe offlineYarn;
|
|
|
|
};
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
buildPhase = ''
|
|
|
|
export RUST_BACKTRACE=1
|
|
|
|
export RUST_LOG=debug
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-09-02 13:31:28 +00:00
|
|
|
mkdir -p out/pylib/anki .git
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
echo ${builtins.substring 0 8 rev} > out/buildhash
|
|
|
|
touch out/env
|
|
|
|
touch .git/HEAD
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
ln -vsf ${pyEnv} ./out/pyenv
|
|
|
|
rsync --chmod +w -avP ${anki-nodemodules}/ out/node_modules/
|
|
|
|
ln -vsf out/node_modules node_modules
|
|
|
|
|
|
|
|
export HOME=$NIX_BUILD_TOP
|
|
|
|
yarn config --offline set yarn-offline-mirror $yarnOfflineCache
|
2023-11-22 22:05:09 +00:00
|
|
|
fixup-yarn-lock yarn.lock
|
2023-03-14 12:15:18 +00:00
|
|
|
|
|
|
|
patchShebangs ./ninja
|
|
|
|
PIP_USER=1 ./ninja build wheels
|
|
|
|
'';
|
2020-06-07 03:59:51 +00:00
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
# mimic https://github.com/ankitects/anki/blob/76d8807315fcc2675e7fa44d9ddf3d4608efc487/build/ninja_gen/src/python.rs#L232-L250
|
2020-06-07 03:59:51 +00:00
|
|
|
checkPhase = ''
|
2023-03-14 12:15:18 +00:00
|
|
|
HOME=$TMP ANKI_TEST_MODE=1 PYTHONPATH=$PYTHONPATH:$PWD/out/pylib \
|
|
|
|
pytest -p no:cacheprovider pylib/tests
|
|
|
|
HOME=$TMP ANKI_TEST_MODE=1 PYTHONPATH=$PYTHONPATH:$PWD/out/pylib:$PWD/pylib:$PWD/out/qt \
|
|
|
|
pytest -p no:cacheprovider qt/tests
|
2020-06-07 03:59:51 +00:00
|
|
|
'';
|
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
preInstall = ''
|
|
|
|
mkdir dist
|
|
|
|
mv out/wheels/* dist
|
2020-06-07 03:59:51 +00:00
|
|
|
'';
|
|
|
|
|
2023-03-14 12:15:18 +00:00
|
|
|
postInstall = ''
|
|
|
|
install -D -t $out/share/applications qt/bundle/lin/anki.desktop
|
|
|
|
install -D -t $doc/share/doc/anki README* LICENSE*
|
|
|
|
install -D -t $out/share/mime/packages qt/bundle/lin/anki.xml
|
|
|
|
install -D -t $out/share/pixmaps qt/bundle/lin/anki.{png,xpm}
|
|
|
|
installManPage qt/bundle/lin/anki.1
|
|
|
|
'';
|
2020-06-07 03:59:51 +00:00
|
|
|
|
|
|
|
preFixup = ''
|
|
|
|
makeWrapperArgs+=(
|
|
|
|
"''${qtWrapperArgs[@]}"
|
2021-01-14 16:16:49 +00:00
|
|
|
--prefix PATH ':' "${lame}/bin:${mpv-unwrapped}/bin"
|
2020-06-07 03:59:51 +00:00
|
|
|
)
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Spaced repetition flashcard program";
|
|
|
|
longDescription = ''
|
|
|
|
Anki is a program which makes remembering things easy. Because it is a lot
|
|
|
|
more efficient than traditional study methods, you can either greatly
|
|
|
|
decrease your time spent studying, or greatly increase the amount you learn.
|
|
|
|
|
|
|
|
Anyone who needs to remember things in their daily life can benefit from
|
|
|
|
Anki. Since it is content-agnostic and supports images, audio, videos and
|
|
|
|
scientific markup (via LaTeX), the possibilities are endless. For example:
|
|
|
|
learning a language, studying for medical and law exams, memorizing
|
|
|
|
people's names and faces, brushing up on geography, mastering long poems,
|
|
|
|
or even practicing guitar chords!
|
2019-12-10 23:23:57 +00:00
|
|
|
'';
|
2023-09-02 13:31:28 +00:00
|
|
|
homepage = "https://apps.ankiweb.net";
|
2020-06-07 03:59:51 +00:00
|
|
|
license = licenses.agpl3Plus;
|
|
|
|
platforms = platforms.mesaPlatforms;
|
2023-09-02 13:31:28 +00:00
|
|
|
maintainers = with maintainers; [ euank oxij paveloom ];
|
2023-08-29 13:13:34 +00:00
|
|
|
# Reported to crash at launch on darwin (as of 2.1.65)
|
|
|
|
broken = stdenv.isDarwin;
|
2020-06-07 03:59:51 +00:00
|
|
|
};
|
2013-01-04 03:48:47 +00:00
|
|
|
}
|