Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the-dark-mod: init at 2.12 #356578

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added fms/consolehistory.dat
Empty file.
Empty file.
73 changes: 73 additions & 0 deletions pkgs/by-name/th/the-dark-mod-assets/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
lib,
stdenv,
curl,
xvfb-run,
the-dark-mod,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "the-dark-mod-assets";
inherit (the-dark-mod) version;

nativeBuildInputs = [
curl
xvfb-run # The installer needs an X11 environment even when unattended
];

dontUnpack = true;

buildPhase = ''
runHook preBuild
mkdir build
cd build
# The installer *really* wants to live in a writable directory to dump its files in
cp ${lib.getExe the-dark-mod.installer} ./installer
while true; do
code=0
xvfb-run ./installer \
--unattended \
--version "release${builtins.replaceStrings [ "." ] [ "" ] finalAttrs.version}" \
|| code=$?
case $code in
0) break ;;
18) echo "spurious network error; retrying"; continue ;;
*) echo "error: failed to install game assets"; exit $code ;;
esac
done
runHook postBuild
'';

installPhase = ''
runHook preInstall
# Filter out files:
# * That aren't decidedly reproducible (logs, tmpfiles, any installer manifests),
# * That we want to build ourselves (executables)
# * That we want to replace with our own (darkmod.ini)
find . \
! -name "*.log" \
! -path "./.zipsync/*" \
! -name "*.iniz" \
! \( -name "*.exe" -o -executable \) \
! -name "darkmod.ini" \
-exec install -Dm644 {} $out/{} \;
runHook postInstall
'';

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "sha256-W2BzvKCqoIQYCT/U2Jks1ZtewVSo/ucevR67pnqZTvA=";

meta = {
inherit (the-dark-mod.meta) homepage changelog maintainers;
description = "Assets for the Dark Mod";
license = with lib.licenses; [ cc-by-nc-sa-30 ];
platforms = lib.platforms.all;
};
})
159 changes: 159 additions & 0 deletions pkgs/by-name/th/the-dark-mod/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
lib,
stdenv,
fetchsvn,

cmake,
ninja,
xorg,
iconConvTools,
makeDesktopItem,
copyDesktopItems,
writableDirWrapper,

addDriverRunpath,
libGL,
alsa-lib,
makeBinaryWrapper,
the-dark-mod-assets,
}:
let
libPath = lib.makeLibraryPath [
# GLFW
addDriverRunpath.driverLink
libGL
xorg.libX11
xorg.libXcursor
xorg.libXext
xorg.libXrandr
xorg.libXxf86vm

# OpenAL
alsa-lib
];

gameDir = "\${XDG_DATA_HOME:-$HOME/.local/share}/darkmod";

description = "Dark and moody stealth game inspired by the Thief series by Looking Glass Studios";
in
stdenv.mkDerivation (finalAttrs: {
pname = "the-dark-mod";
version = "2.12";

# We use the SVN repo as it contains built static binaries that are not
# present in the Git mirror. Currently Nixpkgs only supports a limited set
# of packages that can be statically linked (notably excluding ffmpeg, pulseaudio
# and pipewire), so we couldn't build everything from scratch even if we want to :(
src = fetchsvn {
url = "https://svn.thedarkmod.com/publicsvn/darkmod_src/tags/${finalAttrs.version}";
rev = "10652";
hash = "sha256-jPQWoLlsUQqpBB1BECR9m/p+HwD0jJlpqwUaIqygwP0=";
};

outputs = [
"out"
"debug"
];

nativeBuildInputs = [
cmake
ninja
makeBinaryWrapper
iconConvTools
copyDesktopItems
writableDirWrapper
];

buildInputs = [
xorg.xorgproto
xorg.libX11
xorg.libXxf86vm
xorg.libXext
];

cmakeFlags = [
(lib.cmakeFeature "GAME_DIR" "${placeholder "out"}/bin")
];

# O_O it installs stuff in buildPhase...
preBuild = ''
mkdir -p $out/bin
'';

dontUseNinjaInstall = true;

desktopItems = [
(makeDesktopItem {
name = "the-dark-mod";
desktopName = "The Dark Mod";
comment = description;
icon = "the-dark-mod";
exec = "the-dark-mod";
categories = [
"Game"
"ActionGame"
"AdventureGame"
"RolePlaying"
];
keywords = [
"Stealth"
"Steampunk"
"Thief"
];
prefersNonDefaultGPU = true;
})
];

postInstall = ''
icoFileToHiColorTheme ${the-dark-mod-assets}/darkmod.ico the-dark-mod $out
'';

postFixup = ''
moveToOutput bin/thedarkmod.x64.debug $debug
mv $out/bin/thedarkmod.x64 $out/bin/the-dark-mod
wrapProgramInWritableDir $out/bin/the-dark-mod '${gameDir}' \
--prefix LD_LIBRARY_PATH : ${libPath} \
--set ALSOFT_CONF ${the-dark-mod-assets}/alsoft.ini \
--add-flags '+set fs_basepath "${the-dark-mod-assets}"' \
--add-flags '+set fs_savepath "${gameDir}"' \
--add-flags '+set fs_modSavePath "${gameDir}/fms"'
'';

passthru.installer = stdenv.mkDerivation {
pname = "the-dark-mod-installer";
inherit (finalAttrs) version src;
sourceRoot = "${finalAttrs.src.name}/tdm_installer";

nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
xorg.libX11
xorg.libXext
];

installPhase = ''
runHook preInstall
install -Dm755 tdm_installer.linux64 -t $out/bin
runHook postInstall
'';

meta.mainProgram = "tdm_installer.linux64";
};

meta = {
inherit description;
homepage = "https://www.thedarkmod.com/";
changelog = "https://wiki.thedarkmod.com/index.php?title=What%27s_new_in_TDM_${finalAttrs.version}";
license = with lib.licenses; [
gpl3Plus # Portions based on Doom 3
bsd3 # Original code
];
# Other Linux platforms may work (including i686-linux) but are not officially supported
platforms = [ "x86_64-linux" ];
maintainers = with lib.maintainers; [ pluiedev ];
mainProgram = "the-dark-mod";
};
})
33 changes: 33 additions & 0 deletions pkgs/by-name/th/the-dark-mod/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p subversion common-updater-scripts

