From e2fc3e885eb1b701accc7d358e683bbfeeed3ebb Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Thu, 20 Jul 2023 12:52:48 +0200 Subject: [PATCH] Add FTB integrations Signed-off-by: Magic_RB --- flake.nix | 1 + home-manager/modules/profiles/workstation.nix | 18 +++++- .../minecraft/ftb-integrations/default.nix | 30 +++++++++ nixng/modules/minecraft-forge.nix | 26 ++++++-- .../minecraft/ftb-integrations/default.nix | 24 +++++++ .../minecraft/ftb-integrations/job.hcl | 62 +++++++++++++++++++ terranix/default.nix | 5 ++ 7 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 nixng/containers/minecraft/ftb-integrations/default.nix create mode 100644 terranix/containers/minecraft/ftb-integrations/default.nix create mode 100644 terranix/containers/minecraft/ftb-integrations/job.hcl diff --git a/flake.nix b/flake.nix index fa488e6..3d452dd 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,7 @@ nixng/containers/syncthing nixng/containers/minecraft/vanilla nixng/containers/minecraft/ftb-infinity + nixng/containers/minecraft/ftb-integrations overlays/udp-over-tcp.nix overlays/emacsclient-remote diff --git a/home-manager/modules/profiles/workstation.nix b/home-manager/modules/profiles/workstation.nix index 8a5e35d..666cf7e 100644 --- a/home-manager/modules/profiles/workstation.nix +++ b/home-manager/modules/profiles/workstation.nix @@ -3,7 +3,8 @@ let inherit (lib) concatStringsSep getExe - flip; + flip + singleton; combineWines = wines: pkgs.stdenv.mkDerivation { @@ -58,7 +59,20 @@ in }; home.packages = with pkgs; [ - prismlauncher + (prismlauncher.override { + jdks = with pkgs; [ + jdk8 + jdk11 + jdk17 + ]; + prismlauncher-unwrapped = + (prismlauncher-unwrapped.overrideAttrs (old: { + patches = singleton (pkgs.fetchurl { + url = "https://github.com/PrismLauncher/PrismLauncher/commit/603b38fa46dc61c0c5ae10a3754bcacb0201d881.diff"; + sha256 = "sha256-Q/WkDVIvlYu6lkRPjoYZOUif0TPUT6Mmxd1JR4pgdLI="; + }); + })); + }) dejavu_fonts alacritty diff --git a/nixng/containers/minecraft/ftb-integrations/default.nix b/nixng/containers/minecraft/ftb-integrations/default.nix new file mode 100644 index 0000000..55b888d --- /dev/null +++ b/nixng/containers/minecraft/ftb-integrations/default.nix @@ -0,0 +1,30 @@ +{ inputs, ... }: +{ + flake.nixngConfigurations.minecraft-ftb-integrations = inputs.nixng.nglib.makeSystem { + system = "x86_64-linux"; + name = "nixng-minecraft"; + inherit (inputs) nixpkgs; + config = + { pkgs, lib, ... }: + { + disabledModules = [ "${inputs.nixng}/modules/services/minecraft.nix" ]; + imports = [ ../../../modules/minecraft-forge.nix ../../../modules/minecraft.nix ]; + dumb-init = { + enable = true; + type.services = {}; + }; + + services.minecraft.forge = { + enable = true; + + modpackId = 107; + versionId = 6572; + modpacksChHash = "sha256-YZATEoypF+H00KuJAOdsk1Kw1aWPS1y803GKGi7Tv7Y="; + + javaPackage = pkgs.jdk11; + + eulaAccept = true; + }; + }; + }; +} diff --git a/nixng/modules/minecraft-forge.nix b/nixng/modules/minecraft-forge.nix index 21b6c8a..7caeace 100644 --- a/nixng/modules/minecraft-forge.nix +++ b/nixng/modules/minecraft-forge.nix @@ -19,6 +19,11 @@ in type = types.str; }; + javaPackage = mkOption { + type = types.package; + default = pkgs.jdk17; + }; + serverPackage = mkOption { type = types.package; readOnly = true; @@ -36,6 +41,11 @@ in type = with types; listOf str; default = []; }; + + extraFixup = mkOption { + type = types.lines; + default = ""; + }; }; config = mkIf cfg.enable { @@ -61,12 +71,18 @@ in ''; installPhase = '' - ./modpacks.ch ${toString cfg.modpackId} ${toString cfg.versionId} --auto --nojava --path $out + mkdir bin + ln -s ${pkgs.writeShellScript "noop" ''echo "cd $PWD ; java $@" > install-forge''} bin/java + export PATH=$PWD/bin:$PATH + + ./modpacks.ch ${toString cfg.modpackId} ${toString cfg.versionId} --nojava --path $out --verbose ''; fixupPhase = '' # delete useless non-reproducible data that we really don't need. A less "shotgun" cleaning is possible rm $out/version.json + + ${cfg.extraFixup} ''; }; in @@ -80,7 +96,7 @@ in mkdir -p $out/bin cp ${pkgs.writeShellScript "server.sh" '' - export PATH=${makeBinPath (with pkgs; [ coreutils findutils bash ])}:$PATH + export PATH=${makeBinPath (with pkgs; [ coreutils findutils bash cfg.javaPackage ])}:$PATH export _path=$PWD echo $0 @@ -133,9 +149,11 @@ in find ${forgeFod} -type f -printf '%P\n' | tr '\n' '\0' | xargs -0 -I {} sh -c 'linkFile "$1"' sh {} # mkdir -p "$_path/$(dirname "$1")" ; ln -s "${forgeFod}/$1" "$_path/$1" ln -s ${pkgs.writeShellScript "start.sh" '' - ${lib.getExe pkgs.jdk8} $(cat ${forgeFod}/start.sh | grep -e "java" -e jar | sed 's/^"java" \(.*\) -jar .*$/\1/') "$@" -jar forge-*.jar + ${lib.getExe cfg.javaPackage} $(cat ${forgeFod}/start.sh | grep -e "java" -e jar | sed 's/^"java" \(.*\) -jar .*$/\1/') "$@" -jar forge-*.jar ''} $_path/start.sh + # [ -f $_path/install-forge ] && bash install-forge + $_path/start.sh ''} $out/bin/server ''; @@ -148,7 +166,7 @@ in mkdir -p /var/lib/minecraft/forge cd /var/lib/minecraft/forge echo "eula=true" > eula.txt - ${cfg.serverPackage}/bin/server ${concatMapStringsSep " " (x: ''"${x}"'') cfg.extraJavaArguments} + ${pkgs.bash}/bin/bash -x ${cfg.serverPackage}/bin/server ${concatMapStringsSep " " (x: ''"${x}"'') cfg.extraJavaArguments} ''; enabled = true; }; diff --git a/terranix/containers/minecraft/ftb-integrations/default.nix b/terranix/containers/minecraft/ftb-integrations/default.nix new file mode 100644 index 0000000..e54ae80 --- /dev/null +++ b/terranix/containers/minecraft/ftb-integrations/default.nix @@ -0,0 +1,24 @@ +{ config', pkgs, elib, vars, ... }: +let + inherit (elib) + nfsVolume + nomadJob; +in +{ + resource."nomad_volume"."minecraft-ftb-integrations" = nfsVolume { + access_mode = "single-node-writer"; + volume_name = "minecraft-ftb-integrations"; + server = "blowhole.hosts.in.redalder.org"; + share = "/mnt/kyle/infrastructure/minecraft/ftb-integrations"; + mount_flags = [ "hard" "vers=4.2" "rsize=131072" "wsize=131072" "async" ]; + }; + + resource."nomad_job"."minecraft-ftb-integrations" = nomadJob { + jobspec = ./job.hcl; + vars = { + flake_ref = "${vars.flake_host}?rev=${vars.flake_rev}&ref=${vars.flake_ref}"; + flake_sha = vars.flake_sha; + store_path = config'.flake.nixngConfigurations.minecraft-ftb-integrations.config.system.build.toplevel; + }; + }; +} diff --git a/terranix/containers/minecraft/ftb-integrations/job.hcl b/terranix/containers/minecraft/ftb-integrations/job.hcl new file mode 100644 index 0000000..a9c5a77 --- /dev/null +++ b/terranix/containers/minecraft/ftb-integrations/job.hcl @@ -0,0 +1,62 @@ +variable "flake_ref" { + type = string +} + +variable "flake_sha" { + type = string +} + +variable "store_path" { + type = string +} + +job "minecraft-ftb-integrations" { + datacenters = [ "homelab-1" ] + type = "service" + + group "minecraft-ftb-integrations" { + count = 1 + + volume "minecraft-ftb-integrations" { + type = "csi" + source = "minecraft-ftb-integrations" + read_only = false + + attachment_mode = "file-system" + access_mode = "single-node-writer" + } + + network { + mode = "bridge" + port "minecraft" { + static = 25562 + to = 25565 + } + } + + + task "minecraft-ftb-integrations" { + driver = "docker" + + config { + nix_flake_ref = "${var.flake_ref}#nixngConfigurations.minecraft-ftb-integrations.config.system.build.toplevel" + nix_flake_sha = var.flake_sha + nix_flake_store_path = var.store_path + entrypoint = [ "init" ] + + ports = ["minecraft"] + } + + resources { + cpu = 4096 + memory = 6500 + } + + volume_mount { + volume = "minecraft-ftb-integrations" + destination = "/var/lib/minecraft/forge" + read_only = false + } + } + } +} diff --git a/terranix/default.nix b/terranix/default.nix index f4ccb96..da03925 100644 --- a/terranix/default.nix +++ b/terranix/default.nix @@ -111,6 +111,11 @@ in source = ./containers/minecraft/ftb-infinity; }; + module."minecraft-ftb-integrations" = elib.terraformModule { + name = "nfs-csi"; + source = ./containers/minecraft/ftb-integrations; + }; + module."altra" = elib.terraformModule { name = "altra"; source = ./altra.nix;