Unverified Commit 530db854 authored by Matthew Croughan's avatar Matthew Croughan Committed by GitHub
Browse files

nixos/atalkd: init (#425554)

parents 3046bb2f 75929b46
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -857,6 +857,12 @@
  "modules-services-akkoma-distributed-deployment": [
    "index.html#modules-services-akkoma-distributed-deployment"
  ],
  "module-services-atalkd": [
    "index.html#module-services-atalkd"
  ],
  "module-services-atalkd-basic-usage": [
    "index.html#module-services-atalkd-basic-usage"
  ],
  "module-services-systemd-lock-handler": [
    "index.html#module-services-systemd-lock-handler"
  ],
+1 −0
Original line number Diff line number Diff line
@@ -1073,6 +1073,7 @@
  ./services/networking/anubis.nix
  ./services/networking/aria2.nix
  ./services/networking/asterisk.nix
  ./services/networking/atalkd.nix
  ./services/networking/atftpd.nix
  ./services/networking/atticd.nix
  ./services/networking/autossh.nix
+18 −0
Original line number Diff line number Diff line
# atalkd {#module-services-atalkd}

atalkd (AppleTalk daemon) is a component inside of the suite of software provided by Netatalk. It allows for the creation of AppleTalk networks, typically speaking over a Linux ethernet network interface, that can still be seen by classic macintosh computers. Using the NixOS module, you can specify a set of network interfaces that you wish to speak AppleTalk on, and the corresponding ATALKD.CONF(5) values to go along with it.

## Basic Usage {#module-services-atalkd-basic-usage}

A minimal configuration looks like this:

```nix
{
  services.atalkd = {
    enable = true;
    interfaces.wlan0.config = "-router -phase 2 -net 1 -addr 1.48 -zone \"Default\"";
  };
}
```

It is also valid to use atalkd without setting `services.netatalk.interfaces` to any value, only providing `services.atalkd.enable = true`. In this case it will inherit the behavior of the upstream application when an empty config file is found, which is to listen on and use all interfaces.
+98 −0
Original line number Diff line number Diff line
{
  config,
  pkgs,
  lib,
  utils,
  ...
}:

let
  cfg = config.services.atalkd;

  # Generate atalkd.conf only if configFile isn't manually specified
  atalkdConfFile = pkgs.writeText "atalkd.conf" (
    lib.concatStringsSep "\n" (
      lib.mapAttrsToList (
        iface: ifaceCfg: iface + (if ifaceCfg.config != null then " ${ifaceCfg.config}" else "")
      ) cfg.interfaces
    )
  );
in
{
  options.services.atalkd = {
    enable = lib.mkEnableOption "the AppleTalk daemon";

    configFile = lib.mkOption {
      type = lib.types.nullOr lib.types.path;
      default = atalkdConfFile;
      defaultText = "/nix/store/xxx-atalkd.conf";
      description = ''
        Optional path to a custom `atalkd.conf` file. When set, this overrides the generated
        configuration from `services.atalkd.interfaces`.
      '';
    };

    interfaces = lib.mkOption {
      description = "Per-interface configuration for atalkd.";
      type = lib.types.attrsOf (
        lib.types.submodule {
          options.config = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "Optional configuration string for this interface.";
          };
        }
      );
      default = { };
    };
  };

  config =
    let
      interfaces = map (iface: "sys-subsystem-net-devices-${utils.escapeSystemdPath iface}.device") (
        builtins.attrNames cfg.interfaces
      );
    in
    lib.mkIf cfg.enable {
      system.requiredKernelConfig = [
        (config.lib.kernelConfig.isEnabled "APPLETALK")
      ];
      systemd.services.netatalk.partOf = [ "atalkd.service" ];
      systemd.services.netatalk.after = interfaces;
      systemd.services.netatalk.requires = interfaces;
      systemd.services.atalkd =
        let
          interfaces = map (iface: "sys-subsystem-net-devices-${utils.escapeSystemdPath iface}.device") (
            builtins.attrNames cfg.interfaces
          );
        in
        {

          description = "atalkd AppleTalk daemon";
          unitConfig.Documentation = "man:atalkd.conf(5) man:atalkd(8)";
          after = interfaces;
          wants = [ "network.target" ];
          before = [ "netatalk.service" ];
          requires = interfaces;

          wantedBy = [ "multi-user.target" ];

          path = [ pkgs.netatalk ];

          serviceConfig = {
            Type = "forking";
            GuessMainPID = "no";
            DynamicUser = true;
            AmbientCapabilities = [ "CAP_NET_ADMIN" ];
            RuntimeDirectory = "atalkd";
            PIDFile = "/run/atalkd/atalkd";
            BindPaths = [ "/run/atalkd:/run/lock" ];
            ExecStart = "${pkgs.netatalk}/bin/atalkd -f ${cfg.configFile}";
            Restart = "always";
          };
        };
    };

  meta.maintainers = with lib.maintainers; [ matthewcroughan ];
  meta.doc = ./atalkd.md;
}