2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.netatalk;
|
2021-05-20 23:08:51 +00:00
|
|
|
settingsFormat = pkgs.formats.ini { };
|
|
|
|
afpConfFile = settingsFormat.generate "afp.conf" cfg.settings;
|
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
services.netatalk = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "the Netatalk AFP fileserver";
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 548;
|
|
|
|
description = "TCP port to be used for AFP.";
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
settings = mkOption {
|
|
|
|
inherit (settingsFormat) type;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = { };
|
2021-05-20 23:08:51 +00:00
|
|
|
example = {
|
|
|
|
Global = { "uam list" = "uams_guest.so"; };
|
|
|
|
Homes = {
|
|
|
|
path = "afp-data";
|
|
|
|
"basedir regex" = "/home";
|
|
|
|
};
|
|
|
|
example-volume = {
|
|
|
|
path = "/srv/volume";
|
|
|
|
"read only" = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Configuration for Netatalk. See
|
|
|
|
<citerefentry><refentrytitle>afp.conf</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry>.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extmap = mkOption {
|
|
|
|
type = types.lines;
|
2020-11-24 20:58:05 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
File name extension mappings.
|
2021-05-20 23:08:51 +00:00
|
|
|
See <citerefentry><refentrytitle>extmap.conf</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry>. for more information.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
imports = (map (option:
|
|
|
|
mkRemovedOptionModule [ "services" "netatalk" option ]
|
|
|
|
"This option was removed in favor of `services.netatalk.settings`.") [
|
|
|
|
"extraConfig"
|
|
|
|
"homes"
|
|
|
|
"volumes"
|
|
|
|
]);
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
services.netatalk.settings.Global = {
|
|
|
|
"afp port" = toString cfg.port;
|
|
|
|
"extmap file" = "${pkgs.writeText "extmap.conf" cfg.extmap}";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.netatalk = {
|
|
|
|
description = "Netatalk AFP fileserver for Macintosh clients";
|
2021-05-20 23:08:51 +00:00
|
|
|
unitConfig.Documentation =
|
|
|
|
"man:afp.conf(5) man:netatalk(8) man:afpd(8) man:cnid_metad(8) man:cnid_dbd(8)";
|
2020-04-24 23:36:52 +00:00
|
|
|
after = [ "network.target" "avahi-daemon.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
path = [ pkgs.netatalk ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
GuessMainPID = "no";
|
|
|
|
PIDFile = "/run/lock/netatalk";
|
2021-05-20 23:08:51 +00:00
|
|
|
ExecStart = "${pkgs.netatalk}/sbin/netatalk -F ${afpConfFile}";
|
2020-04-24 23:36:52 +00:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
2021-05-20 23:08:51 +00:00
|
|
|
ExecStop = "${pkgs.coreutils}/bin/kill -TERM $MAINPID";
|
2020-04-24 23:36:52 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 1;
|
2021-05-20 23:08:51 +00:00
|
|
|
StateDirectory = [ "netatalk/CNID" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
security.pam.services.netatalk.unixAuth = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|