summaryrefslogtreecommitdiff
path: root/tw/packages/games.scm
diff options
context:
space:
mode:
authorTimo Wilken2023-02-25 21:13:11 +0100
committerTimo Wilken2023-02-25 21:13:11 +0100
commit78fc34b83d9d5308353c2df4b4bd6b09b8f90c18 (patch)
treed722fa54e6c9ab858601319cb83e8aab15819b04 /tw/packages/games.scm
parent1fcc1b28bbdb2bdeb0300899baddd075c9f407a8 (diff)
Package Kerbal Space Program
Diffstat (limited to 'tw/packages/games.scm')
-rw-r--r--tw/packages/games.scm166
1 files changed, 164 insertions, 2 deletions
diff --git a/tw/packages/games.scm b/tw/packages/games.scm
index abe855ad..98c18ff4 100644
--- a/tw/packages/games.scm
+++ b/tw/packages/games.scm
@@ -1,14 +1,26 @@
(define-module (tw packages games)
- #:use-module (guile) ; for `geiser-eval-buffer-and-go' to work properly
+ #:use-module ((srfi srfi-26) #:select (cut))
#:use-module ((ice-9 string-fun) #:select (string-replace-substring))
#:use-module (gnu packages audio)
+ #:use-module (gnu packages base)
+ #:use-module (gnu packages bash)
#:use-module (gnu packages compression)
+ #:use-module (gnu packages elf)
+ #:use-module (gnu packages fonts)
#:use-module (gnu packages fontutils)
+ #:use-module (gnu packages freedesktop)
+ #:use-module (gnu packages gcc)
+ #:use-module (gnu packages gl)
+ #:use-module (gnu packages glib)
+ #:use-module (gnu packages gtk)
#:use-module (gnu packages guile)
#:use-module (gnu packages image)
+ #:use-module (gnu packages linux)
#:use-module (gnu packages pkg-config)
+ #:use-module (gnu packages pulseaudio)
#:use-module (gnu packages sdl)
#:use-module (gnu packages textutils)
+ #:use-module (gnu packages xorg)
#:use-module (guix build utils)
#:use-module (guix build-system copy)
#:use-module (guix build-system gnu)
@@ -17,7 +29,9 @@
#:use-module (guix gexp)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix modules)
- #:use-module (guix packages))
+ #:use-module (guix packages)
+ #:use-module (nonguix build-system binary)
+ #:use-module ((nonguix licenses) #:prefix nonguix-license:))
(define-public simutrans-pak128
;; Install paks as propagated-inputs of simutrans, so they go in
@@ -168,3 +182,151 @@ directory as assets from the base game, such as music files.")
;; TODO: package Widelands 1.1
;; https://github.com/widelands/widelands/releases/tag/v1.1
+
+;; $ guix download KSP-Breaking_Ground_Expansion-en-us-lin-1.7.1.zip
+;; /gnu/store/mlrsbl99rjmx0ss7im9d26rnxg98mb04-KSP-Breaking_Ground_Expansion-en-us-lin-1.7.1.zip
+;; 0k3agr1ycdk8cll54wn63r6hdzbjpcj7wsjl003wkpza410x4ja8
+
+;; TODO: package Breaking Ground DLC
+
+(define-public kerbal-space-program
+ (package
+ (name "kerbal-space-program")
+ (version "1.12.5")
+ (source (origin
+ (method url-fetch)
+ (uri (string-append "file://" (getenv "HOME")
+ "/installers/games/ksp-linux-"
+ version ".zip"))
+ (sha256 (base32 "0rxh25wmx4bpxdjjmci77356j60d37w6p1rvh72m38z41fyyzq0a"))))
+ (build-system binary-build-system)
+ ;; Linux Installer instructions from KSP_linux/readme.txt:
+ ;; * Uncompress the file provided
+ ;; * Place the contents of the file in your KSP installation directory
+ ;; * Run the script called dlc-mhe-[lang].command ; this doesn't seem to exist...
+ (supported-systems '("x86_64-linux"))
+ (arguments
+ `(#:patchelf-plan
+ '(("KSPLauncher_Data/Plugins/x86_64/ScreenSelector.so"
+ ("glibc" "gcc:lib" "mesa" "gtk+" "atk" "glib" "pango"
+ "gdk-pixbuf" "cairo" "freetype" "fontconfig"))
+ ("UnityPlayer.so"
+ ;; Unity tries to load the following dynamically (even though they
+ ;; don't show up in ldd output). Not sure what it does on Wayland.
+ ("glibc" "gcc:lib" "mesa" "libx11" "libxext" "libxcursor"
+ "libxinerama" "libxi" "libxrandr" "libxscrnsaver" "libxxf86vm"
+ "pulseaudio" "alsa-lib" "eudev"))
+ ;; Mesa doesn't show up in ldd output, but is loaded by the launcher
+ ;; and KSP itself.
+ ,@(map (cut list <> '("glibc" "gcc:lib" "mesa"))
+ '("KSPLauncher.x86_64"
+ "KSPLauncher_Data/MonoBleedingEdge/x86_64/libMonoPosixHelper.so"
+ "KSPLauncher_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so"
+ "KSP.x86_64"
+ "KSP_Data/MonoBleedingEdge/x86_64/libMonoPosixHelper.so"
+ "KSP_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so"
+ "KSP_Data/Plugins/libkeyboard.so"
+ "KSP_Data/Plugins/liblingoona.grammar.kerbal.so"
+ "KSP_Data/Plugins/libsteam_api.so")))
+ #:install-plan
+ '(("./" "share/kerbal-space-program/"))
+ #:phases
+ ,#~(modify-phases %standard-phases
+ (add-after 'patchelf 'add-origin-to-rpath
+ ;; KSP.x86_64 needs to be able to find UnityPlayer.so.
+ (lambda _
+ (use-modules (ice-9 popen))
+ (let* ((patchelf #+(file-append patchelf "/bin/patchelf"))
+ (port (open-pipe* OPEN_READ patchelf "--print-rpath" "KSP.x86_64"))
+ (rpath (symbol->string (read port)))
+ (new-rpath (string-append rpath ":$ORIGIN")))
+ (close-pipe port)
+ (invoke patchelf "--set-rpath" new-rpath "KSP.x86_64"))))
+ (add-after 'install 'wrap-game
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (wrap-program (search-input-file
+ outputs "share/kerbal-space-program/KSP.x86_64")
+ #:sh (search-input-file inputs "/bin/sh")
+ `("LC_ALL" "" = ("C"))
+ `("PATH" ":" =
+ (;; KSP runs "sh -c 'setxkbmap -print'" on startup.
+ ,(string-append (assoc-ref inputs "bash-minimal") "/bin")
+ ,(string-append (assoc-ref inputs "setxkbmap") "/bin")
+ ;; Hopefully, this will allow opening web links in the main menu.
+ ,(string-append (assoc-ref inputs "xdg-utils") "/bin"))))))
+ (add-after 'install 'wrap-launcher
+ ;; The launcher calls out to xdg-open and uname for some actions.
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (wrap-program (search-input-file
+ outputs "share/kerbal-space-program/KSPLauncher.x86_64")
+ #:sh (search-input-file inputs "/bin/sh")
+ `("PATH" ":" =
+ (,(string-append (assoc-ref inputs "xdg-utils") "/bin")
+ ,(string-append (assoc-ref inputs "coreutils") "/bin"))))))
+ (add-after 'install 'install-overlay-launcher
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (let ((out (assoc-ref outputs "out")))
+ (mkdir-p (string-append out "/bin"))
+ (call-with-output-file (string-append out "/bin/ksp")
+ (lambda (port)
+ (chmod port #o555) ; make executable
+ (display (string-append "\
+#!" (assoc-ref inputs "bash-minimal") "/bin/sh -e
+ret=0 dir=$XDG_DATA_HOME/ksp-overlay
+mkdir -p \"$dir/upper\" \"$dir/work\" \"$dir/merged\"
+echo 'Mounting overlayfs' >&2
+sudo mount -t overlay overlay \"$dir/merged\" -o \\
+ \"lowerdir=" out "/share/kerbal-space-program,upperdir=$dir/upper,workdir=$dir/work,metacopy=on\"
+# Make files writable in the overlay, so that KSP can overwrite the ones it needs to.
+# This relies on metacopy=on for efficiency (so file data isn't copied to the upperdir on chown).
+echo 'Adjusting permissions' >&2
+sudo find \"$dir/merged\" -exec chown \"$(id -u):$(id -g)\" '{}' + -exec chmod u+w '{}' +
+echo 'Running KSP' >&2
+\"$dir/merged/KSP.x86_64\" \"$@\" || ret=$?
+echo 'Unmounting overlayfs' >&2
+sudo umount \"$dir/merged\"
+exit $ret
+") port)))))))))
+ (inputs `(("glibc" ,glibc)
+ ("gcc:lib" ,gcc "lib")
+ ("mesa" ,mesa)
+ ("gtk+" ,gtk+-2)
+ ("atk" ,atk)
+ ("glib" ,glib)
+ ("pango" ,pango)
+ ("gdk-pixbuf" ,gdk-pixbuf)
+ ("cairo" ,cairo)
+ ("freetype" ,freetype)
+ ("fontconfig" ,fontconfig)
+ ("libx11" ,libx11)
+ ("libxext" ,libxext)
+ ("libxcursor" ,libxcursor)
+ ("libxinerama" ,libxinerama)
+ ("libxi" ,libxi)
+ ("libxrandr" ,libxrandr)
+ ("libxscrnsaver" ,libxscrnsaver)
+ ("libxxf86vm" ,libxxf86vm)
+ ("pulseaudio" ,pulseaudio)
+ ("alsa-lib" ,alsa-lib)
+ ("eudev" ,eudev)
+ ("bash-minimal" ,bash-minimal)
+ ("coreutils" ,coreutils)
+ ("xdg-utils" ,xdg-utils)
+ ("setxkbmap" ,setxkbmap)))
+ (native-inputs (list unzip))
+ (home-page "https://www.kerbalspaceprogram.com/game/kerbal-space-program/")
+ (synopsis "Rocketry simulation game")
+ (description "Create and manage your own space program. Build spacecraft,
+fly them, and try to help the Kerbals fulfill their ultimate mission of
+conquering space. This is the original KSP, not the early-access KSP2.
+
+Note: KSP seems to require a writable game directory (e.g., in order to write
+its @samp{settings.cfg}). This means that the game will not run properly from
+@samp{/gnu/store}, and must be copied somewhere else first, for instance using
+@samp{rsync -a $(guix build kerbal-space-program)/share/kerbal-space-program/
+~/ksp/ && chmod -R u+w ~/ksp && ~/ksp/KSP.x86_64}.")
+ (license (list (nonguix-license:undistributable
+ "https://www.take2games.com/eula/")
+ (license:non-copyleft
+ "file://LegalNotice.txt"
+ "Contains components licensed under various permissive licenses.")))))