1 { config, lib, pkgs, ... }:
6 cfg = config.services.ankisyncd;
10 stateDir = "/var/lib/${name}";
12 authDbPath = "${stateDir}/auth.db";
14 sessionDbPath = "${stateDir}/session.db";
16 configFile = pkgs.writeText "ankisyncd.conf" (lib.generators.toINI {} {
21 auth_db_path = authDbPath;
22 session_db_path = sessionDbPath;
25 base_media_url = "/msync/";
30 options.services.ankisyncd = {
31 enable = mkEnableOption (lib.mdDoc "ankisyncd");
35 default = pkgs.ankisyncd;
36 defaultText = literalExpression "pkgs.ankisyncd";
37 description = lib.mdDoc "The package to use for the ankisyncd command.";
42 default = "localhost";
43 description = lib.mdDoc "ankisyncd host";
49 description = lib.mdDoc "ankisyncd port";
52 openFirewall = mkOption {
55 description = lib.mdDoc "Whether to open the firewall for the specified port.";
59 config = mkIf cfg.enable {
60 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
62 environment.etc."ankisyncd/ankisyncd.conf".source = configFile;
64 systemd.services.ankisyncd = {
65 description = "ankisyncd - Anki sync server";
66 after = [ "network.target" ];
67 wantedBy = [ "multi-user.target" ];
68 path = [ cfg.package ];
73 StateDirectory = name;
74 ExecStart = "${cfg.package}/bin/ankisyncd";