From 845e68316d023b549b026d34e97fb031dea09bae Mon Sep 17 00:00:00 2001 From: yukkop Date: Mon, 2 Nov 2026 22:16:56 +0000 Subject: [PATCH] feat: add horizon --- nixos/system/neuro/minecraft/default.nix | 1 + nixos/system/neuro/minecraft/horizon.md | 44 +++++++ nixos/system/neuro/minecraft/horizon.nix | 83 +++++++++++++ package/default.nix | 1 + package/horizon/default.nix | 143 +++++++++++++++++++++++ test/nixos/default.nix | 3 +- test/nixos/horizon.nix | 53 +++++++++ 7 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 nixos/system/neuro/minecraft/horizon.md create mode 100644 nixos/system/neuro/minecraft/horizon.nix create mode 100644 package/horizon/default.nix create mode 100644 test/nixos/horizon.nix diff --git a/nixos/system/neuro/minecraft/default.nix b/nixos/system/neuro/minecraft/default.nix index 8bd35b29..5d618263 100644 --- a/nixos/system/neuro/minecraft/default.nix +++ b/nixos/system/neuro/minecraft/default.nix @@ -1,6 +1,7 @@ { imports = [ ./vanilla.nix + ./horizon.nix ./create-aeronautics.nix ./wow-mine-map.nix ./world-of-sosal.nix diff --git a/nixos/system/neuro/minecraft/horizon.md b/nixos/system/neuro/minecraft/horizon.md new file mode 100644 index 00000000..4e308f91 --- /dev/null +++ b/nixos/system/neuro/minecraft/horizon.md @@ -0,0 +1,44 @@ +# Horizon on neuro + +Horizon Nightly 2026-11-01 serves Minecraft Java Edition 26.3 on TCP 25569. +It runs without Java on neuro, uses `/var/lib/horizon`, and starts only when +`/var/lib/horizon/resources/registries.json` exists. The whitelist is enabled; +add an account with: + +```sh +sudo -u horizon horizon-server --dir /var/lib/horizon whitelist add PLAYER +``` + +## Prepare resources + +Horizon cannot redistribute Minecraft resources. On a computer with Minecraft +26.3 installed and played once, Java 25, its `server.jar`, and this pinned +Horizon package, prepare them locally: + +```sh +horizon-prepare --prepare \ + --server-jar /path/to/26.3/server.jar \ + --minecraft-dir /path/to/.minecraft \ + --output ./horizon-resources +``` + +The packaged command seeds its pinned exporter support files into +`$XDG_CACHE_HOME/horizon/prepare-root-nightly-2026-11-01` (or `~/.cache` when +`XDG_CACHE_HOME` is unset). Bundled support files contain no Mojang data. +Preparation imports your local game files into this writable root. Pass +`--root PATH` to seed and use another writable location. + +Copy the complete `horizon-resources` folder to neuro without changing its +contents, then grant the service read access and explicitly restart it: + +```sh +sudo install -d -o horizon -g horizon -m 0750 /var/lib/horizon/resources +sudo rsync -a --chown=horizon:horizon ./horizon-resources/ /var/lib/horizon/resources/ +sudo systemctl restart horizon +``` + +If `registries.json` is absent, systemd leaves the unit skipped instead of +crash-looping. `server.toml` and Horizon's `eula.txt` are copied to writable +state on every start; +declarative defaults remain authoritative while worlds, backups, whitelist, +operators, bans, and other generated files persist under `/var/lib/horizon`. diff --git a/nixos/system/neuro/minecraft/horizon.nix b/nixos/system/neuro/minecraft/horizon.nix new file mode 100644 index 00000000..b9725905 --- /dev/null +++ b/nixos/system/neuro/minecraft/horizon.nix @@ -0,0 +1,83 @@ +{ pkgs, ... }: +let + horizon = pkgs.hectic.horizon; + eulaFile = pkgs.writeText "horizon-eula.txt" '' + eula=true + ''; + serverConfig = pkgs.writeText "horizon-server.toml" '' + [server] + port = 25569 + online_mode = true + whitelist = true + + [world] + name = "world" + + [engine] + path = "${horizon}/libexec/horizon/horizon-engine" + resources = "/var/lib/horizon/resources" + restart_on_crash = true + + [backups] + every = "6h" + keep = 12 + + [panel] + bind = "" + allow_public = false + + [api] + bind = "127.0.0.1:8131" + token = "" + allow_public = false + ''; +in { + users.groups.horizon = {}; + users.users.horizon = { + isSystemUser = true; + group = "horizon"; + home = "/var/lib/horizon"; + }; + + environment.systemPackages = [ horizon ]; + networking.firewall.allowedTCPPorts = [ 25569 ]; + + systemd.services.horizon = { + description = "Horizon Minecraft server"; + wantedBy = [ "multi-user.target" ]; + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + unitConfig.ConditionPathExists = "/var/lib/horizon/resources/registries.json"; + environment.HORIZON_NO_UPDATE_CHECK = "1"; + restartTriggers = [ serverConfig eulaFile ]; + preStart = '' + install -m 0640 ${serverConfig} /var/lib/horizon/server.toml + install -m 0640 ${eulaFile} /var/lib/horizon/eula.txt + ''; + serviceConfig = { + User = "horizon"; + Group = "horizon"; + WorkingDirectory = "/var/lib/horizon"; + ExecStart = "${horizon}/bin/horizon-server --dir /var/lib/horizon run"; + Restart = "on-failure"; + RestartSec = 10; + KillSignal = "SIGTERM"; + TimeoutStopSec = 180; + StateDirectory = "horizon"; + StateDirectoryMode = "0750"; + UMask = "0027"; + NoNewPrivileges = true; + PrivateDevices = true; + PrivateTmp = true; + ProtectHome = true; + ProtectSystem = "strict"; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectControlGroups = true; + RestrictSUIDSGID = true; + CapabilityBoundingSet = [ "" ]; + RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ]; + }; + }; +} diff --git a/package/default.nix b/package/default.nix index 0743507a..5a749fef 100644 --- a/package/default.nix +++ b/package/default.nix @@ -191,6 +191,7 @@ in { in { inherit affine; affine-frontend-static = affine.frontendStatic; + horizon = pkgs.callPackage ./horizon {}; }) // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { with-attic-cache = pkgs.callPackage ./with-attic-cache {}; } diff --git a/package/horizon/default.nix b/package/horizon/default.nix new file mode 100644 index 00000000..b56f109b --- /dev/null +++ b/package/horizon/default.nix @@ -0,0 +1,143 @@ +{ + autoPatchelfHook, + coreutils, + fetchurl, + lib, + runtimeShell, + stdenv, + stdenvNoCC, +}: +let + version = "nightly-2026-11-01"; +in +stdenvNoCC.mkDerivation { + pname = "horizon"; + inherit version; + + src = fetchurl { + url = "https://github.com/horizon-rust/horizon/releases/download/${version}/horizon-server-linux-x86_64.tar.gz"; + hash = "sha256-xF7PQAoR6FBRWXq4YBFRin9oSE3X97gOffxXGdGcrVs="; + }; + + nativeBuildInputs = [ autoPatchelfHook ]; + buildInputs = [ stdenv.cc.cc.lib ]; + + installPhase = '' + runHook preInstall + mkdir -p \ + "$out/bin" \ + "$out/libexec/horizon" \ + "$out/share/horizon/prepare-root/mods/horizon/src/test/java/dev/horizonlab" \ + "$out/share/licenses/horizon" + install -m 0755 horizon-server horizon-engine horizon-prepare "$out/libexec/horizon/" + install -m 0644 LICENSE "$out/share/licenses/horizon/LICENSE" + install -m 0644 research-lock.json "$out/share/horizon/prepare-root/research-lock.json" + cp -R exporters "$out/share/horizon/prepare-root/exporters" + cp -R \ + mods/horizon/src/test/java/dev/horizonlab/parity \ + "$out/share/horizon/prepare-root/mods/horizon/src/test/java/dev/horizonlab/parity" + for binary in horizon-server horizon-engine; do + ln -s "$out/libexec/horizon/$binary" "$out/bin/$binary" + done + cat > "$out/bin/horizon-prepare" <<'EOF' + #!${runtimeShell} + set -eu + + executable=$(${coreutils}/bin/readlink -f "$0") + package_root=$(${coreutils}/bin/dirname "$executable") + package_root=$(${coreutils}/bin/dirname "$package_root") + support_root="$package_root/share/horizon/prepare-root" + preparer="$package_root/libexec/horizon/horizon-prepare" + root="" + saw_root=false + want_root=false + + for argument do + case "$argument" in + -h|--help|-V|--version) + exec "$preparer" "$@" + ;; + esac + if "$want_root"; then + root=$argument + want_root=false + continue + fi + case "$argument" in + --root) + saw_root=true + want_root=true + ;; + --root=*) + saw_root=true + root=''${argument#--root=} + ;; + esac + done + + if "$want_root" || { "$saw_root" && [ -z "$root" ]; }; then + exec "$preparer" "$@" + fi + if ! "$saw_root"; then + cache_home=''${XDG_CACHE_HOME:-''${HOME:?HOME is unset}/.cache} + root="$cache_home/horizon/prepare-root-${version}" + set -- --root "$root" "$@" + fi + + marker="$root/.hearth-${version}" + if [ ! -f "$marker" ]; then + ${coreutils}/bin/mkdir -p "$root" + ${coreutils}/bin/cp -R "$support_root/." "$root/" + ${coreutils}/bin/chmod -R u+w \ + "$root/research-lock.json" "$root/exporters" "$root/mods" + ${coreutils}/bin/touch "$marker" + fi + exec "$preparer" "$@" + EOF + chmod 0755 "$out/bin/horizon-prepare" + runHook postInstall + ''; + + doInstallCheck = true; + installCheckPhase = '' + runHook preInstallCheck + "$out/bin/horizon-server" --help >/dev/null + "$out/bin/horizon-server" --version | grep -F '${version}' >/dev/null + "$out/bin/horizon-engine" --help >/dev/null + "$out/bin/horizon-prepare" --help >/dev/null + "$out/bin/horizon-prepare" --version | grep -F '${version}' >/dev/null + test -f "$out/share/horizon/prepare-root/research-lock.json" + test -f "$out/share/horizon/prepare-root/exporters/manifest.json" + test -f "$out/share/horizon/prepare-root/mods/horizon/src/test/java/dev/horizonlab/parity/PrepareWorker.java" + + set +e + check_output=$(XDG_CACHE_HOME="$TMPDIR/cache" \ + "$out/bin/horizon-prepare" --check --output "$TMPDIR/missing" 2>&1) + check_status=$? + set -e + test "$check_status" -eq 1 + printf '%s\n' "$check_output" | grep -F 'is not prepared: horizon-prepare --prepare' >/dev/null + test -f "$TMPDIR/cache/horizon/prepare-root-${version}/research-lock.json" + + set +e + check_output=$("$out/bin/horizon-prepare" \ + --root "$TMPDIR/custom-root" --check --output "$TMPDIR/missing" 2>&1) + check_status=$? + set -e + test "$check_status" -eq 1 + printf '%s\n' "$check_output" | grep -F 'is not prepared: horizon-prepare --prepare' >/dev/null + test -f "$TMPDIR/custom-root/exporters/manifest.json" + runHook postInstallCheck + ''; + + passthru.sourceRevision = "4aa6854a886183440256f4f4a4a9d1ed853227a1"; + + meta = { + description = "Native Horizon server for Minecraft Java Edition 26.3"; + homepage = "https://github.com/horizon-rust/horizon"; + license = lib.licenses.mit; + mainProgram = "horizon-server"; + platforms = [ "x86_64-linux" ]; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + }; +} diff --git a/test/nixos/default.nix b/test/nixos/default.nix index 10e5c98b..806c906a 100644 --- a/test/nixos/default.nix +++ b/test/nixos/default.nix @@ -35,7 +35,8 @@ let }).config; in (import ./affine.nix { inherit system inputs self pkgs; }) // (import ./affine-chatgpt.nix { inherit system inputs pkgs; }) // - (import ./affine-frontend.nix { inherit system inputs pkgs; }) // { + (import ./affine-frontend.nix { inherit system inputs pkgs; }) // + (import ./horizon.nix { inherit system inputs pkgs; }) // { p4d-module-basic = assert enabledCfg.users.users.p4d.isSystemUser; assert enabledCfg.users.users.p4d.group == "p4d"; diff --git a/test/nixos/horizon.nix b/test/nixos/horizon.nix new file mode 100644 index 00000000..83009a47 --- /dev/null +++ b/test/nixos/horizon.nix @@ -0,0 +1,53 @@ +{ system, inputs, pkgs, ... }: +let + lib = inputs.nixpkgs.lib; + fakeHorizon = pkgs.runCommand "horizon-test-package" {} '' + mkdir -p "$out/bin" "$out/libexec/horizon" + touch "$out/bin/horizon-server" "$out/libexec/horizon/horizon-engine" + ''; + cfg = (lib.nixosSystem { + inherit system; + modules = [ + ../../nixos/system/neuro/minecraft/horizon.nix + { + nixpkgs.overlays = [ (_: _: { hectic.horizon = fakeHorizon; }) ]; + system.stateVersion = "25.05"; + } + ]; + }).config; + service = cfg.systemd.services.horizon; + serverConfig = builtins.readFile (builtins.head service.restartTriggers); + eulaFile = builtins.readFile (builtins.elemAt service.restartTriggers 1); +in { + horizon-module = + assert cfg.users.users.horizon.isSystemUser; + assert cfg.users.users.horizon.group == "horizon"; + assert service.serviceConfig.User == "horizon"; + assert service.serviceConfig.Group == "horizon"; + assert service.serviceConfig.StateDirectory == "horizon"; + assert service.serviceConfig.ProtectSystem == "strict"; + assert service.serviceConfig.ExecStart == "${fakeHorizon}/bin/horizon-server --dir /var/lib/horizon run"; + assert !lib.hasInfix "java" service.serviceConfig.ExecStart; + assert service.serviceConfig.Restart == "on-failure"; + assert service.serviceConfig.TimeoutStopSec == 180; + assert service.unitConfig.ConditionPathExists == "/var/lib/horizon/resources/registries.json"; + assert service.environment.HORIZON_NO_UPDATE_CHECK == "1"; + assert lib.elem fakeHorizon cfg.environment.systemPackages; + assert lib.hasInfix "install -m 0640" service.preStart; + assert eulaFile == "eula=true\n"; + assert !(lib.hasInfix "eula" serverConfig); + assert lib.hasInfix "port = 25569" serverConfig; + assert lib.hasInfix "online_mode = true" serverConfig; + assert lib.hasInfix "whitelist = true" serverConfig; + assert lib.hasInfix "name = \"world\"" serverConfig; + assert lib.hasInfix "/libexec/horizon/horizon-engine\"" serverConfig; + assert lib.hasInfix "resources = \"/var/lib/horizon/resources\"" serverConfig; + assert lib.hasInfix "every = \"6h\"" serverConfig; + assert lib.hasInfix "keep = 12" serverConfig; + assert lib.hasInfix "bind = \"127.0.0.1:8131\"" serverConfig; + assert cfg.networking.firewall.allowedTCPPorts == [ 25569 ]; + assert !(builtins.hasAttr "minecraft-servers" cfg.services); + pkgs.runCommand "horizon-module" {} '' + touch "$out" + ''; +}