1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.netatalk;
7 settingsFormat = pkgs.formats.ini { };
8 afpConfFile = settingsFormat.generate "afp.conf" cfg.settings;
9in {
10 options = {
11 services.netatalk = {
12
13 enable = mkEnableOption (lib.mdDoc "the Netatalk AFP fileserver");
14
15 port = mkOption {
16 type = types.port;
17 default = 548;
18 description = lib.mdDoc "TCP port to be used for AFP.";
19 };
20
21 settings = mkOption {
22 inherit (settingsFormat) type;
23 default = { };
24 example = {
25 Global = { "uam list" = "uams_guest.so"; };
26 Homes = {
27 path = "afp-data";
28 "basedir regex" = "/home";
29 };
30 example-volume = {
31 path = "/srv/volume";
32 "read only" = true;
33 };
34 };
35 description = lib.mdDoc ''
36 Configuration for Netatalk. See
37 {manpage}`afp.conf(5)`.
38 '';
39 };
40
41 extmap = mkOption {
42 type = types.lines;
43 default = "";
44 description = lib.mdDoc ''
45 File name extension mappings.
46 See {manpage}`extmap.conf(5)`. for more information.
47 '';
48 };
49
50 };
51 };
52
53 imports = (map (option:
54 mkRemovedOptionModule [ "services" "netatalk" option ]
55 "This option was removed in favor of `services.netatalk.settings`.") [
56 "extraConfig"
57 "homes"
58 "volumes"
59 ]);
60
61 config = mkIf cfg.enable {
62
63 services.netatalk.settings.Global = {
64 "afp port" = toString cfg.port;
65 "extmap file" = "${pkgs.writeText "extmap.conf" cfg.extmap}";
66 };
67
68 systemd.services.netatalk = {
69 description = "Netatalk AFP fileserver for Macintosh clients";
70 unitConfig.Documentation =
71 "man:afp.conf(5) man:netatalk(8) man:afpd(8) man:cnid_metad(8) man:cnid_dbd(8)";
72 after = [ "network.target" "avahi-daemon.service" ];
73 wantedBy = [ "multi-user.target" ];
74
75 path = [ pkgs.netatalk ];
76
77 serviceConfig = {
78 Type = "forking";
79 GuessMainPID = "no";
80 PIDFile = "/run/lock/netatalk";
81 ExecStart = "${pkgs.netatalk}/sbin/netatalk -F ${afpConfFile}";
82 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
83 ExecStop = "${pkgs.coreutils}/bin/kill -TERM $MAINPID";
84 Restart = "always";
85 RestartSec = 1;
86 StateDirectory = [ "netatalk/CNID" ];
87 };
88
89 };
90
91 security.pam.services.netatalk.unixAuth = true;
92
93 };
94
95}