From 041c700cc777aa1fe98ae6930146d9eaee8fe04a Mon Sep 17 00:00:00 2001
From: Rickard Nilsson <rickynils@gmail.com>
Date: Sat, 17 Mar 2012 21:21:52 +0100
Subject: [PATCH 6/6] rpcbind

---
 modules/module-list.nix                       |    1 +
 modules/services/network-filesystems/nfsd.nix |    6 +-
 modules/services/networking/rpcbind.nix       |   80 +++++++++++++++++++++++++
 modules/tasks/filesystems/nfs.nix             |    6 +-
 4 files changed, 87 insertions(+), 6 deletions(-)
 create mode 100644 modules/services/networking/rpcbind.nix

diff --git a/modules/module-list.nix b/modules/module-list.nix
index 36e934d..7e9a4d2 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -142,6 +142,7 @@
   ./services/networking/quassel.nix
   ./services/networking/radvd.nix
   ./services/networking/rdnssd.nix
+  ./services/networking/rpcbind.nix
   ./services/networking/sabnzbd.nix
   ./services/networking/ssh/lshd.nix
   ./services/networking/ssh/sshd.nix
diff --git a/modules/services/network-filesystems/nfsd.nix b/modules/services/network-filesystems/nfsd.nix
index d1c280c..dba2db2 100644
--- a/modules/services/network-filesystems/nfsd.nix
+++ b/modules/services/network-filesystems/nfsd.nix
@@ -67,7 +67,7 @@ in
 
   config = mkIf cfg.enable {
 
-    services.portmap.enable = true;
+    services.rpcbind.enable = true;
 
     services.nfs.client.enable = true; # needed for statd and idmapd
 
@@ -89,7 +89,7 @@ in
 
         preStart =
           ''
-            ensure portmap
+            ensure rpcbind
             ensure mountd
 
             # Create a state directory required by NFSv4.
@@ -116,7 +116,7 @@ in
 
         preStart =
           ''
-            ensure portmap
+            ensure rpcbind
 
             mkdir -p /var/lib/nfs
             touch /var/lib/nfs/rmtab
diff --git a/modules/services/networking/rpcbind.nix b/modules/services/networking/rpcbind.nix
new file mode 100644
index 0000000..5437d22
--- /dev/null
+++ b/modules/services/networking/rpcbind.nix
@@ -0,0 +1,80 @@
+{ config, pkgs, ... }:
+
+with pkgs.lib;
+
+let
+
+  netconfigFile = {
+    target = "netconfig";
+    source = pkgs.writeText "netconfig" ''
+      #
+      # The network configuration file. This file is currently only used in
+      # conjunction with the TI-RPC code in the libtirpc library.
+      #
+      # Entries consist of:
+      #
+      #       <network_id> <semantics> <flags> <protofamily> <protoname> \
+      #               <device> <nametoaddr_libs>
+      #
+      # The <device> and <nametoaddr_libs> fields are always empty in this
+      # implementation.
+      #
+      udp        tpi_clts      v     inet     udp     -       -
+      tcp        tpi_cots_ord  v     inet     tcp     -       -
+      udp6       tpi_clts      v     inet6    udp     -       -
+      tcp6       tpi_cots_ord  v     inet6    tcp     -       -
+      rawip      tpi_raw       -     inet      -      -       -
+      local      tpi_cots_ord  -     loopback  -      -       -
+      unix       tpi_cots_ord  -     loopback  -      -       -
+    '';
+  };
+
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.rpcbind = {
+
+      enable = mkOption {
+        default = false;
+        description = ''
+          Whether to enable `rpcbind', an ONC RPC directory service
+          notably used by NFS and NIS, and which can be queried
+          using the rpcinfo(1) command. `rpcbind` is a replacement for
+          `portmap`.
+        '';
+      };
+
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf config.services.rpcbind.enable {
+
+    environment.etc = [netconfigFile];
+
+    jobs.rpcbind =
+      { description = "ONC RPC rpcbind";
+
+        startOn = "started network-interfaces";
+        stopOn = "";
+
+        daemonType = "fork";
+
+        exec =
+          ''
+            ${pkgs.rpcbind}/bin/rpcbind
+          '';
+      };
+
+  };
+
+}
diff --git a/modules/tasks/filesystems/nfs.nix b/modules/tasks/filesystems/nfs.nix
index ceb21c8..e54cb81 100644
--- a/modules/tasks/filesystems/nfs.nix
+++ b/modules/tasks/filesystems/nfs.nix
@@ -49,7 +49,7 @@ in
 
   config = mkIf config.services.nfs.client.enable {
 
-    services.portmap.enable = true;
+    services.rpcbind.enable = true;
     
     system.fsPackages = [ pkgs.nfsUtils ];
 
@@ -72,7 +72,7 @@ in
 
         preStart =
           ''
-            ensure portmap
+            ensure rpcbind
             mkdir -p ${nfsStateDir}/sm
             mkdir -p ${nfsStateDir}/sm.bak
             sm-notify -d
@@ -92,7 +92,7 @@ in
 
         preStart =
           ''
-            ensure portmap
+            ensure rpcbind
             mkdir -p ${rpcMountpoint}
             mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint}
           '';
-- 
1.7.9.4

