From f1da50c5c0083b84ae8656edc5c82d0dfbbc7a7b Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Fri, 9 Oct 2020 01:20:40 +0200 Subject: [PATCH] update Hash2Pub testbed container and make it more configurable --- nixos/Hash2PubTestbed.nix | 52 +++++++++++++++++++++++++-------------- nixos/configuration.nix | 7 +++++- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/nixos/Hash2PubTestbed.nix b/nixos/Hash2PubTestbed.nix index dec7d72..1efbfe6 100644 --- a/nixos/Hash2PubTestbed.nix +++ b/nixos/Hash2PubTestbed.nix @@ -1,10 +1,20 @@ -{ config, pkgs, ... }: +{ config, pkgs, experimentUid ? 1000, ... }: let projectDir = "/home/spiollinux/Seafile/Studium/Semester11/INF-PM-FP-ANW"; projectPath = builtins.toPath projectDir; projectMount = "/mnt/project"; - shell = import (projectDir + "/Hash2Pub/shell.nix"); + shell = (import (projectDir + "/Hash2Pub/default.nix") {}).shell; + simulationSetupScript = pkgs.writeShellScriptBin "simulationSetup" '' + # make cabal-install work offline + mkdir $HOME/.cabal + echo "" > $HOME/.cabal/config + + # run simulation script within the shell + ${pkgs.nix}/bin/nix-shell ${shell.drvPath} --command "cd ${projectMount} && bash ./build/simulationrunner.sh 2>&1" + ''; + instanceData = builtins.fromJSON (builtins.readFile "${projectDir}/simulationData/inputs/generated/instances_sample.json"); + in { @@ -17,30 +27,36 @@ in config = { networking = { firewall.enable = false; - interfaces.lo.ipv6.addresses = [ - {address = "2604:a880:800:10::34e1:d001"; prefixLength = 0;} - {address = "2001:41d0:2:c0af::15"; prefixLength = 0;} - {address = "2a01:e0a:23a:5600::2"; prefixLength = 64;} - ]; - extraHosts = '' - 2604:a880:800:10::34e1:d001 animalliberation.social - 2001:41d0:2:c0af::15 hostux.social - 2a01:e0a:23a:5600::2 social.imirhil.fr - ''; + interfaces.lo.ipv6.addresses = + builtins.map (inst: {address = inst.ip; prefixLength = 0;}) instanceData; + extraHosts = + pkgs.lib.concatMapStringsSep "\n" (inst: "${inst.ip} ${inst.hostname}") instanceData; }; + # avoid permission problems with project builds + users.users.experimentor = { + uid = experimentUid; + isNormalUser = true; + }; + + # adjust open file limits + security.pam.loginLimits = [{ + domain = "*" + ; type = "-" + ; item = "nofile" + ; value = "50000" + ;}]; + environment.systemPackages = [ pkgs.netcat pkgs.iproute pkgs.tmux pkgs.ping + pkgs.lsof + pkgs.iftop (pkgs.writeShellScriptBin "doSimulation" '' - # make cabal-install work offline - mkdir $HOME/.cabal - echo "" > $HOME/.cabal/config - - # run simulation script within the shell - ${pkgs.nix}/bin/nix-shell ${shell.drvPath} --command "cd ${projectMount} && bash simtest.sh" + su experimentor -c "${simulationSetupScript}/bin/simulationSetup" '') + pkgs.tcpdump ]; }; } diff --git a/nixos/configuration.nix b/nixos/configuration.nix index 3a4461b..4f1d773 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -198,7 +198,12 @@ in # declarative containers containers = { - hash2PubSim = import ./Hash2PubTestbed.nix {inherit pkgs config;}; + hash2PubSim = import ./Hash2PubTestbed.nix + { + inherit pkgs config; + experimentUid = config.users.users.spiollinux.uid; + projectDir = "/home/spiollinux/Seafile/Studium/Semester11/INF-PM-FP-ANW"; + }; }; # stop NetworkManager from managing virtual interfaces