at 24.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.ankisyncd; 7 8 name = "ankisyncd"; 9 10 stateDir = "/var/lib/${name}"; 11 12 toml = pkgs.formats.toml {}; 13 14 configFile = toml.generate "ankisyncd.conf" { 15 listen = { 16 host = cfg.host; 17 port = cfg.port; 18 }; 19 paths.root_dir = stateDir; 20 # encryption.ssl_enable / cert_file / key_file 21 }; 22in 23 { 24 options.services.ankisyncd = { 25 enable = mkEnableOption "ankisyncd, a standalone unofficial anky sync server"; 26 27 package = mkPackageOption pkgs "ankisyncd" { }; 28 29 host = mkOption { 30 type = types.str; 31 default = "localhost"; 32 description = "ankisyncd host"; 33 }; 34 35 port = mkOption { 36 type = types.port; 37 default = 27701; 38 description = "ankisyncd port"; 39 }; 40 41 openFirewall = mkOption { 42 default = false; 43 type = types.bool; 44 description = "Whether to open the firewall for the specified port."; 45 }; 46 }; 47 48 config = mkIf cfg.enable { 49 warnings = [ 50 '' 51 `services.ankisyncd` has been replaced by `services.anki-sync-server` and will be removed after 52 24.05 because anki-sync-server(-rs and python) are not maintained. 53 '' 54 ]; 55 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; 56 57 systemd.services.ankisyncd = { 58 description = "ankisyncd - Anki sync server"; 59 after = [ "network.target" ]; 60 wantedBy = [ "multi-user.target" ]; 61 path = [ cfg.package ]; 62 63 serviceConfig = { 64 Type = "simple"; 65 DynamicUser = true; 66 StateDirectory = name; 67 ExecStart = "${cfg.package}/bin/ankisyncd --config ${configFile}"; 68 Restart = "always"; 69 }; 70 }; 71 }; 72 }