terracotta: init at 0.3.13 (#456495)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
From d5680fd01964755c39c0fd5c128c972d9bd9a044 Mon Sep 17 00:00:00 2001
|
||||
From: Moraxyc <i@qaq.li>
|
||||
Date: Tue, 28 Oct 2025 16:57:58 +0800
|
||||
Subject: [PATCH 1/2] nix: read timestamp from SOURCE_DATE_EPOCH
|
||||
|
||||
---
|
||||
timestamp/src/lib.rs | 8 ++------
|
||||
1 file changed, 2 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/timestamp/src/lib.rs b/timestamp/src/lib.rs
|
||||
index 142abf3..3935272 100644
|
||||
--- a/timestamp/src/lib.rs
|
||||
+++ b/timestamp/src/lib.rs
|
||||
@@ -1,15 +1,11 @@
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
-use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[proc_macro]
|
||||
pub fn compile_time(_: TokenStream) -> TokenStream {
|
||||
lazy_static::lazy_static! {
|
||||
- static ref TIMESTAMP: u128 = SystemTime::now()
|
||||
- .duration_since(UNIX_EPOCH)
|
||||
- .unwrap()
|
||||
- .as_millis();
|
||||
+ static ref TIMESTAMP: u128 = std::fs::read_to_string("SOURCE_DATE_EPOCH").ok().and_then(|s| s.trim().parse().ok()).unwrap_or(0);
|
||||
}
|
||||
|
||||
return format!("({}u128)", *TIMESTAMP).parse().unwrap();
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+}
|
||||
--
|
||||
2.51.0
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
From 8c8ef3bcdbebb11999a6a229de2d537c9a0110a9 Mon Sep 17 00:00:00 2001
|
||||
From: Moraxyc <i@qaq.li>
|
||||
Date: Tue, 28 Oct 2025 17:01:29 +0800
|
||||
Subject: [PATCH 2/2] nix: use easytier from nix input
|
||||
|
||||
---
|
||||
build.rs | 3 ++-
|
||||
src/easytier.rs | 31 +++----------------------------
|
||||
2 files changed, 5 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/build.rs b/build.rs
|
||||
index dc6e117..df454d9 100644
|
||||
--- a/build.rs
|
||||
+++ b/build.rs
|
||||
@@ -12,7 +12,8 @@ fn main() {
|
||||
println!("cargo::rerun-if-changed=Cargo.toml");
|
||||
|
||||
println!("cargo::rerun-if-changed=.easytier");
|
||||
- download_easytier();
|
||||
+ // Use easytier from nix
|
||||
+ // download_easytier();
|
||||
|
||||
sevenz_rust2::compress_to_path(
|
||||
"web",
|
||||
diff --git a/src/easytier.rs b/src/easytier.rs
|
||||
index c657a08..38e6abd 100644
|
||||
--- a/src/easytier.rs
|
||||
+++ b/src/easytier.rs
|
||||
@@ -14,12 +14,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
-static EASYTIER_ARCHIVE: (&str, &str, &[u8]) = (
|
||||
- include_str!(env!("TERRACOTTA_ET_ENTRY_CONF")),
|
||||
- include_str!(env!("TERRACOTTA_ET_CLI_CONF")),
|
||||
- include_bytes!(env!("TERRACOTTA_ET_ARCHIVE")),
|
||||
-);
|
||||
-
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref FACTORY: EasytierFactory = create();
|
||||
}
|
||||
@@ -36,32 +30,13 @@ pub struct Easytier {
|
||||
}
|
||||
|
||||
fn create() -> EasytierFactory {
|
||||
- let _ = fs::create_dir_all(&*EASYTIER_DIR);
|
||||
-
|
||||
logging!(
|
||||
"Easytier",
|
||||
- "Releasing easytier to {}",
|
||||
- &*EASYTIER_DIR.to_string_lossy()
|
||||
+ "Using path @TERRACOTTA_ET_PATH@ (Nix)."
|
||||
);
|
||||
|
||||
- sevenz_rust2::decompress(Cursor::new(EASYTIER_ARCHIVE.2.to_vec()), &*EASYTIER_DIR)
|
||||
- .map_err(|e| Error::other(e.to_string()))
|
||||
- .unwrap();
|
||||
-
|
||||
- let exe: PathBuf = Path::join(&EASYTIER_DIR, EASYTIER_ARCHIVE.0);
|
||||
- let cli: PathBuf = Path::join(&EASYTIER_DIR, EASYTIER_ARCHIVE.1);
|
||||
- #[cfg(target_family = "unix")]
|
||||
- {
|
||||
- use std::os::unix::fs::PermissionsExt;
|
||||
-
|
||||
- let mut permissions = fs::metadata(exe.clone()).unwrap().permissions();
|
||||
- permissions.set_mode(permissions.mode() | 0o100);
|
||||
- fs::set_permissions(exe.clone(), permissions).unwrap();
|
||||
-
|
||||
- let mut permissions = fs::metadata(cli.clone()).unwrap().permissions();
|
||||
- permissions.set_mode(permissions.mode() | 0o100);
|
||||
- fs::set_permissions(cli.clone(), permissions).unwrap();
|
||||
- }
|
||||
+ let exe: PathBuf = PathBuf::from("@TERRACOTTA_ET_EXE@");
|
||||
+ let cli: PathBuf = PathBuf::from("@TERRACOTTA_ET_CLI@");
|
||||
EasytierFactory { exe, cli }
|
||||
}
|
||||
|
||||
--
|
||||
2.51.0
|
||||
|
||||
Generated
+3589
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,103 @@
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
rustPlatform,
|
||||
fetchFromGitHub,
|
||||
easytier,
|
||||
replaceVars,
|
||||
imagemagick,
|
||||
nix-update-script,
|
||||
}:
|
||||
|
||||
rustPlatform.buildRustPackage (finalAttrs: {
|
||||
pname = "terracotta";
|
||||
version = "0.3.13";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "burningtnt";
|
||||
repo = "Terracotta";
|
||||
tag = "v${finalAttrs.version}";
|
||||
hash = "sha256-2Ghn/f0EaWOLhabxY7WBEesB/28fojreXs1ve1PvpdM=";
|
||||
# populate values that require us to use git. By doing this in postFetch we
|
||||
# can delete .git afterwards and maintain better reproducibility of the src.
|
||||
leaveDotGit = true;
|
||||
postFetch = ''
|
||||
cd "$out"
|
||||
echo $(git log -1 --pretty=%ct)"000" > $out/SOURCE_DATE_EPOCH
|
||||
find "$out" -name .git -print0 | xargs -0 rm -rf
|
||||
'';
|
||||
};
|
||||
|
||||
patches = [
|
||||
# For reproducibility
|
||||
./0001-nix-read-timestamp-from-SOURCE_DATE_EPOCH.patch
|
||||
# Use easytier from inputs instead
|
||||
(replaceVars ./0002-nix-use-easytier-from-nix-input.patch {
|
||||
TERRACOTTA_ET_PATH = easytier;
|
||||
TERRACOTTA_ET_EXE = "${easytier}/bin/easytier-core";
|
||||
TERRACOTTA_ET_CLI = "${easytier}/bin/easytier-cli";
|
||||
})
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
ln -s ${./Cargo.lock} Cargo.lock
|
||||
''
|
||||
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
|
||||
daemon_plist="$out/Library/LaunchAgents/org.nixos.terracotta.daemon.plist"
|
||||
substituteInPlace src/main.rs \
|
||||
--replace-fail '/Library/LaunchAgents/net.burningtnt.terracotta.daemon.plist' "$daemon_plist"
|
||||
'';
|
||||
|
||||
nativeBuildInputs = [ imagemagick ];
|
||||
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
|
||||
env = {
|
||||
# terracotta depends on nightly features
|
||||
RUSTC_BOOTSTRAP = 1;
|
||||
TERRACOTTA_ET_VERSION = "v${easytier.version}";
|
||||
TERRACOTTA_VERSION = finalAttrs.version;
|
||||
};
|
||||
|
||||
postInstall =
|
||||
lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||
install -Dm0644 build/linux/terracotta.desktop -t $out/share/applications
|
||||
|
||||
for n in 16 32 48 64 96 128 256
|
||||
do
|
||||
size=$n"x"$n
|
||||
mkdir -p $out/share/icons/hicolor/$size/apps
|
||||
magick build/linux/icon.png -resize $size $out/share/icons/hicolor/$size/apps/terracotta.png
|
||||
done
|
||||
''
|
||||
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
|
||||
mkdir -p $out/{Library/LaunchAgents,Applications}
|
||||
|
||||
cp -r build/macos/terracotta.app $out/Applications/
|
||||
ln -sr $out/bin/terracotta $out/Applications/terracotta.app/Contents/MacOS/terracotta
|
||||
|
||||
cat > "$daemon_plist" <<EOF
|
||||
${lib.generators.toPlist { escape = true; } {
|
||||
Label = "org.nixos.terracotta.daemon";
|
||||
ProgramArguments = [
|
||||
"@TERRACOTTA_BIN@"
|
||||
"--daemon"
|
||||
];
|
||||
KeepAlive = true;
|
||||
}}
|
||||
EOF
|
||||
substituteInPlace "$daemon_plist" \
|
||||
--replace-fail '@TERRACOTTA_BIN@' "$out/bin/terracotta"
|
||||
'';
|
||||
|
||||
passthru.updateScript = nix-update-script { extraArgs = [ "--generate-lockfile" ]; };
|
||||
|
||||
meta = {
|
||||
description = "Terracotta provides out-of-the-box multiplayer support for Minecraft";
|
||||
homepage = "https://github.com/burningtnt/Terracotta";
|
||||
changelog = "https://github.com/burningtnt/Terracotta/releases/tag/${finalAttrs.src.tag}";
|
||||
license = lib.licenses.agpl3Plus;
|
||||
maintainers = with lib.maintainers; [ moraxyc ];
|
||||
mainProgram = "terracotta";
|
||||
};
|
||||
})
|
||||
Reference in New Issue
Block a user