Skip to content

Commit

Permalink
cjdns service: refactor cjdns hosts builder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joachifm committed Oct 27, 2016
1 parent 9654e09 commit 8180922
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
11 changes: 0 additions & 11 deletions nixos/modules/services/networking/cjdns-hosts.sh

This file was deleted.

29 changes: 13 additions & 16 deletions nixos/modules/services/networking/cjdns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

This comment has been minimized.

Copy link
@spacekitteh

spacekitteh Nov 4, 2016

Contributor

error: undefined variable ‘x’ at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/networking/cjdns.nix:39:53

This comment has been minimized.

Copy link
@joachifm

joachifm Nov 4, 2016

Author Contributor

Oops. I have a fix pending. Thank you

(cfg.ETHInterface.connectTo // cfg.UDPInterface.connectTo))}
echo \'\'
'');

parseModules = x:
x // { connectTo = mapAttrs (name: value: { inherit (value) password publicKey; }) x.connectTo; };
Expand Down Expand Up @@ -254,7 +251,7 @@ in
};
};

networking.extraHosts = "${cjdnsHosts}";
networking.extraHosts = cjdnsExtraHosts;

assertions = [
{ assertion = ( cfg.ETHInterface.bind != "" || cfg.UDPInterface.bind != "" || cfg.confFile != null );
Expand Down

0 comments on commit 8180922

Please sign in to comment.