From 3876d5324247a47545f8c82a7826ec93933ee87f Mon Sep 17 00:00:00 2001 From: Johannes Maier Date: Wed, 15 Jun 2022 22:35:44 +0200 Subject: [PATCH 1/2] sil: clean up a bit and add a test - Add meta.mainProgram to be able to use nix run - Run preInstall and postInstall hooks - Test creation of the save directory in passthru.tests - Fix some typos and misformatting - Change prePatch to postPatch (as in the suggestion I got when adding sil-q) --- pkgs/games/sil/default.nix | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkgs/games/sil/default.nix b/pkgs/games/sil/default.nix index 2e6c50daa8236..7d446a684aae0 100644 --- a/pkgs/games/sil/default.nix +++ b/pkgs/games/sil/default.nix @@ -1,4 +1,6 @@ -{ lib, stdenv, fetchzip, ncurses, libX11, libXaw, libXt, libXext, libXmu, makeWrapper, writeScript, ... }: +{ pkgs, lib, stdenv, fetchzip, ncurses, libX11, libXaw, libXt, libXext, libXmu +, makeWrapper, writeScript }: + let setup = writeScript "setup" '' mkdir -p "$ANGBAND_PATH" @@ -15,7 +17,7 @@ stdenv.mkDerivation rec { src = fetchzip { url = "http://www.amirrorclear.net/flowers/game/sil/Sil-130-src.zip"; sha256 = "1amp2mr3fxascra0k76sdsvikjh8g76nqh46kka9379zd35lfq8w"; - stripRoot=false; + stripRoot = false; }; nativeBuildInputs = [ makeWrapper ]; @@ -25,7 +27,7 @@ stdenv.mkDerivation rec { makefile = "Makefile.std"; - prePatch = '' + postPatch = '' # Allow usage of ANGBAND_PATH substituteInPlace config.h --replace "#define FIXED_PATHS" "" ''; @@ -41,30 +43,42 @@ stdenv.mkDerivation rec { NIX_CFLAGS_COMPILE = "-fcommon"; installPhase = '' - # the makefile doesn't have a sensible install target, so we hav to do it ourselves + runHook preInstall + + # the makefile doesn't have a sensible install target, so we have to do it ourselves mkdir -p $out/bin cp sil $out/bin/sil - # Wrap the program to set a user-local ANGBAND_PATH, and run the setup script to copy files into place + + # Wrap the program to set a user-local ANGBAND_PATH, and run the setup script to copy files into place. # We could just use the options for a user-local save and scores dir, but it tried to write to the # lib directory anyway, so we might as well give everyone a copy wrapProgram $out/bin/sil \ - --run "set -u" \ --run "export ANGBAND_PATH=\$HOME/.sil" \ --run "${setup} ${src}/Sil/lib" + + runHook postInstall ''; + passthru.tests = { + saveDirCreation = pkgs.runCommand "save-dir-creation" {} '' + HOME=$(pwd) ${lib.getExe pkgs.sil} --help + test -d .sil && touch $out + ''; + }; + meta = { - description = "A rouge-like game set in the first age of Middle-earth"; + description = "A rogue-like game set in the First Age of Middle-earth"; longDescription = '' - A game of adventure set in the first age of Middle-earth, when the world still - rang with elven song and gleamed with dwarven mail. + A game of adventure set in the First Age of Middle-earth, when the world still + rang with Elven song and gleamed with Dwarven mail. Walk the dark halls of Angband. Slay creatures black and fell. Wrest a shining Silmaril from Morgoth’s iron crown. ''; homepage = "http://www.amirrorclear.net/flowers/game/sil/index.html"; license = lib.licenses.gpl2; - maintainers = [ lib.maintainers.michaelpj ]; + maintainers = with lib.maintainers; [ michaelpj kenran ]; platforms = lib.platforms.linux; + mainProgram = "sil"; }; } From 44feda004bda00a55a3d5d496756e4f5f1544e6c Mon Sep 17 00:00:00 2001 From: Johannes Maier Date: Wed, 15 Jun 2022 23:22:33 +0200 Subject: [PATCH 2/2] sil-q: add a test Check whether creating the save directory works (as a test in passthru.tests). --- pkgs/games/sil-q/default.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/games/sil-q/default.nix b/pkgs/games/sil-q/default.nix index 1676f8da55a90..e4299bd8aca73 100644 --- a/pkgs/games/sil-q/default.nix +++ b/pkgs/games/sil-q/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, writeScript, makeWrapper, ncurses, libX11 }: +{ pkgs, lib, stdenv, fetchFromGitHub, writeScript, makeWrapper, ncurses, libX11 }: let setup = writeScript "setup" '' @@ -47,6 +47,13 @@ in stdenv.mkDerivation rec { runHook postInstall ''; + passthru.tests = { + saveDirCreation = pkgs.runCommand "save-dir-creation" {} '' + HOME=$(pwd) ${lib.getExe pkgs.sil-q} --help + test -d .sil && touch $out + ''; + }; + meta = { description = "A roguelike game set in the First Age of Middle-earth"; longDescription = ''