1# Anki Sync Server {#module-services-anki-sync-server}
2
3[Anki Sync Server](https://docs.ankiweb.net/sync-server.html) is the built-in
4sync server, present in recent versions of Anki. Advanced users who cannot or
5do not wish to use AnkiWeb can use this sync server instead of AnkiWeb.
6
7This module is compatible only with Anki versions >=2.1.66, due to [recent
8enhancements to the Nix anki
9package](https://github.com/NixOS/nixpkgs/commit/05727304f8815825565c944d012f20a9a096838a).
10
11## Basic Usage {#module-services-anki-sync-server-basic-usage}
12
13By default, the module creates a
14[`systemd`](https://www.freedesktop.org/wiki/Software/systemd/)
15unit which runs the sync server with an isolated user using the systemd
16`DynamicUser` option.
17
18This can be done by enabling the `anki-sync-server` service:
19```nix
20{ ... }:
21
22{
23 services.anki-sync-server.enable = true;
24}
25```
26
27It is necessary to set at least one username-password pair under
28{option}`services.anki-sync-server.users`. For example
29
30```nix
31{
32 services.anki-sync-server.users = [
33 {
34 username = "user";
35 passwordFile = /etc/anki-sync-server/user;
36 }
37 ];
38}
39```
40
41Here, `passwordFile` is the path to a file containing just the password in
42plaintext. Make sure to set permissions to make this file unreadable to any
43user besides root.
44
45By default, the server listen address {option}`services.anki-sync-server.host`
46is set to localhost, listening on port
47{option}`services.anki-sync-server.port`, and does not open the firewall. This
48is suitable for purely local testing, or to be used behind a reverse proxy. If
49you want to expose the sync server directly to other computers (not recommended
50in most circumstances, because the sync server doesn't use HTTPS), then set the
51following options:
52
53```nix
54{
55 services.anki-sync-server.host = "0.0.0.0";
56 services.anki-sync-server.openFirewall = true;
57}
58```
59
60
61## Alternatives {#module-services-anki-sync-server-alternatives}
62
63The [`ankisyncd` NixOS
64module](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/ankisyncd.nix)
65provides similar functionality, but using a third-party implementation,
66[`anki-sync-server-rs`](https://github.com/ankicommunity/anki-sync-server-rs/).
67According to that project's README, it is "no longer maintained", and not
68recommended for Anki 2.1.64+.