Skip to content

Commit

Permalink
drl: init at 0.9.9.8a
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhys-T committed Oct 30, 2024
1 parent 5c0d6eb commit bfa4b2e
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Uncomment this if you use travis:

## Package-specific notes

### `drl`

DRL (formerly DoomRL) expects to run with the game directory as its working directory, containing both the read-only game data and mutable state. Obviously that doesn't work very well with Nix, so I'm using a similar approach to [the `sdlpop` derivation](https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/sdlpop/default.nix): `drl` is actually a wrapper script that links/copies the game data into `${XDG_DATA_HOME:-$HOME/.local/share}/drl` as appropriate, then runs the game from there. It won't replace any file/directory there that isn't a symlink, so you can always override any of the files you need to.

### `hbmame`

Takes the upstream `mame` derivation to base itself off of as an argument. If you want to override dependencies and such, you'll currently need to override them on `mame`, then override `mame` on `hbmame`:
Expand Down
8 changes: 8 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ in {
};
});

drl-hq = callPackage ./pkgs/drl { drl-audio = self.drl-audio-hq; };
drl-lq = callPackage ./pkgs/drl { drl-audio = self.drl-audio-lq; };
drl = self.drl-hq;
drl-unwrapped = callPackage ./pkgs/drl/unwrapped.nix {};
drl-audio-hq = callPackage ./pkgs/drl/audio.nix { audioQuality = "hq"; };
drl-audio-lq = callPackage ./pkgs/drl/audio.nix { audioQuality = "lq"; };
drl-audio = self.drl-audio-hq;

