From 58542c2d7eee26541aba35745e2eec40a0ee22b6 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Tue, 12 Nov 2024 09:49:00 -0500 Subject: [PATCH 1/2] descent3-unwrapped: init at 1.5.0-beta-unstable-2024-10-29 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Originally, I had thought that the version number should be 1.5.0-unstable-2024-10-29. It ended up being 1.5.0-beta-unstable-2024-10-29 due to a technicality. The package versioning conventions in pkgs/README.md say: > - If a package is a commit from a repository without a version > assigned, then the `version` attribute _should_ be the latest upstream > version preceding that commit, followed by `-unstable-` and the date > of the (fetched) commit. The key phrase here is “preceding that commit”. The commit for Descent 3 version 1.5.0 was created in a separate branch [1]. That being said, there was a beta version of 1.5.0 that was released in 2005 [2]. That beta version of 1.5.0 was indeed merged into Descent 3’s main branch [3], so it’s the latest upstream version preceding the fetched commit. [1]: [2]: [3]: --- .../by-name/de/descent3-unwrapped/package.nix | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 pkgs/by-name/de/descent3-unwrapped/package.nix diff --git a/pkgs/by-name/de/descent3-unwrapped/package.nix b/pkgs/by-name/de/descent3-unwrapped/package.nix new file mode 100644 index 000000000000..eb1d0de47adb --- /dev/null +++ b/pkgs/by-name/de/descent3-unwrapped/package.nix @@ -0,0 +1,152 @@ +{ + SDL2, + cmake, + fetchFromGitHub, + glm, + lib, + runCommand, + stdenv, + unstableGitUpdater, + writeShellScript, + zlib, +}: + +stdenv.mkDerivation rec { + pname = "descent3-unwrapped"; + # I’m using an unstable version here because we need to use -additionaldir in + # the wrapped version of Descent 3. Once there’s a stable version of Descent + # 3 that supports the -additionaldir command-line option, we can stop using + # an unstable version of Descent 3. + version = "1.5.0-beta-unstable-2024-10-29"; + src = fetchFromGitHub { + owner = "DescentDevelopers"; + repo = "Descent3"; + rev = "d51ce964c7a925333ea64f00cf8d9ae15ee63a6b"; + fetchSubmodules = true; + leaveDotGit = true; + # Descent 3 is supposed to display its Git commit hash in the bottom right + # corner of the main menu. That feature only works if either the .git + # directory or a git-hash.txt file exists at build time. We don’t want .git + # to exist at build time (see #8567), so we create a git-hash.txt file and + # then delete the .git directory. + # + # Technically, we could simplify the code by reading the value of src.rev. + # src.rev contains a Git commit hash at the moment, but it won’t contain a + # Git commit hash in the future when we switch to a stable version of + # Descent 3. + # + # Upstream expects git-hash.txt to contain a short commit hash, but I’ve + # decided to use a full commit hash. Full commit hashes are more + # reproducible. The short hash “1234” might correspond to one commit today, + # but correspond to two commits tomorrow. Full commit hashes don’t have + # that problem. + # + # Also, upstream expects git-hash.txt to contain no newlines. If + # git-hash.txt contains a newline, then Descent 3 will fail to build. + postFetch = '' + cd "$out" + git rev-parse --verify HEAD | tr --delete '\n' > git-hash.txt + rm -r .git + ''; + hash = "sha256-C6r06cntQ14jPFO9EUzLisZjsl22cIaJb8I7xFzXrNc="; + }; + + hardeningDisable = [ "format" ]; + nativeBuildInputs = [ cmake ]; + buildInputs = [ + SDL2 + glm + zlib + ]; + cmakeFlags = [ "-DFORCE_PORTABLE_INSTALL=OFF" ]; + # This is a workaround for a problem that will eventually get fixed upstream. + postInstall = '' + cd "$out" + mv lib/* share/ + rmdir lib + ''; + + passthru = { + # The idea here is to make sure that we don’t forget to update meta.license + # when reviewing a pull request from @r-ryantm. + tests.licenseInfoIsUpToDate = runCommand "${pname}-license-info-is-up-to-date" { } '' + function on_success { + echo Test succeeded. > "$out" + } + + function on_failure { + echo \ + It looks like at least one of Descent 3’s licensing-related files \ + changed. Before you continue to update this package, you should \ + check to see if meta.license needs to be updated. Once you’ve done \ + that, you can update the hashes in the \ + passthru.tests.licenseInfoIsUpToDate script and then try running the \ + package tests again. >&2 + return 1 + } + + cd ${lib.strings.escapeShellArg src} + sha256sum --check << EOF && on_success || on_failure + 8b1ba204bb69a0ade2bfcf65ef294a920f6bb361b317dba43c7ef29d96332b9b LICENSE + 55d65dbf5d785111cf7029941cb7f72dbef084509e6126bcc58b6bb20203f8c6 THIRD_PARTY.md + EOF + ''; + updateScript = unstableGitUpdater { + shallowClone = false; + # unstableGitUpdater assumes that the version number should be 0 if there + # isn’t any tags in the repo’s default branch. For most packages, that is + # the correct decision, but for Descent 3 it’s not. Descent 3’s source + # code lived in private repos until 2024. In 2024, a new public repo was + # created [1], but the old commit history wasn’t imported into the new + # repo. Version 1.5.0-beta from 2005 [2] was the last release that was + # created from one of the private repos.* + # + # *Technically, there was one release that came after the 2005 one. There + # was a Linux version and a macOS version of Descent 3 that were released + # on Steam in 2020 [3][4][5]. Those versions don’t count because they + # haven’t been fully merged into the public repo yet [6]. + # + # [1]: + # [2]: + # [3]: + # [4]: + # [5]: + # [6]: + tagConverter = writeShellScript "${pname}-tag-converter.sh" '' + read -r input_tag + if [ "$input_tag" = 0 ] + then + printf '%s' 1.5.0-beta + else + printf '%s' "$input_tag" + fi + ''; + }; + }; + + meta = { + description = "Game engine for a 6DOF first-person shooter"; + homepage = "https://github.com/DescentDevelopers/Descent3"; + license = with lib.licenses; [ + # See LICENSE and header that’s at the top of many source files. + gpl3Plus + # See THIRD_PARTY.md. + isc + mit + ]; + mainProgram = "Descent3"; + maintainers = [ lib.maintainers.jayman2000 ]; + platforms = lib.platforms.all; + badPlatforms = [ + # Descent 3 stores modules in HOG2 archives. It extracts those modules + # and then tries to dlopen() them at runtime. + lib.systems.inspect.platformPatterns.isStatic + # When you build Descent 3 on Darwin, it produces a different directory + # structure (no bin/ directory) [1]. I’m sure that this derivation could be + # updated to account for that different directory structure, but I don’t + # have any Darwin systems to test things on at the moment. + # + # [1]: + ] ++ lib.platforms.darwin; + }; +} From 4c5768f0bcafe2975cbe4fa7c6c65c559018a54f Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Tue, 12 Nov 2024 16:05:53 -0500 Subject: [PATCH 2/2] descent3: init at 1.5.0-beta-unstable-2024-10-29 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, Descent 3 will only look for game files in the current working directory. In order to function properly, Descent 3 needs to look for some of its files in the Nix store. This commit creates a wrapper around the main Descent3 executable that automatically looks in the correct path in the Nix store. Hopefully, this wrapper will only exist temporarily. I have an unfinished Descent 3 pull request that adds a DEFAULT_ADDITIONAL_DIRS CMake option [1]. Once I can finish that pull request (DescentDevelopers/Descent3#623 needs to get merged first), we’ll be able to get rid of this wrapper and use DEFAULT_ADDITIONAL_DIRS instead. Additionally, if DescentDevelopers/Descent3#628 gets merged first, then that pull request will also probably make this wrapper unnecessary. [1]: --- pkgs/by-name/de/descent3/package.nix | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pkgs/by-name/de/descent3/package.nix diff --git a/pkgs/by-name/de/descent3/package.nix b/pkgs/by-name/de/descent3/package.nix new file mode 100644 index 000000000000..5027a8bc12e7 --- /dev/null +++ b/pkgs/by-name/de/descent3/package.nix @@ -0,0 +1,60 @@ +{ + descent3-unwrapped, + lib, + makeBinaryWrapper, + runCommand, +}: + +runCommand "descent3-${descent3-unwrapped.version}" + { + pname = "descent3"; + inherit (descent3-unwrapped) version; + nativeBuildInputs = [ makeBinaryWrapper ]; + passthru.unwrapped = descent3-unwrapped; + + meta = descent3-unwrapped.meta // { + # The code that produces the wrapper is in the Nixpkgs repo, and the + # Nixpkgs repo is MIT Licensed. + license = [ lib.licenses.mit ]; + longDescription = '' + Playing Descent 3 using the Nix package manager is a little bit awkward + at the moment. This wrapper makes it slightly less awkward. Here’s how + you use this wrapper: + + 1. Install the `descent3` package, or start an ephemeral shell with the + `descent3` package. + + 2. Find the documentation folder for `descent3-unwrapped` by running this + command: + + ```bash + nix-instantiate --eval --expr '(import { }).descent3-unwrapped + "/share/doc/Descent3"' + ``` + + 3. Open `/USAGE.md`. + + 4. Follow steps 1–6 of Descent 3’s usage instructions. + + 5. Change directory into the `D3-open-source` folder: + + ```bash + cd + ``` + + 6. Start Descent 3 by running this command: + + ```bash + Descent3 + ``` + ''; + }; + } + '' + mkdir --parents "$out/bin" + descent3_unwrapped=${lib.strings.escapeShellArg descent3-unwrapped} + makeBinaryWrapper \ + "$descent3_unwrapped/bin/Descent3" \ + "$out/bin/Descent3" \ + --append-flags -additionaldir \ + --append-flags "$descent3_unwrapped/share" + ''