74 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
{
 | 
						|
  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/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
 | 
						|
 | 
						|
{
 | 
						|
  privateNetwork = true;
 | 
						|
  ephemeral = true;
 | 
						|
  bindMounts = {
 | 
						|
    "${projectMount}" = {
 | 
						|
      hostPath = projectDir;
 | 
						|
      isReadOnly = false;
 | 
						|
    };
 | 
						|
  };
 | 
						|
 | 
						|
  config = {
 | 
						|
    networking = {
 | 
						|
      firewall.enable = false;
 | 
						|
      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" ''
 | 
						|
        su experimentor -c "${simulationSetupScript}/bin/simulationSetup"
 | 
						|
      '')
 | 
						|
      pkgs.tcpdump
 | 
						|
    ];
 | 
						|
  };
 | 
						|
}
 |