attr=the-dark-mod
svnUrl=https://svn.thedarkmod.com/publicsvn/darkmod_src/tags

versions=$(svn list $svnUrl | rg "^\d+.\d+/\$" | tr -d '/')
currentVersion=$(nix-instantiate --eval -E "with import ./. {}; $attr.version" | tr -d '"')

echo "Current TDM version: $currentVersion"
for version in $versions; do
[ "$version" = "$(printf '%s\n%s' "$version" "$currentVersion" | sort -V | head -n1)" ] && continue

echo "New version found: $version";
rev=$(svn info $svnUrl/$version --show-item last-changed-revision)

echo "Updating engine";
update-source-version "$attr-unwrapped" "$version" --rev="$rev"

echo "Updating assets";
oldAssetsHash=$(nix-instantiate --eval --strict -A "the-dark-mod-assets.drvAttrs.outputHash" | tr -d '"')
nix-build --no-out-link -A "the-dark-mod-assets" 2>&1 | tee assets.log
newAssetsHash=$(grep -P --only-matching "got: +.+[:-]\K.+" assets.log)

sed -i.cmp 's,$oldAssetsHash,$newAssetsHash,' pkgs/by-name/th/the-dark-mod-assets/package.nix

echo "Update complete!";

exit 0
done

echo "Already at latest version"

116 changes: 116 additions & 0 deletions pkgs/by-name/wr/writableDirWrapper/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
lib,
writeShellApplication,
xorg,
makeSetupHook,

makeWrapper,
}:
makeSetupHook {
name = "writable-dir-wrapper";

propagatedBuildInputs = [
makeWrapper
];

substitutions = {
lndir = lib.getExe xorg.lndir;
};

} ./wrapper.sh

/**
A wrapper for programs that require a writable directory to function, typically
games or proprietary software that expect read-only resources to be placed alongside
config files and state files (e.g. logs).

# Inputs

*`options`* (Attribute set)

: Set of options for the wrapper.

`name` (String)

: File name of the wrapper.

`version` (String, _optional_)

: Version of the underlying program. When set, version checks will be enabled and existing links will be recreated if they belong to a different version.

`path` (String)

: Path of the directory that would hold the linked data.

`links` (List of attrsets, _optional_)

: List of links from a source directory to a directory relative to the output path.

`src` (String)

: Source directory of the link, usually from the Nix store.

`dst` (String, _optional_)

: Destination directory of the link.

: _Default:_ the output path.

`postLink` (String, _optional_)

: Command to run after (re-)linking. Since links are first created in a temporary directory, `postLink` can be used to remove or add files that will be copied to the output path (for example, when some files need to be excluded from the linked result).

`exec` (String)

: Command to run.

`flags` (List of strings, _optional_)

: The list of flags given to the command. ***Unescaped and can refer to Bash variables and perform shell substitutions.***

# Type

```
writableDirWrapper ::
{
name :: String;
version? :: String;
path :: String;
links? :: [{ src :: String; dst? :: String }];
postLink? :: String;
exec :: String
} -> Derivation
```

# Examples
:::{.example}
## `pkgs.writableDirWrapper` usage example

```nix
{
writableDirWrapper,
hello,
}:
writableDirWrapper {
name = "writable-hello";
links = [
{
src = hello;
dst = "hello";
}
];
postLink = ''
echo "Hello world!" | base64 > hello.txt
'';
exec = ''
./hello/bin/hello --greeting=$(<"hello.txt")
'';
}
```

When built and run, this should output:
```console
SGVsbG8gd29ybGQhCg==
```
:::
*/
Loading
Loading