summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/networking/atalkd.nix
blob: 72760a1da96454fd50253a2c90b707f3530c923b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  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 {file}`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;
}