diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 574619b2b31..0204c1e3529 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -4544,6 +4544,12 @@ githubId = 1711539; name = "matklad"; }; + matt-snider = { + email = "matt.snider@protonmail.com"; + github = "matt-snider"; + githubId = 11810057; + name = "Matt Snider"; + }; matthewbauer = { email = "mjbauer95@gmail.com"; github = "matthewbauer"; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 917840fb919..dba2593bbef 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -406,6 +406,7 @@ ./services/mail/sympa.nix ./services/mail/nullmailer.nix ./services/misc/airsonic.nix + ./services/misc/ankisyncd.nix ./services/misc/apache-kafka.nix ./services/misc/autofs.nix ./services/misc/autorandr.nix diff --git a/nixos/modules/services/misc/ankisyncd.nix b/nixos/modules/services/misc/ankisyncd.nix new file mode 100644 index 00000000000..5fc19649d3d --- /dev/null +++ b/nixos/modules/services/misc/ankisyncd.nix @@ -0,0 +1,79 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.ankisyncd; + + name = "ankisyncd"; + + stateDir = "/var/lib/${name}"; + + authDbPath = "${stateDir}/auth.db"; + + sessionDbPath = "${stateDir}/session.db"; + + configFile = pkgs.writeText "ankisyncd.conf" (lib.generators.toINI {} { + sync_app = { + host = cfg.host; + port = cfg.port; + data_root = stateDir; + auth_db_path = authDbPath; + session_db_path = sessionDbPath; + + base_url = "/sync/"; + base_media_url = "/msync/"; + }; + }); +in + { + options.services.ankisyncd = { + enable = mkEnableOption "ankisyncd"; + + package = mkOption { + type = types.package; + default = pkgs.ankisyncd; + defaultText = literalExample "pkgs.ankisyncd"; + description = "The package to use for the ankisyncd command."; + }; + + host = mkOption { + type = types.str; + default = "localhost"; + description = "ankisyncd host"; + }; + + port = mkOption { + type = types.int; + default = 27701; + description = "ankisyncd port"; + }; + + openFirewall = mkOption { + default = false; + type = types.bool; + description = "Whether to open the firewall for the specified port."; + }; + }; + + 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" ]; + wantedBy = [ "multi-user.target" ]; + path = [ cfg.package ]; + + serviceConfig = { + Type = "simple"; + DynamicUser = true; + StateDirectory = name; + ExecStart = "${cfg.package}/bin/ankisyncd"; + Restart = "always"; + }; + }; + }; + } diff --git a/pkgs/servers/ankisyncd/default.nix b/pkgs/servers/ankisyncd/default.nix new file mode 100644 index 00000000000..e1098670123 --- /dev/null +++ b/pkgs/servers/ankisyncd/default.nix @@ -0,0 +1,67 @@ +{ lib +, fetchFromGitHub +, python3 +, anki +}: + +python3.pkgs.buildPythonApplication rec { + pname = "ankisyncd"; + version = "2.1.0"; + src = fetchFromGitHub { + owner = "tsudoko"; + repo = "anki-sync-server"; + rev = version; + sha256 = "6a140afa94fdb1725fed716918875e3d2ad0092cb955136e381c9d826cc4927c"; + }; + format = "other"; + + installPhase = '' + runHook preInstall + + mkdir -p $out/${python3.sitePackages} + + cp -r ankisyncd utils ankisyncd.conf $out/${python3.sitePackages} + mkdir $out/share + cp ankisyncctl.py $out/share/ + + runHook postInstall + ''; + + fixupPhase = '' + PYTHONPATH="$PYTHONPATH:$out/${python3.sitePackages}:${anki}" + + 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" + ''; + + checkInputs = with python3.pkgs; [ + pytest + webtest + ]; + + buildInputs = [ ]; + + propagatedBuildInputs = [ anki ]; + + checkPhase = '' + # Exclude tests that require sqlite's sqldiff command, since + # it isn't yet packaged for NixOS, although 2 PRs exist: + # - https://github.com/NixOS/nixpkgs/pull/69112 + # - https://github.com/NixOS/nixpkgs/pull/75784 + # Once this is merged, these tests can be run as well. + pytest --ignore tests/test_web_media.py tests/ + ''; + + meta = with lib; { + description = "Self-hosted Anki sync server"; + maintainers = with maintainers; [ matt-snider ]; + homepage = "https://github.com/tsudoko/anki-sync-server"; + license = licenses.agpl3; + platforms = platforms.linux; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 74ab773c239..190be007f4f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -126,6 +126,8 @@ in addOpenGLRunpath = callPackage ../build-support/add-opengl-runpath { }; + ankisyncd = callPackage ../servers/ankisyncd { }; + avro-tools = callPackage ../development/tools/avro-tools { }; # Zip file format only allows times after year 1980, which makes e.g. Python wheel building fail with: