~misterio/nix-config

29fbb06f155411e743a8d82e1486accf7d62e19c — Gabriel Fontes 1 year, 1 month ago 020b55a wip
add modpack server and helper
M hosts/celaeno/services/minecraft/default.nix => hosts/celaeno/services/minecraft/default.nix +2 -1
@@ 1,9 1,10 @@
{ inputs, pkgs, config, lib, ... }: {
{ inputs, config, lib, ... }: {
  imports = [
    inputs.nix-minecraft.nixosModules.minecraft-servers
    ./servers/proxy
    ./servers/limbo
    ./servers/survival
    ./servers/modpack
  ];

  sops.secrets.minecraft-secrets = {

A hosts/celaeno/services/minecraft/servers/modpack/default.nix => hosts/celaeno/services/minecraft/servers/modpack/default.nix +67 -0
@@ 0,0 1,67 @@
{ pkgs, lib, ... }:
let
  name = "modpack";
  version = "0.2.9";
  url = "https://github.com/Misterio77/Modpack/raw/${version}/pack.toml";

  modpack = (pkgs.fetchPackwizPack {
    inherit version url;
    pname = "modpack";
    packHash = "sha256-L5RiSktqtSQBDecVfGj1iDaXV+E90zrNEcf4jtsg+wk=";
    manifestHash = "sha256:0cblpbqwb7ikqr2lwc355mq9kymrm5dl8bxkha81r8iqdyw65w5s";
  }).addFiles {
    "mods/FabricProxy-Lite.jar" = pkgs.fetchurl rec {
      pname = "FabricProxy-Lite";
      version = "1.1.6";
      url = "https://cdn.modrinth.com/data/8dI2tmqs/versions/v${version}/${pname}-${version}.jar";
      hash = "sha256-U+nXvILXlYdx0vgomVDkKxj0dGCtw60qW22EK4FhAJk=";
    };
  };

  mcVersion = "${modpack.manifest.versions.minecraft}";
  fabricVersion = "${modpack.manifest.versions.fabric}";
  serverVersion = lib.replaceStrings [ "." ] [ "_" ] "fabric-${mcVersion}-${fabricVersion}";
in
{
  services.minecraft-servers.servers.${name} = {
    enable = true;
    package = pkgs.inputs.nix-minecraft.fabricServers.${serverVersion};
    jvmOpts = (import ../../aikar-flags.nix) "4G";
    serverProperties = {
      server-port = 25572;
      online-mode = false;
    };
    files = {
      "ops.json".value = [
        {
          uuid = "3fc76c64-b1b2-4a95-b3cf-0d7d94db2d75";
          name = "Misterio7x";
          level = 4;
        }
      ];
      "config/luckperms/luckperms.conf".format = pkgs.formats.yaml { };
      "config/luckperms/luckperms.conf".value = {
        server = name;
        storage-method = "mysql";
        data = {
          address = "127.0.0.1";
          database = "minecraft";
          username = "minecraft";
          password = "@DATABASE_PASSWORD@";
          table-prefix = "luckperms_";
        };
        messaging-service = "sql";
      };
      "config/FabricProxy-Lite.toml".value = {
        hackEarlySend = true; # Needed for luckperms
        hackOnlineMode = true;
        secret = "@VELOCITY_FORWARDING_SECRET@";
      };
      "config/yosbr" = "${modpack}/config/yosbr";
    };
    symlinks = {
      "mods" = "${modpack}/mods";
      "global_packs" = "${modpack}/global_packs";
    };
  };
}

M hosts/celaeno/services/minecraft/servers/proxy/default.nix => hosts/celaeno/services/minecraft/servers/proxy/default.nix +1 -0
@@ 19,6 19,7 @@ in
        online-mode = true;
        servers = {
          survival = "localhost:${toString servers.survival.serverProperties.server-port}";
          modpack = "localhost:${toString servers.modpack.serverProperties.server-port}";
          limbo = "localhost:${toString servers.limbo.files."settings.yml".value.bind.port}";
          try = [ "survival" ];
        };

A pkgs/add-files/default.nix => pkgs/add-files/default.nix +14 -0
@@ 0,0 1,14 @@
{ lib, runCommand }:


drv: files:
let
  addScript = (lib.concatStringsSep "\n"
    (lib.mapAttrsToList (n: v: "cp ${v} $out/${n}") files)
  );
in
(runCommand drv.name { } ''
  cp ${drv} $out
'' + addScript) // {
  inherit (drv) pname version name meta passthru;
}

M pkgs/default.nix => pkgs/default.nix +4 -1
@@ 1,4 1,4 @@
{ pkgs ? import <nixpkgs> { } }: {
{ pkgs ? import <nixpkgs> { } }: rec {

  # Packages with an actual source
  rgbdaemon = pkgs.callPackage ./rgbdaemon { };


@@ 19,4 19,7 @@

  # My slightly customized plymouth theme, just makes the blue outline white
  plymouth-spinner-monochrome = pkgs.callPackage ./plymouth-spinner-monochrome { };

  addFiles = pkgs.callPackage ./add-files { };
  fetchPackwizPack = pkgs.callPackage ./fetch-packwiz-pack { };
}

A pkgs/fetch-packwiz-pack/default.nix => pkgs/fetch-packwiz-pack/default.nix +99 -0
@@ 0,0 1,99 @@
{ lib, stdenvNoCC, fetchurl, jre, jq, moreutils, curl, runCommand }:

let
  fetchPackwizPack =
    { pname ? "packwiz-pack"
    , version ? ""
    , url
    , packHash ? lib.fakeHash
    , side ? "server"
    , manifestHash ? lib.fakeHash
    , manifest ? if manifestHash == null then null
      else
        builtins.fetchurl {
          inherit url;
          sha256 = manifestHash;
        }
    , ...
    }@args:

    stdenvNoCC.mkDerivation (finalAttrs: {
      inherit pname version;

      packwizInstaller = fetchurl rec {
        pname = "packwiz-installer";
        version = "0.5.8";
        url = "https://github.com/packwiz/${pname}/releases/download/v${version}/${pname}.jar";
        hash = "sha256-+sFi4ODZoMQGsZ8xOGZRir3a0oQWXjmRTGlzcXO/gPc=";
      };

      packwizInstallerBootstrap = fetchurl rec {
        pname = "packwiz-installer-bootstrap";
        version = "0.0.3";
        url = "https://github.com/packwiz/${pname}/releases/download/v${version}/${pname}.jar";
        hash = "sha256-qPuyTcYEJ46X9GiOgtPZGjGLmO/AjV2/y8vKtkQ9EWw=";
      };

      dontUnpack = true;

      buildInputs = [ jre jq moreutils curl ];

      buildPhase = ''
        java -jar "$packwizInstallerBootstrap" \
          --bootstrap-main-jar "$packwizInstaller" --bootstrap-no-update --no-gui \
          --side "${side}" "${url}"
      '';

      installPhase = ''
        runHook preInstall

        # Fix non-determinism
        rm env-vars -r
        jq -Sc '.' packwiz.json | sponge packwiz.json

        mkdir -p $out
        cp * -r $out/

        runHook postInstall
      '';

      passthru = {
        manifest =
          if manifest == null then null
          else builtins.fromTOML (builtins.readFile manifest);

        addFiles = files:
          let
            drv = fetchPackwizPack args;
          in
          stdenvNoCC.mkDerivation {
            inherit (drv) pname version;
            src = null;
            dontUnpack = true;
            dontConfig = true;
            dontBuild = true;
            dontFixup = true;

            installPhase = ''
              cp -as "${drv}" $out
              chmod u+w -R $out
            '' + lib.concatLines (lib.mapAttrsToList
              (name: file: ''
                mkdir -p "$out/$(dirname "${name}")"
                cp "${file}" "$out/${name}"
              '')
              files
            );

            passthru = { inherit (drv) manifest; };
          };
      };

      dontFixup = true;

      outputHashMode = "recursive";
      outputHashAlgo = "sha256";
      outputHash = packHash;
    } // args);
in
fetchPackwizPack