From d6b50dd171e6092c5df26728dc8397d1add1e3f0 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Mon, 23 Sep 2019 12:52:24 -0400
Subject: [PATCH] ever so much simpler this way

just need 35 more hosts and then defining the function will be a win ...
---
 nixos/modules/tests/private-storage.nix | 50 +++++--------------------
 1 file changed, 10 insertions(+), 40 deletions(-)

diff --git a/nixos/modules/tests/private-storage.nix b/nixos/modules/tests/private-storage.nix
index e628984d..30818b33 100644
--- a/nixos/modules/tests/private-storage.nix
+++ b/nixos/modules/tests/private-storage.nix
@@ -13,48 +13,18 @@ let
     name = "introducer.furl";
     text = introducerFURL;
   };
-
-  # setupNetwork :: Set Name (Set -> AttrSet) -> Set Name (Set -> AttrSet)
-  setupNetwork = nodes:
-    let
-      # makeNetwork :: Integer -> AttrSet
-      makeNetwork = n: {
-        # Just need to disable the firewall so all the traffic flows freely.
-        # We could do other network configuration here too, if we wanted.
-        # Initially I thought we might need to statically asssign IPs but we
-        # can just use the node names, "introducer", etc, instead.
-        networking.firewall.enable = false;
-      };
-      # addresses :: [Integer]
-      addresses = pkgs.lib.range 0 (builtins.length (builtins.attrNames nodes));
-      # nodesAsList :: [(Name, (Set -> AttrSet))]
-      nodesAsList = pkgs.lib.attrsets.mapAttrsToList (name: value: [name value]) nodes;
-      # nodeAndNetworkList :: [[Name, Set -> AttrSet], Integer]
-      nodeAndNetworkList = pkgs.lib.lists.zipListsWith (fst: snd: [fst snd]) nodesAsList addresses;
-
-      # mergeNodeAndNetwork :: Integer -> Name -> (Set -> AttrSet) -> {Name, (Set -> AttrSet)}
-      mergeNodeAndNetwork = number: name: node: {
-        inherit name;
-        # Sadly we have to name arguments in this definition to get them
-        # automatically passed in by the various autocall helpers in Nix.
-        value = args@{ pkgs, ... }: ((node args) // (makeNetwork number));
-      };
-      at = builtins.elemAt;
-      merged = map (elem:
-        let
-          node = (at (at elem 0) 1);
-          name = (at (at elem 0) 0);
-          number = (at elem 1);
-        in
-          mergeNodeAndNetwork number name node
-      ) nodeAndNetworkList;
-    in
-      builtins.listToAttrs merged;
+  networkConfig = {
+    # Just need to disable the firewall so all the traffic flows freely.  We
+    # could do other network configuration here too, if we wanted.  Initially
+    # I thought we might need to statically asssign IPs but we can just use
+    # the node names, "introducer", etc, instead.
+    networking.firewall.enable = false;
+  };
 in
 # https://nixos.org/nixos/manual/index.html#sec-nixos-tests
 import <nixpkgs/nixos/tests/make-test.nix> {
 
-  nodes = setupNetwork rec {
+  nodes = rec {
     # Get a machine where we can run a Tahoe-LAFS client node.
     client =
       { config, pkgs, ... }:
@@ -62,7 +32,7 @@ import <nixpkgs/nixos/tests/make-test.nix> {
           pkgs.tahoe-lafs
           pkgs.daemonize
         ];
-      };
+      } // networkConfig;
 
     # Get another machine where we can run a Tahoe-LAFS introducer node.  It has the same configuration as the client.
     introducer = client;
@@ -76,7 +46,7 @@ import <nixpkgs/nixos/tests/make-test.nix> {
         services.private-storage.enable = true;
         services.private-storage.publicIPv4 = "storage";
         services.private-storage.introducerFURL = introducerFURL;
-      };
+      } // networkConfig;
   };
 
   # Test the machines with a Perl program (sobbing).
-- 
GitLab