Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created June 3, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamc/45d050f26d99fc6e285846e200533ba9 to your computer and use it in GitHub Desktop.
Save grahamc/45d050f26d99fc6e285846e200533ba9 to your computer and use it in GitHub Desktop.
import ../make-test.nix ({ lib, pkgs, ...} : let
globalPeers = [
{
idx = 1;
private = "QHWxUiMMnCNdYlUUowXOhwA9dqFj0mPW+hlrfL8+33U=";
public = "vcLLUIzLkTuv60vV7+nMsWUDSh+R+g+YR2Jn+Kjlc1g=";
}
{
idx = 2;
private = "yEhxYq3jxZMXMBCofjGNG+GomUmrwVUHvWvuFRWC2HU=";
public = "AMYt7rajfDZfupU8+m/uQ8C+1R++zBrI+Z8wuQylXio=";
}
{
idx = 3;
private = "mDXJoAJmFaERpaP6Wvll/FqoGTxZA0CgnL68dFs4XGM=";
public = "UWBRfv+VsUOLIi5iD++Zurl4wx+S+A6r39flcI3jyhA=";
}
{
idx = 4;
private = "gDINget094ZZNd2AV1lFxi3wOxbrtG74oZ/7FOEY30Q=";
public = "/aqhS+qrcRMQWdCQjnnc++hggRqU+4s26EEVlnsFcTA=";
}
{
idx = 5;
private = "SBil1s3P9Uam6zJTdm/GOjgozaoVPha1ThS49OGbO0E=";
public = "+l2Q+6Ap7y2MavVR1SR+qMQQUSp4shwNeFjcodhr+lw=";
}
];
peersFor = self: lib.remove self globalPeers;
in {
name = "wireguard-interesting-keys";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ ma27 grahamc ];
};
nodes = lib.listToAttrs (map (self: {
name = "peer${toString self.idx}";
value = {
networking.useDHCP = false;
networking.interfaces.eth1 = {
ipv4.addresses = lib.singleton {
address = "192.168.0.${toString self.idx}";
prefixLength = 24;
};
};
networking.wireguard.interfaces.wg0 = {
ips = [ "10.10.10.${toString self.idx}/24" ];
listenPort = 12345;
privateKey = self.private;
peers = map (peer: {
allowedIPs = [ "10.10.10.${toString peer.idx}/32" ];
endpoint = "192.168.0.${toString peer.idx}:12345";
publicKey = peer.public;
persistentKeepalive = 1;
}) (peersFor self);
};
};
}) globalPeers);
testScript = ''
startAll;
# Wait for wireguard-wg0 to be up
${lib.concatMapStringsSep "\n" (self: "$peer${toString self.idx}->waitForUnit(\"wireguard-wg0\");") globalPeers}
${lib.concatMapStringsSep "\n" (self: "print $peer${toString self.idx}->succeed(\"wg\");") globalPeers}
# Ping all the peers
${lib.concatStringsSep "\n"
(lib.flatten (map
(self: map
(peer: "$peer${toString self.idx}->succeed(\"ping -c1 10.10.10.${toString peer.idx}\");")
(peersFor self)
)
globalPeers
))}
'';
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment