2020-04-24 23:36:52 +00:00
|
|
|
{ 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 = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "ankisyncd");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.ankisyncd;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.ankisyncd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The package to use for the ankisyncd command.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "ankisyncd host";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 27701;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "ankisyncd port";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to open the firewall for the specified port.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|