summary refs log tree commit diff
path: root/nixos/modules/services/networking/cjdns.nix
diff options
context:
space:
mode:
authorJoachim Fasting <joachifm@fastmail.fm>2016-10-25 20:56:54 +0200
committerJoachim Fasting <joachifm@fastmail.fm>2016-10-27 14:15:54 +0200
commit8180922d236c53b5e09cfe1b63f6c12977bb2803 (patch)
tree25ef9efe35719e555df74d2c95a17bbe8f4745d9 /nixos/modules/services/networking/cjdns.nix
parent9654e09b5a4bd44ecf16f8c435afa834a76ef2b1 (diff)
downloadnixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar.gz
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar.bz2
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar.lz
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar.xz
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.tar.zst
nixpkgs-8180922d236c53b5e09cfe1b63f6c12977bb2803.zip
cjdns service: refactor cjdns hosts builder
The old version would export two lists to a bash builder and do pairwise
processing on the bash side.  In the new version we instead generate a
logic free builder on the Nix side. This is not only conceptually
simpler but reduces the amount of code and intermediate values.
Diffstat (limited to 'nixos/modules/services/networking/cjdns.nix')
-rw-r--r--nixos/modules/services/networking/cjdns.nix29
1 files changed, 13 insertions, 16 deletions
diff --git a/nixos/modules/services/networking/cjdns.nix b/nixos/modules/services/networking/cjdns.nix
index 849d273a41d..5e15e40ea0c 100644
--- a/nixos/modules/services/networking/cjdns.nix
+++ b/nixos/modules/services/networking/cjdns.nix
@@ -28,21 +28,18 @@ let
     };
   };
 
-  peers = mapAttrsToList (n: v: v) (cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo);
-
-  pubs  = toString (map (p: if p.hostname == "" then "" else p.publicKey) peers);
-  hosts = toString (map (p: if p.hostname == "" then "" else p.hostname)  peers);
-
-  cjdnsHosts =
-    if hosts != "" then
-      import (pkgs.stdenv.mkDerivation {
-        name = "cjdns-hosts";
-        builder = ./cjdns-hosts.sh;
-
-        inherit (pkgs) cjdns;
-        inherit pubs hosts;
-      })
-    else "";
+  # Additional /etc/hosts entries for peers with an associated hostname
+  cjdnsExtraHosts = import (pkgs.runCommand "cjdns-hosts" {}
+    # Generate a builder that produces an output usable as a Nix string value
+    ''
+      exec >$out
+      echo \'\'
+      ${concatStringsSep "\n" (mapAttrsToList (k: v:
+          optionalString (v.hostname != "")
+            "echo $(${pkgs.cjdns}/bin/publictoip6 ${x.key}) ${x.host}")
+          (cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo))}
+      echo \'\'
+    '');
 
   parseModules = x:
     x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
@@ -254,7 +251,7 @@ in
       };
     };
 
-    networking.extraHosts = "${cjdnsHosts}";
+    networking.extraHosts = cjdnsExtraHosts;
 
     assertions = [
       { assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );