Merge pull request #224366 from martinetd/ankisyncd-rs

ankisyncd-rs: add package for anki-sync-server-rs
This commit is contained in:
Atemu 2023-07-04 18:03:19 +02:00 committed by GitHub
commit 712caf8eb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 4059 additions and 76 deletions

View file

@ -84,6 +84,10 @@
- `services.fail2ban.jails` can now be configured with attribute sets defining settings and filters instead of lines. The stringed options `daemonConfig` and `extraSettings` have respectively been replaced by `daemonSettings` and `jails.DEFAULT.settings` which use attribute sets.
- The module [services.ankisyncd](#opt-services.ankisyncd.package) has been switched to [anki-sync-server-rs](https://github.com/ankicommunity/anki-sync-server-rs) from the old python version, which was difficult to update, had not been updated in a while, and did not support recent versions of anki.
Unfortunately all servers supporting new clients (newer version of anki-sync-server, anki's built in sync server and this new rust package) do not support the older sync protocol that was used in the old server, so such old clients will also need updating and in particular the anki package in nixpkgs is also being updated in this release.
The module update takes care of the new config syntax and the data itself (user login and cards) are compatible, so users of the module will be able to just log in again after updating both client and server without any extra action.
- `services.nginx` gained a `defaultListen` option at server-level with support for PROXY protocol listeners, also `proxyProtocol` is now exposed in `services.nginx.virtualHosts.<name>.listen` option. It is now possible to run PROXY listeners and non-PROXY listeners at a server-level, see [#213510](https://github.com/NixOS/nixpkgs/pull/213510/) for more details.
- `services.prometheus.exporters` has a new exporter to monitor electrical power consumption based on PowercapRAPL sensor called [Scaphandre](https://github.com/hubblo-org/scaphandre), see [#239803](https://github.com/NixOS/nixpkgs/pull/239803) for more details.

View file

@ -9,22 +9,16 @@ let
stateDir = "/var/lib/${name}";
authDbPath = "${stateDir}/auth.db";
toml = pkgs.formats.toml {};
sessionDbPath = "${stateDir}/session.db";
configFile = pkgs.writeText "ankisyncd.conf" (lib.generators.toINI {} {
sync_app = {
configFile = toml.generate "ankisyncd.conf" {
listen = {
host = cfg.host;
port = cfg.port;
data_root = stateDir;
auth_db_path = authDbPath;
session_db_path = sessionDbPath;
base_url = "/sync/";
base_media_url = "/msync/";
};
});
paths.root_dir = stateDir;
# encryption.ssl_enable / cert_file / key_file
};
in
{
options.services.ankisyncd = {
@ -59,8 +53,6 @@ in
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
environment.etc."ankisyncd/ankisyncd.conf".source = configFile;
systemd.services.ankisyncd = {
description = "ankisyncd - Anki sync server";
after = [ "network.target" ];
@ -71,7 +63,7 @@ in
Type = "simple";
DynamicUser = true;
StateDirectory = name;
ExecStart = "${cfg.package}/bin/ankisyncd";
ExecStart = "${cfg.package}/bin/ankisyncd --config ${configFile}";
Restart = "always";
};
};

4005
pkgs/servers/ankisyncd/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,68 +1,52 @@
{ lib
, fetchFromGitHub
, python3
}:
{ lib, runCommand, fetchFromGitHub, rustPlatform, protobuf }:
python3.pkgs.buildPythonApplication rec {
let
pname = "ankisyncd";
version = "2.2.0";
src = fetchFromGitHub {
owner = "ankicommunity";
repo = "anki-sync-server";
rev = version;
hash = "sha256-RXrdJGJ+HMSpDGQBuVPPqsh3+uwAgE6f7ZJ0yFRMI8I=";
version = "1.1.4";
# anki-sync-server-rs expects anki sources in the 'anki' folder
# of its own source tree, with a patch applied (mostly to make
# some modules public): prepare our own 'src' manually
src = runCommand "anki-sync-server-rs-src" {
src = fetchFromGitHub {
owner = "ankicommunity";
repo = "anki-sync-server-rs";
rev = version;
hash = "sha256-iL4lJJAV4SrNeRX3s0ZpJ//lrwoKjLsltlX4d2wP6O0=";
};
} ''
cp -r "$src/." "$out"
chmod +w "$out"
cp -r "${ankiSrc}" "$out/anki"
chmod -R +w "$out/anki"
patch -d "$out/anki" -Np1 < "$src/anki_patch/d9d36078f17a2b4b8b44fcb802eb274911ebabe7_anki_rslib.patch"
'';
# Note we do not use anki.src because the patch in ankisyncd's
# sources expect a fixed version, so we pin it here.
ankiSrc = fetchFromGitHub {
owner = "ankitects";
repo = "anki";
rev = "2.1.60";
hash = "sha256-hNrf6asxF7r7QK2XO150yiRjyHAYKN8OFCFYX0SAiwA=";
fetchSubmodules = true;
};
format = "other";
in rustPlatform.buildRustPackage {
inherit pname version src;
installPhase = ''
runHook preInstall
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"csv-1.1.6" = "sha256-w728ffOVkI+IfK6FbmkGhr0CjuyqgJnPB1kutMJIUYg=";
};
};
mkdir -p $out/${python3.sitePackages}
cp -r ankisyncd utils ankisyncd.conf $out/${python3.sitePackages}
cp -r anki-bundled/anki $out/${python3.sitePackages}
mkdir $out/share
cp ankisyncctl.py $out/share/
runHook postInstall
'';
fixupPhase = ''
PYTHONPATH="$PYTHONPATH:$out/${python3.sitePackages}"
makeWrapper "${python3.interpreter}" "$out/bin/ankisyncd" \
--set PYTHONPATH $PYTHONPATH \
--add-flags "-m ankisyncd"
makeWrapper "${python3.interpreter}" "$out/bin/ankisyncctl" \
--set PYTHONPATH $PYTHONPATH \
--add-flags "$out/share/ankisyncctl.py"
'';
nativeCheckInputs = with python3.pkgs; [
pytest
webtest
];
buildInputs = [ ];
propagatedBuildInputs = with python3.pkgs; [
decorator
requests
];
checkPhase = ''
# skip these tests, our files are too young:
# tests/test_web_media.py::SyncAppFunctionalMediaTest::test_sync_mediaChanges ValueError: ZIP does not support timestamps before 1980
pytest --ignore tests/test_web_media.py tests/
'';
nativeBuildInputs = [ protobuf ];
meta = with lib; {
description = "Self-hosted Anki sync server";
maintainers = with maintainers; [ matt-snider ];
homepage = "https://github.com/ankicommunity/anki-sync-server";
license = licenses.agpl3Only;
platforms = platforms.linux;
description = "Standalone unofficial anki sync server";
homepage = "https://github.com/ankicommunity/anki-sync-server-rs";
license = with licenses; [ agpl3Only ];
maintainers = with maintainers; [ martinetd ];
};
}

View file

@ -240,9 +240,7 @@ with pkgs;
anders = callPackage ../applications/science/logic/anders { };
ankisyncd = callPackage ../servers/ankisyncd {
python3 = python39;
};
ankisyncd = callPackage ../servers/ankisyncd { };
ariang = callPackage ../servers/ariang { };