From 55f9c5cfaf7f1ecf4dda288f37bd7695d8f8c97c Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 28 Aug 2019 14:39:29 -0400
Subject: [PATCH] Refine the private-storage configuration model

This results in less repetition, less abstraction leakage, and provides more
power to the private-storage module (by exposing meaningful values instead of
Tahoe-LAFS config strings).
---
 morph/staging000.nix              | 10 +++++-----
 morph/staging001.nix              | 10 +++-------
 nixos/modules/private-storage.nix | 24 +++++++++++++-----------
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/morph/staging000.nix b/morph/staging000.nix
index cf726b45..592c124b 100644
--- a/morph/staging000.nix
+++ b/morph/staging000.nix
@@ -4,9 +4,9 @@
     ../nixos/modules/private-storage.nix
   ];
 
-  services.private-storage.enable = true;
-  services.private-storage.tahoe.node."tub.port" = "tcp:${toString publicStoragePort}";
-  services.private-storage.tahoe.node."tub.location" = "tcp:${publicIPv4}:${toString publicStoragePort}";
-
-  networking.firewall.allowedTCPPorts = [ publicStoragePort ];
+  services.private-storage =
+  { enable = true;
+    inherit publicIPv4;
+    inherit publicStoragePort;
+  };
 }
diff --git a/morph/staging001.nix b/morph/staging001.nix
index 488fc907..873d8d35 100644
--- a/morph/staging001.nix
+++ b/morph/staging001.nix
@@ -1,11 +1,7 @@
-# Edit this configuration file to define what should be installed on
-# your system.  Help is available in the configuration.nix(5) man page
-# and in the NixOS manual (accessible by running ‘nixos-help’).
+{ publicIPv4, publicStoragePort }:
 
 { config, pkgs, ... }:
-
-{
-  imports =
+{ imports =
     [ # Include the results of the hardware scan.
       ./staging001-hardware.nix
     ];
@@ -27,7 +23,7 @@
   # Provide the static network configuration.
   networking.interfaces = {
     enp2s0f0.ipv4.addresses = [
-      { address = "209.95.51.251"; prefixLength = 24; }
+      { address = publicIPv4; prefixLength = 24; }
     ];
   };
   networking.defaultGateway = {
diff --git a/nixos/modules/private-storage.nix b/nixos/modules/private-storage.nix
index ae0eb077..dc83150f 100644
--- a/nixos/modules/private-storage.nix
+++ b/nixos/modules/private-storage.nix
@@ -33,20 +33,20 @@ in
         The package to use for the Tahoe-LAFS daemon.
       '';
     };
-    services.private-storage.tahoe.node."tub.port" = lib.mkOption
-    { default = "disabled";
+    services.private-storage.publicIPv4 = lib.mkOption
+    { default = "127.0.0.1";
       type = lib.types.str;
-      example = lib.literalExample "tcp:8098";
+      example = lib.literalExample "192.0.2.0";
       description = ''
-        A value for the [node]tub.port in tahoe.cfg.
+        An IPv4 address to advertise for this storage service.
       '';
     };
-    services.private-storage.tahoe.node."tub.location" = lib.mkOption
-    { default = "disabled";
-      type = lib.types.str;
-      example = lib.literalExample "tcp:192.0.2.0:8098";
+    services.private-storage.publicStoragePort = lib.mkOption
+    { default = 8898;
+      type = lib.types.int;
+      example = lib.literalExample 8098;
       description = ''
-        A value for the [node]tub.location in tahoe.cfg.
+        The port number on which to service storage clients.
       '';
     };
   };
@@ -58,8 +58,8 @@ in
         # XXX Should try to name that is unique across the grid.
         { nickname = "storage";
           "web.port" = "tcp:3456:interface=127.0.0.1";
-          "tub.port" = cfg.tahoe.node."tub.port";
-          "tub.location" = cfg.tahoe.node."tub.location";
+          "tub.port" = "tcp:${toString cfg.publicStoragePort}";
+          "tub.location" = "tcp:${cfg.publicIPv4}:${toString cfg.publicStoragePort}";
         };
         storage =
         { enabled = true;
@@ -70,5 +70,7 @@ in
         };
       };
     };
+    networking.firewall.allowedTCPPorts = [ cfg.publicStoragePort ];
+
   };
 }
-- 
GitLab