Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: add an offline mode. #50

Open
LEXUGE opened this issue Aug 9, 2020 · 20 comments
Open

Feature Request: add an offline mode. #50

LEXUGE opened this issue Aug 9, 2020 · 20 comments
Assignees

Comments

@LEXUGE
Copy link

LEXUGE commented Aug 9, 2020

Hi, I am a packager for NixOS (https://www.nixos.org), and I am trying to package the fabric loader (specifically server side) here.
However, due to the certain constraints from NixOS packaging process, there would be no network during it.
I am wondering if all other parts like vanilla server are present, how can I force installer not to access Internet?
Or, can we have an offline mode?

Thanks in advance!

@modmuss50
Copy link
Member

Yes, this is something I do want to do! Ive been saying for a long while that ill do it, but havent gotten around to it just yet.

One limitation is that it would still require a network connection to download stuff that isnt ours (minecraft its self). Would this be an issue for you? or do you already have the minecraft jar?

@LEXUGE
Copy link
Author

LEXUGE commented Aug 13, 2020

Yes, this is something I do want to do! Ive been saying for a long while that ill do it, but havent gotten around to it just yet.

One limitation is that it would still require a network connection to download stuff that isnt ours (minecraft its self). Would this be an issue for you? or do you already have the minecraft jar?

No, it is perfectly fine for Nix to have minecraft jar and whatever resources on the Internet. The only limitation Nix has is that no Internet should be available during build/install phase.
Thank you very much!

@modmuss50 modmuss50 self-assigned this Aug 19, 2020
@kloenk
Copy link

kloenk commented Aug 30, 2020

Seems related to #37

Should I close #37 as its basically the same (but I only asked for server code)

@kloenk
Copy link

kloenk commented Aug 30, 2020

Yes, this is something I do want to do! Ive been saying for a long while that ill do it, but havent gotten around to it just yet.
One limitation is that it would still require a network connection to download stuff that isnt ours (minecraft its self). Would this be an issue for you? or do you already have the minecraft jar?

No, it is perfectly fine for Nix to have minecraft jar and whatever resources on the Internet. The only limitation Nix has is that no Internet should be available during build/install phase.
Thank you very much!

This answer confuses me. What we from nix want is to have a directory where we can put things like the minecrat.jar, and give this directory to fabric installer, which then has no way of connecting to the internet.

@dali99
Copy link

dali99 commented Sep 5, 2020

I was also looking into adding fabric support to nixpkgs today. Good to know this is on someone's radar already.

Fabric devs, feel free to ask any questions.

One limitation is that it would still require a network connection to download stuff that isnt ours (minecraft its self). Would this be an issue for you? or do you already have the minecraft jar?

The steps in nix would be something like:

  1. Nix downloads server.jar from minecraft.net (already does this)
  2. Nix downloads fabric-loader, mappings for the correct minecraft version, and an offline capable fabric-installer.

Nix will download these files from the url humans give it, and will check that the file matches a human provided checksum.

  1. Nix will move all the dependencies to right locations, and run fabric installer.
  2. Nix will move the output of fabric installer to the right location

fabric-installer should yell about missing files and such but can't ever access the internet.

@modmuss50
Copy link
Member

I am about 1/2 way through the changes. I will comment on this issue once I have something ready to test.

@dali99
Copy link

dali99 commented Apr 3, 2021

Hey Ive been looking into this again, is there any information you might need? Not to rush or seem demanding in any way.

Alternatively if you don't think this will get added, maybe could point me to some information on how to manually install fabric without the installer?

Thanks

@Minecon724
Copy link

any updates?

@dali99
Copy link

dali99 commented Jan 14, 2022

Specifically for nix there is one option available.

Created by someone who wants to minimize their internet presence, and updated/changed a little by me:

default.nix:

{ callPackage, writeTextFile, writeShellScriptBin, minecraft-server, jre_headless }:

let
  loader = callPackage ./generate-loader.nix {};
  log4j = writeTextFile {
    name = "log4j.xml";
    text = ''
      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="WARN" packages="com.mojang.util">
          <Appenders>
              <Console name="SysOut" target="SYSTEM_OUT">
                  <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
              </Console>
              <Queue name="ServerGuiConsole">
                  <PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
              </Queue>
              <RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
                  <PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
                  <Policies>
                      <TimeBasedTriggeringPolicy />
                      <OnStartupTriggeringPolicy />
                  </Policies>
                  <DefaultRolloverStrategy max="1000"/>
              </RollingRandomAccessFile>
          </Appenders>
          <Loggers>
              <Root level="info">
                  <filters>
                      <MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL" />
                  </filters>
                  <AppenderRef ref="SysOut"/>
                  <AppenderRef ref="File"/>
                  <AppenderRef ref="ServerGuiConsole"/>
              </Root>
          </Loggers>
      </Configuration>
    '';
  };
in
writeShellScriptBin "minecraft-server" ''
  echo "serverJar=${minecraft-server}/lib/minecraft/server.jar" >> fabric-server-launcher.properties
  exec ${jre_headless}/bin/java -Dlog4j.configurationFile=${log4j} $@ -jar ${loader} nogui

generate-loader.nix:

{ lib, fetchurl, stdenv, unzip, zip, jre_headless }:

let
  lock = import ./lock.nix;
  libraries = lib.forEach lock.libraries fetchurl;
in
stdenv.mkDerivation {
  name = "fabric-server-launch.jar";
  nativeBuildInputs = [ unzip zip jre_headless ];

  libraries = libraries;

  buildPhase = ''
    for i in $libraries; do
      unzip -o $i
    done

    cat > META-INF/MANIFEST.MF << EOF
    Manifest-Version: 1.0
    Main-Class: net.fabricmc.loader.impl.launch.server.FabricServerLauncher
    Name: org/objectweb/asm/
    Implementation-Version: 9.2
    EOF

    cat > fabric-server-launch.properties << EOF
    launch.mainClass=net.fabricmc.loader.impl.launch.knot.KnotServer
    EOF
  '';

  installPhase = ''
    jar cmvf META-INF/MANIFEST.MF "server.jar" .
    zip -d server.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA'
    cp server.jar "$out"
  '';

  phases = [ "buildPhase" "installPhase" ];
}

lock.nix:

    {
      mainClass = "net.fabricmc.loader.impl.launch.knot.KnotServer";
      libraries = [
        { name = "tiny-mappings-parser-0.3.0+build.17.zip"; sha256 = "19kvhxfk5v01f2rvl7j02vqhn3nd2bh5jsgbk44rpzqv9f6074db"; url = "https://maven.fabricmc.net/net/fabricmc/tiny-mappings-parser/0.3.0+build.17/tiny-mappings-parser-0.3.0+build.17.jar"; }
        { name = "sponge-mixin-0.10.7+mixin.0.8.4.zip"; sha256 = "18m5wksd9vjp676cxapkggnz8s3f8j89phln8gy5n8vxlrli8n0d"; url = "https://maven.fabricmc.net/net/fabricmc/sponge-mixin/0.10.7+mixin.0.8.4/sponge-mixin-0.10.7+mixin.0.8.4.jar"; }
        { name = "tiny-remapper-0.6.0.zip"; sha256 = "1ynjfxg7cj9rd9c4l450w7yp20p2csjdpnk3mcx5bdkjzhbgvgzf"; url = "https://maven.fabricmc.net/net/fabricmc/tiny-remapper/0.6.0/tiny-remapper-0.6.0.jar"; }
        { name = "access-widener-2.0.1.zip"; sha256 = "0a7s4x6dbaa9p59ps7pidzwrs0xwy5i17s35xrgh58i26szlsaxm"; url = "https://maven.fabricmc.net/net/fabricmc/access-widener/2.0.1/access-widener-2.0.1.jar"; }
        { name = "asm-9.2.zip"; sha256 = "1xa7kccwmcqcdw1xly6n2frzhk56m8ma9v7h764g73ckf56zxm5r"; url = "https://maven.fabricmc.net/org/ow2/asm/asm/9.2/asm-9.2.jar"; }
        { name = "asm-analysis-9.2.zip"; sha256 = "1i1kyirizs5sm2v0f06sdz86mbmyn61vjr9d9p8p5h1i2x9bx3w7"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar"; }
        { name = "asm-commons-9.2.zip"; sha256 = "19p04mr14ahndba65v4krbvf4p5syf8wz0fp5i9bnf5270qyak5y"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar"; }
        { name = "asm-tree-9.2.zip"; sha256 = "04g0zb7v65iz4k2m2grdpbv8jjryrzkkw7ww23yfp94i6399pgxa"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar"; }
        { name = "asm-util-9.2.zip"; sha256 = "16759v4hh3ijpf4cglrxybz29x2hiylhsa388y09m2mf679kqnzz"; url = "https://maven.fabricmc.net/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar"; }
        { name = "intermediary-1.18.1.zip"; sha256 = "1rfz2gazvnivn6hlqiyjpiaycz8va87n5czy1p6w3lnrlfggj2i9"; url = "https://maven.fabricmc.net/net/fabricmc/intermediary/1.18.1/intermediary-1.18.1.jar"; }
        { name = "fabric-loader-0.12.12.zip"; sha256 = "070dpcp7kcj4xr75wp1j6pb1bgfzllwg8xmqk3sk79jfqiqwzizw"; url = "https://maven.fabricmc.net/net/fabricmc/fabric-loader/0.12.12/fabric-loader-0.12.12.jar"; }
      ];
    }

with lock.nix generated by

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash curl jq
curl https://meta.fabricmc.net/v2/versions/loader/1.18.1/0.12.12/server/json \
| jq -r '
  .mainClass,
  (.libraries[]
  | .url as $url
  | .name | split(":") as [$dir, $name, $version]
  |"\($name)-\($version).zip|\($url)\($dir|sub("\\.";"/";"g"))/\($name)/\($version)/\($name)-\($version).jar"
  )' \
| {
    echo '{'
    read mainClass;
    echo "  mainClass = \"$mainClass\";"
    echo "  libraries = ["
    while IFS="|" read name url; do
        hash=$(nix-prefetch-url $url);
        echo "    { name = \"$name\"; sha256 = \"$hash\"; url = \"$url\"; }"
    done
    echo "  ];"
    echo '}'
}

while this is a package you can just swap into the minecraft-server module, it's a little bit cursed... So I'm hoping to get a better solution at some point as well.

@Minecon724
Copy link

i have no idea whats "nix" and i dont use it

@frqnny
Copy link

frqnny commented Jan 14, 2022

this is only about nix so why are you asking about it 😂

@Minecon724
Copy link

Minecon724 commented Jan 14, 2022

this is only about nix so why are you asking about it 😂

oh ok for some reason online-mode setting is ignored on my server (its always on)

@soupglasses
Copy link

Has there been any updates on this? @modmuss50 @dali99

@Infinidoge
Copy link

While this doesn't solve the problem at the root of this issue, I've gone ahead and packaged (pretty much) all versions of Fabric servers for Nix here: https://github.com/Infinidoge/nix-minecraft

If an offline mode is added, that would make the packaging much easier, though.

@Atemo-C
Copy link

Atemo-C commented Jul 11, 2024

Two years later bump, I guess.

I am trying to declaratively set up a Minecraft server on NixOS. I have everything configured properly, and it works fine on Vanilla, but I have no option to use Fabric as it is not packaged yet; Made harder by the lack of an offline mode.

services.minecraft-server.package = pkgs.minecraft-server.fabic-1-21;

services.minecraft-sever.mods.fabric = [
	"https://modrinth.com/mod/lithium"
	"https://modrinth.com/mod/ferrite-core"
	"https://modrinth.com/mod/modernfix"
	"https://modrinth.com/mod/krypton"
	"https://modrinth.com/mod/debugify"
	"https://modrinth.com/mod/c2me-fabric"
	"https://modrinth.com/plugin/lmd"
	"https://modrinth.com/mod/servercore"
	"…"
];

Ahh… How beautiful a Nixed Fabric Minecraft server could be…


On a side note, running a Fabric Minecraft server the "normal" way works just fine. At least there is that. ¯\_(ツ)_/¯

@modmuss50
Copy link
Member

For the server everyone should be using the server launcher from: https://fabricmc.net/use/server/ Using the installer is not the reccomended way to setup a server anymore.

I know its not technically offline, but its never going to be able to be (as we cannot bundle the minecraft server). It should work better for your usecase though.

@Infinidoge
Copy link

Atemo: you might like https://github.com/Infinidoge/nix-minecraft :)
It packages Fabric, and has a module for managing Minecraft servers.

modmuss: Does it bundle Fabric's libraries? I think that ends up being the biggest hurdle, since for the server jar you could just download it yourself and transfer it with the installer, but getting libraries is a pain. I have this solved in nix-minecraft by using api.fabricmc.net to get the libraries and fetching them myself.

@modmuss50
Copy link
Member

modmuss50 commented Jul 11, 2024

Does it bundle Fabric's libraries?

No, it doesnt. Would it help if there was a command line argument to download the libraries and then exit? The biggest struggle with adding an offline installer is finding a good way to actually generate distribute it. Its not impossible by any means, just needs some consideration.

@Atemo-C
Copy link

Atemo-C commented Jul 11, 2024

Atemo: you might like https://github.com/Infinidoge/nix-minecraft :) It packages Fabric, and has a module for managing Minecraft servers.

I've looked at it, but I try to avoid using Flakes whenever possible. Still a nice project.

@Infinidoge
Copy link

The repo has flake-compat, so you should be able to import it in a non-flakes configuration. (I should add that to the readme)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants