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