dev.fron.io rc / c5ad70f
packages: add mc-server Tony Olagbaiye a month ago
1 changed file(s) with 64 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 (define-module (rc packages minecraft)
1 #:use-module (rc packages)
2 #:use-module (guix gexp)
3 #:use-module (guix packages)
4 #:use-module (guix download)
5 #:use-module ((guix licenses) #:prefix license:)
6 #:use-module (guix build-system trivial)
7 #:use-module (gnu packages)
8 #:use-module (gnu packages bash)
9 #:use-module (gnu packages java)
10 #:export (minecraft-server))
11
12 (define* (make-minecraft-server
13 #:key (mc-version "1.17")
14 (mc-objectid "0a269b5f2c5b93b1712d0f5dc43b6182b9ab254e") ; sha-1 hash
15 (src-hash (base32 "0jqz7hpx7zvjj2n5rfrh8jmdj6ziqyp8c9nq4sr4jmkbky6hsfbv")))
16 (package
17 (name "minecraft-server")
18 (version mc-version)
19 (source (origin
20 (method url-fetch)
21 (uri (string-append "https://launcher.mojang.com/v1/objects/"
22 mc-objectid
23 "/server.jar"))
24 (sha256 src-hash)))
25 (build-system trivial-build-system)
26 (inputs `(("openjdk" ,openjdk16)
27 ("bash" ,bash)))
28 (arguments
29 `(#:modules ((guix build utils))
30 #:builder (begin
31 (use-modules (guix build utils)
32 (srfi srfi-26))
33 (let* ((source (assoc-ref %build-inputs "source"))
34 (patchelf (assoc-ref %build-inputs "patchelf"))
35 (openjdk (assoc-ref %build-inputs "openjdk"))
36 (bash (assoc-ref %build-inputs "bash"))
37 (output (assoc-ref %outputs "out")))
38 (mkdir-p (string-append output "/lib/minecraft"))
39 (copy-file source (string-append output "/lib/minecraft/server.jar"))
40 (mkdir-p (string-append output "/bin"))
41 ;; TODO: replace this with lisp (use install-jars, etc)
42 (let ((port (open-file (string-append output "/bin/minecraft-server") "a")))
43 (display (string-append "#!" (string-append bash "/bin/sh") "\n") port)
44 (display (string-append "exec -a minecraft-server "
45 (string-append openjdk "/bin/java ")
46 "-jar "
47 "$@ "
48 (string-append output "/lib/minecraft/server.jar ")
49 "nogui "
50 "\n") port)
51 ;; TODO: use some syntax sugar like "with-output-to-port"?
52 (close port))
53 (chmod (string-append output "/bin/minecraft-server") #o555)
54 #t))))
55 (home-page "https://minecraft.net")
56 (synopsis "Minecraft Server")
57 (description "Minecraft Server")
58 (license #f)))
59
60 (define minecraft-server
61 (make-minecraft-server))
62
63 minecraft-server