# Can't just pass `-L` to `nix-build-uncached`: it ends up being passed to both
# old `nix-build` (which doesn't understand it) and new `nix build` (which does).
nix-build-uncached-logging = callPackage ({nix-build-uncached}: nix-build-uncached.overrideAttrs (old: {
Expand Down
26 changes: 26 additions & 0 deletions pkgs/drl/audio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ audioQuality, drl-unwrapped, fetchzip, lib }: let
pname = "drl-${audioQuality}-audio";
inherit (drl-unwrapped) version;
rev = builtins.replaceStrings ["."] ["_"] version;
shortVersion = lib.concatStrings (builtins.filter (x: builtins.match "[0-9]+" x != null) (builtins.splitVersion version));
passthru = { inherit audioQuality; };
fetchtgz = fetchzip.override { withUnzip = false; };
in if audioQuality == "hq" then fetchtgz {
inherit pname version passthru;
url = "https://github.com/chaosforgeorg/doomrl/releases/download/${rev}/drl-linux-${shortVersion}.tar.gz";
postFetch = ''
shopt -s extglob
rm -r "$out"/!(mp3|wavhq)
shopt -u extglob
'';
hash = "sha256-j1YzEAW40w+yBRT3MJz5IGe3gNvd4ede32SVhNAGjUc=";
} else fetchtgz {
inherit pname version passthru;
url = "https://github.com/chaosforgeorg/doomrl/releases/download/${rev}/drl-linux-${shortVersion}-lq.tar.gz";
postFetch = ''
shopt -s extglob
rm -r "$out"/!(music|wav)
shopt -u extglob
'';
hash = "sha256-GyOklqXecE6jhN2dZ6XIliLAZQob7gPgnkW484MQeiw=";
}
29 changes: 29 additions & 0 deletions pkgs/drl/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ stdenvNoCC, lib, drl-unwrapped, drl-audio, coreutils }: let
wrongAudioSuffix = if drl-audio.audioQuality == "hq" then "" else "hq";
in stdenvNoCC.mkDerivation {
pname = "drl-${drl-audio.audioQuality}";
inherit (drl-unwrapped) version;
dontUnpack = true;
unwrapped = drl-unwrapped;
audio = drl-audio;
inherit coreutils;
installPhase = ''
shopt -s extglob
mkdir -p "$out"/bin "$out"/share/drl
ln -s \
"$unwrapped"/share/drl/!(@(sound|music)${wrongAudioSuffix}.lua) \
"$out"/share/drl/
${lib.optionalString (drl-audio.audioQuality == "hq") ''
for file in sound music; do
mv "$out/share/drl/''${file}hq.lua" "$out/share/drl/$file.lua"
done
''}
ln -s "$audio"/* "$out"/share/drl/
substituteAll ${./drl.sh} "$out"/bin/drl
chmod +x "$out"/bin/drl
shopt -u extglob
'';
meta = drl-unwrapped.meta // {
mainProgram = "drl";
};
}
22 changes: 22 additions & 0 deletions pkgs/drl/drl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!@shell@
set -e
destDir="${XDG_DATA_HOME:-$HOME/.local/share}/drl"
oldPath="$PATH"
PATH="@coreutils@/bin"
mkdir -p "$destDir"
shopt -s extglob
for file in @out@/share/drl/!(drl); do
baseFile="${file##*/}"
destFile="$destDir/$baseFile"
if [[ ! -e "$destFile" ]]; then
if [[ "$baseFile" == @(config.lua|colors.lua|screenshot|mortem|backup) ]]; then
cp -Lr --no-preserve=all "$file" "$destFile"
elif [[ ! -e "$destFile" || -L "$destFile" ]]; then
ln -sf "$file" "$destDir"
fi
fi
done
shopt -u extglob
PATH="$oldPath"
cd "$destDir"
exec -a drl @out@/share/drl/drl "$@"
123 changes: 123 additions & 0 deletions pkgs/drl/unwrapped.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{ stdenv, lib, fetchFromGitHub, writeText, lua5_1, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, ncurses, darwin, fpc, maintainers }: let
libExt = if stdenv.isDarwin then "dylib" else "so";
version = "0.9.9.8a";
gitShortRev = "97f1c51";
rev = builtins.replaceStrings ["."] ["_"] version;
shortVersion = lib.concatStrings (builtins.filter (x: builtins.match "[0-9]+" x != null) (builtins.splitVersion version));
src = fetchFromGitHub {
owner = "chaosforgeorg";
repo = "doomrl";
inherit rev;
hash = "sha256-5FwaBuMFrz5dOxhHsJZLmL/PkwhXgW5XpVKDWoiVuWk=";
};
fpcvalkyrie = fetchFromGitHub {
owner = "chaosforgeorg";
repo = "fpcvalkyrie";
rev = "0_9_0a";
hash = "sha256-R/FgbmT7pvw9Qn0a7uR/Hw4pEQ2mArZY6sqXShQWU1Q=";
};
in stdenv.mkDerivation rec {
pname = "drl-unwrapped";
inherit version gitShortRev;
inherit src fpcvalkyrie;
postUnpack = ''
cp -r "$fpcvalkyrie" fpcvalkyrie
chmod -R u+rwX fpcvalkyrie
export FPCVALKYRIE_ROOT="$PWD/fpcvalkyrie/"
'';
nativeBuildInputs = [lua5_1 fpc];
buildInputs = [lua5_1 SDL2 SDL2_image SDL2_mixer SDL2_ttf ncurses];
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-unused-command-line-argument";
env.NIX_LDFLAGS = lib.optionalString stdenv.isDarwin (lib.concatMapStringsSep " " (f: "-F${f}/Library/Frameworks") (with darwin.apple_sdk.frameworks; [CoreFoundation Cocoa]));
postPatch = ''
sed -i '
/fpc_params =/ a\
"-dLUA_DYNAMIC",
/macosx_version_min/ d
/OSX_APP_BUNDLE/ d
' makefile.lua
substituteInPlace makefile.lua --replace-fail 'make.gitrevision()' "(function()
local revision = '$gitShortRev'
return {
full = revision,
working = tonumber(revision, 16),
current = tonumber(revision, 16),
mod = mod,
}
end)()"
substituteInPlace "$FPCVALKYRIE_ROOT"/libs/vlualibrary.pas \
--replace-fail 'lua5.1.${libExt}' '${lib.getLib lua5_1}/lib/liblua.5.1.${libExt}'
substituteInPlace "$FPCVALKYRIE_ROOT"/libs/vsdl2library.pas \
--replace-fail '${if stdenv.isDarwin then "SDL2.framework/SDL2" else "libSDL2-2.0.so.0"}' '${lib.getLib SDL2}/lib/libSDL2.${libExt}' \
--replace-fail '{$linklib SDLmain}' '{.$linklib SDL2main}' \
--replace-fail '{$linkframework SDL}' '{$linklib SDL2}' \
--replace-fail '{$PASCALMAINNAME SDL_main}' '{.$PASCALMAINNAME SDL_main}'
substituteInPlace "$FPCVALKYRIE_ROOT"/libs/vsdl2imagelibrary.pas \
--replace-fail '${if stdenv.isDarwin then "SDL2_image.framework/SDL_image" else "libSDL2_image-2.0.so.0"}' '${lib.getLib SDL2_image}/lib/libSDL2_image.${libExt}'
substituteInPlace "$FPCVALKYRIE_ROOT"/libs/vsdl2mixerlibrary.pas \
--replace-fail '${if stdenv.isDarwin then "SDL2_mixer.framework/SDL2_mixer" else "libSDL2_mixer-2.0.so.0"}' '${lib.getLib SDL2_mixer}/lib/libSDL2_mixer.${libExt}'
substituteInPlace "$FPCVALKYRIE_ROOT"/libs/vsdl2ttflibrary.pas \
--replace-fail '${if stdenv.isDarwin then "SDL2_ttf.framework/SDL2_ttf" else "libSDL2_ttf-2.0.so.0"}' '${lib.getLib SDL2_ttf}/lib/libSDL2_ttf.${libExt}'
'' + lib.optionalString stdenv.isDarwin ''
sed -E -i '
/glExtLoader/ {
/GetSymbolExt\s*:=/ s/glExtLoader/GetSymbol/
/GetSymbolExt\s*:=/! d
}
' "$FPCVALKYRIE_ROOT"/libs/vgl3library.pas
'';
configurePhase = ''
runHook preConfigure
cp ${writeText "config.lua" ''
OS = "${if stdenv.isDarwin then "MACOSX" else "LINUX"}"
''} config.lua
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
mkdir tmp
lua makefile.lua
ls -al bin
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"/share/drl
cp bin/drl "$out"/share/drl/drl
for file in \
backup \
mortem \
screenshot \
modules \
config.lua \
colors.lua \
sound.lua \
soundhq.lua \
music.lua \
musichq.lua \
manual.txt \
version.txt \
version_api.txt \
drl.wad \
core.wad \
; do
cp -r bin/"$file" "$out"/share/drl/"$file"
done
runHook postInstall
'';
meta = {
description = "Roguelike game based on the FPS Doom";
longDescription = ''
DRL (D**m, the Roguelike) is a fast and furious coffee-break Roguelike game, that is heavily inspired by the popular FPS game Doom by ID Software.
'';
homepage = "https://drl.chaosforge.org/";
licenses = with lib.licenses; [
# Code
gpl2Only
# Artwork
# Music (according to <https://simonvolpert.com/drla/>)
cc-by-sa-40
];
maintainers = [maintainers.Rhys-T];
};
}

0 comments on commit bfa4b2e

Please sign in to comment.