summary refs log tree commit diff
path: root/modules/services/networking/portmap.nix
blob: 9c0d559f867e7b18e56169286d76e0a573ecfdf0 (plain) (blame)
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
{ config, pkgs, ... }:

with pkgs.lib;

let

  uid = config.ids.uids.portmap;
  gid = config.ids.gids.portmap;

  portmap = pkgs.portmap.override { daemonUID = uid; daemonGID = gid; };
  
in

{

  ###### interface

  options = {
  
    services.portmap = {
    
      enable = mkOption {
        default = false;
        description = ''
          Whether to enable `portmap', an ONC RPC directory service
          notably used by NFS and NIS, and which can be queried
          using the rpcinfo(1) command.
        '';
      };

      verbose = mkOption {
        default = false;
        description = ''
          Whether to enable verbose output.
        '';
      };

      chroot = mkOption {
        default = "/var/empty";
        description = ''
          If non-empty, a path to change root to.
        '';
      };

    };

  };
  

  ###### implementation

  config = mkIf config.services.portmap.enable {

    users.extraUsers = singleton
      { name = "portmap";
        inherit uid;
        description = "Portmap daemon user";
        home = "/var/empty";
      };

    users.extraGroups = singleton
      { name = "portmap";
        inherit gid;
      };

    jobs.portmap =
      { description = "ONC RPC portmap";

        startOn = "started network-interfaces";
        stopOn = "never";

        daemonType = "fork";

        exec =
          ''
            ${portmap}/sbin/portmap \
              ${optionalString (config.services.portmap.chroot != "")
                "-t '${config.services.portmap.chroot}'"} \
              ${if config.services.portmap.verbose then "-v" else ""}
          '';
      };

  };

}