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 "the Netatalk AFP fileserver"; 14 15 port = mkOption { 16 type = types.port; 17 default = 548; 18 description = "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 = '' 36 Configuration for Netatalk. See 37 <citerefentry><refentrytitle>afp.conf</refentrytitle> 38 <manvolnum>5</manvolnum></citerefentry>. 39 ''; 40 }; 41 42 extmap = mkOption { 43 type = types.lines; 44 default = ""; 45 description = '' 46 File name extension mappings. 47 See <citerefentry><refentrytitle>extmap.conf</refentrytitle> 48 <manvolnum>5</manvolnum></citerefentry>. for more information. 49 ''; 50 }; 51 52 }; 53 }; 54 55 imports = (map (option: 56 mkRemovedOptionModule [ "services" "netatalk" option ] 57 "This option was removed in favor of `services.netatalk.settings`.") [ 58 "extraConfig" 59 "homes" 60 "volumes" 61 ]); 62 63 config = mkIf cfg.enable { 64 65 services.netatalk.settings.Global = { 66 "afp port" = toString cfg.port; 67 "extmap file" = "${pkgs.writeText "extmap.conf" cfg.extmap}"; 68 }; 69 70 systemd.services.netatalk = { 71 description = "Netatalk AFP fileserver for Macintosh clients"; 72 unitConfig.Documentation = 73 "man:afp.conf(5) man:netatalk(8) man:afpd(8) man:cnid_metad(8) man:cnid_dbd(8)"; 74 after = [ "network.target" "avahi-daemon.service" ]; 75 wantedBy = [ "multi-user.target" ]; 76 77 path = [ pkgs.netatalk ]; 78 79 serviceConfig = { 80 Type = "forking"; 81 GuessMainPID = "no"; 82 PIDFile = "/run/lock/netatalk"; 83 ExecStart = "${pkgs.netatalk}/sbin/netatalk -F ${afpConfFile}"; 84 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 85 ExecStop = "${pkgs.coreutils}/bin/kill -TERM $MAINPID"; 86 Restart = "always"; 87 RestartSec = 1; 88 StateDirectory = [ "netatalk/CNID" ]; 89 }; 90 91 }; 92 93 security.pam.services.netatalk.unixAuth = true; 94 95 }; 96 97}