anki: refactor

This commit is contained in:
Pavel Sobolev 2023-09-02 16:31:28 +03:00
parent 818441a0cf
commit aa2f2dd7df
No known key found for this signature in database
2 changed files with 39 additions and 32 deletions

View File

@ -1,10 +1,11 @@
{ lib { lib
, stdenv , stdenv
, buildEnv , buildEnv
, cargo
, fetchFromGitHub , fetchFromGitHub
, fetchYarnDeps , fetchYarnDeps
, fixup_yarn_lock , fixup_yarn_lock
, cargo
, installShellFiles , installShellFiles
, lame , lame
, mpv-unwrapped , mpv-unwrapped
@ -18,9 +19,10 @@
, rustPlatform , rustPlatform
, writeShellScriptBin , writeShellScriptBin
, yarn , yarn
, swift
, AVKit , AVKit
, CoreAudio , CoreAudio
, swift
}: }:
let let
@ -36,7 +38,6 @@ let
fetchSubmodules = true; fetchSubmodules = true;
}; };
cargoDeps = rustPlatform.importCargoLock { cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
outputHashes = { outputHashes = {
@ -46,6 +47,11 @@ let
}; };
}; };
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-66mYsHojQQBfLTHd12+/HEf7FKF5Y2RZRFeYRS2yZco=";
};
anki-build-python = python3.withPackages (ps: with ps; [ anki-build-python = python3.withPackages (ps: with ps; [
mypy-protobuf mypy-protobuf
]); ]);
@ -87,20 +93,16 @@ let
pathsToLink = [ "/bin" ]; pathsToLink = [ "/bin" ];
}; };
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-66mYsHojQQBfLTHd12+/HEf7FKF5Y2RZRFeYRS2yZco=";
};
# https://discourse.nixos.org/t/mkyarnpackage-lockfile-has-incorrect-entry/21586/3 # https://discourse.nixos.org/t/mkyarnpackage-lockfile-has-incorrect-entry/21586/3
anki-nodemodules = stdenv.mkDerivation { anki-nodemodules = stdenv.mkDerivation {
pname = "anki-nodemodules"; pname = "anki-nodemodules";
inherit version src yarnOfflineCache; inherit version src yarnOfflineCache;
nativeBuildInputs = [ nativeBuildInputs = [
fixup_yarn_lock fixup_yarn_lock
yarn
nodejs-slim nodejs-slim
yarn
]; ];
configurePhase = '' configurePhase = ''
@ -118,35 +120,37 @@ let
}; };
in in
python3.pkgs.buildPythonApplication { python3.pkgs.buildPythonApplication {
inherit pname version src; inherit pname version;
outputs = [ "out" "doc" "man" ]; outputs = [ "doc" "man" "out" ];
inherit src;
patches = [ patches = [
./patches/gl-fixup.patch ./patches/gl-fixup.patch
./patches/no-update-check.patch ./patches/no-update-check.patch
./patches/0001-Skip-formatting-python-code.patch ./patches/skip-formatting-python-code.patch
]; ];
inherit cargoDeps; inherit cargoDeps yarnOfflineCache;
nativeBuildInputs = [ nativeBuildInputs = [
fakeGit fakeGit
fixup_yarn_lock fixup_yarn_lock
offlineYarn offlineYarn
installShellFiles
cargo cargo
rustPlatform.cargoSetupHook installShellFiles
ninja ninja
qt6.wrapQtAppsHook qt6.wrapQtAppsHook
rsync rsync
rustPlatform.cargoSetupHook
] ++ lib.optional stdenv.isDarwin swift; ] ++ lib.optional stdenv.isDarwin swift;
nativeCheckInputs = with python3.pkgs; [ pytest mock astroid ];
buildInputs = [ buildInputs = [
qt6.qtbase qt6.qtbase
] ++ lib.optional stdenv.isLinux qt6.qtwayland; ] ++ lib.optional stdenv.isLinux qt6.qtwayland;
propagatedBuildInputs = with python3.pkgs; [ propagatedBuildInputs = with python3.pkgs; [
# This rather long list came from running: # This rather long list came from running:
# grep --no-filename -oE "^[^ =]*" python/{requirements.base.txt,requirements.bundle.txt,requirements.qt6_4.txt} | \ # grep --no-filename -oE "^[^ =]*" python/{requirements.base.txt,requirements.bundle.txt,requirements.qt6_4.txt} | \
@ -174,13 +178,13 @@ python3.pkgs.buildPythonApplication {
markupsafe markupsafe
orjson orjson
pep517 pep517
python3.pkgs.protobuf
pyparsing pyparsing
pyqt6 pyqt6
pyqt6-sip pyqt6-sip
pyqt6-webengine pyqt6-webengine
pyrsistent pyrsistent
pysocks pysocks
python3.pkgs.protobuf
requests requests
send2trash send2trash
six six
@ -194,23 +198,30 @@ python3.pkgs.buildPythonApplication {
CoreAudio CoreAudio
]; ];
# Activate optimizations nativeCheckInputs = with python3.pkgs; [ pytest mock astroid ];
RELEASE = true;
PROTOC_BINARY = lib.getExe protobuf; # tests fail with to many open files
NODE_BINARY = lib.getExe nodejs; # TODO: verify if this is still true (I can't, no mac)
YARN_BINARY = lib.getExe offlineYarn; doCheck = !stdenv.isDarwin;
PYTHON_BINARY = lib.getExe python3;
inherit yarnOfflineCache;
dontUseNinjaInstall = false; dontUseNinjaInstall = false;
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;
};
buildPhase = '' buildPhase = ''
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
export RUST_LOG=debug export RUST_LOG=debug
mkdir -p out/pylib/anki \ mkdir -p out/pylib/anki .git
.git
echo ${builtins.substring 0 8 rev} > out/buildhash echo ${builtins.substring 0 8 rev} > out/buildhash
touch out/env touch out/env
@ -228,9 +239,6 @@ python3.pkgs.buildPythonApplication {
PIP_USER=1 ./ninja build wheels PIP_USER=1 ./ninja build wheels
''; '';
# tests fail with to many open files
# TODO: verify if this is still true (I can't, no mac)
doCheck = !stdenv.isDarwin;
# mimic https://github.com/ankitects/anki/blob/76d8807315fcc2675e7fa44d9ddf3d4608efc487/build/ninja_gen/src/python.rs#L232-L250 # mimic https://github.com/ankitects/anki/blob/76d8807315fcc2675e7fa44d9ddf3d4608efc487/build/ninja_gen/src/python.rs#L232-L250
checkPhase = '' checkPhase = ''
HOME=$TMP ANKI_TEST_MODE=1 PYTHONPATH=$PYTHONPATH:$PWD/out/pylib \ HOME=$TMP ANKI_TEST_MODE=1 PYTHONPATH=$PYTHONPATH:$PWD/out/pylib \
@ -252,7 +260,6 @@ python3.pkgs.buildPythonApplication {
installManPage qt/bundle/lin/anki.1 installManPage qt/bundle/lin/anki.1
''; '';
dontWrapQtApps = true;
preFixup = '' preFixup = ''
makeWrapperArgs+=( makeWrapperArgs+=(
"''${qtWrapperArgs[@]}" "''${qtWrapperArgs[@]}"
@ -261,7 +268,6 @@ python3.pkgs.buildPythonApplication {
''; '';
meta = with lib; { meta = with lib; {
homepage = "https://apps.ankiweb.net/";
description = "Spaced repetition flashcard program"; description = "Spaced repetition flashcard program";
longDescription = '' longDescription = ''
Anki is a program which makes remembering things easy. Because it is a lot Anki is a program which makes remembering things easy. Because it is a lot
@ -275,9 +281,10 @@ python3.pkgs.buildPythonApplication {
people's names and faces, brushing up on geography, mastering long poems, people's names and faces, brushing up on geography, mastering long poems,
or even practicing guitar chords! or even practicing guitar chords!
''; '';
homepage = "https://apps.ankiweb.net";
license = licenses.agpl3Plus; license = licenses.agpl3Plus;
platforms = platforms.mesaPlatforms; platforms = platforms.mesaPlatforms;
maintainers = with maintainers; [ oxij euank ]; maintainers = with maintainers; [ euank oxij paveloom ];
# Reported to crash at launch on darwin (as of 2.1.65) # Reported to crash at launch on darwin (as of 2.1.65)
broken = stdenv.isDarwin; broken = stdenv.isDarwin;
}; };