diff --git a/pkgs/games/cataclysm-dda/builder.nix b/pkgs/games/cataclysm-dda/builder.nix new file mode 100644 index 000000000000..24128875f3a1 --- /dev/null +++ b/pkgs/games/cataclysm-dda/builder.nix @@ -0,0 +1,49 @@ +{ stdenvNoCC, lib, type }: + +assert lib.elem type [ + "mod" + "soundpack" + "tileset" +]; + +{ modName, version, src, ... } @ args: + +stdenvNoCC.mkDerivation (args // rec { + pname = args.pname or "cataclysm-dda-${type}-${modName}"; + + modRoot = args.modRoot or "."; + + configurePhase = args.configurePhase or '' + runHook preConfigure + runHook postConfigure + ''; + + buildPhase = args.buildPhase or '' + runHook preBuild + runHook postBuild + ''; + + checkPhase = args.checkPhase or '' + runHook preCheck + runHook postCheck + ''; + + installPhase = let + baseDir = { + mod = "mods"; + soundpack = "sound"; + tileset = "gfx"; + }.${type}; + in args.installPhase or '' + runHook preInstall + destdir="$out/share/cataclysm-dda/${baseDir}" + mkdir -p "$destdir" + cp -R "${modRoot}" "$destdir/${modName}" + runHook postInstall + ''; + + passthru = { + forTiles = true; + forCurses = type == "mod"; + }; +}) diff --git a/pkgs/games/cataclysm-dda/common.nix b/pkgs/games/cataclysm-dda/common.nix index 48941bdb01f6..3cbda9479070 100644 --- a/pkgs/games/cataclysm-dda/common.nix +++ b/pkgs/games/cataclysm-dda/common.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub, pkgconfig, gettext, ncurses, CoreFoundation +{ stdenv, pkgconfig, gettext, ncurses, CoreFoundation , tiles, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, freetype, Cocoa , debug, runtimeShell }: @@ -12,7 +12,7 @@ let tilesDeps = [ SDL2 SDL2_image SDL2_mixer SDL2_ttf freetype ] ++ optionals stdenv.isDarwin [ Cocoa ]; - common = { + common = stdenv.mkDerivation { pname = "cataclysm-dda"; nativeBuildInputs = [ pkgconfig ]; @@ -51,6 +51,11 @@ let # make: *** [Makefile:687: obj/tiles/weather_data.o] Error 1 enableParallelBuilding = false; + passthru = { + isTiles = tiles; + isCurses = !tiles; + }; + meta = with stdenv.lib; { description = "A free, post apocalyptic, zombie infested rogue-like"; longDescription = '' @@ -84,13 +89,6 @@ let }; utils = { - fetchFromCleverRaven = { rev, sha256 }: - fetchFromGitHub { - owner = "CleverRaven"; - repo = "Cataclysm-DDA"; - inherit rev sha256; - }; - installXDGAppLauncher = '' launcher="$out/share/applications/cataclysm-dda.desktop" install -D -m 444 data/xdg/*cataclysm-dda.desktop -T "$launcher" @@ -113,4 +111,4 @@ let }; in -{ inherit common utils; } +common diff --git a/pkgs/games/cataclysm-dda/default.nix b/pkgs/games/cataclysm-dda/default.nix index ed3fe7fdfc7a..ada212ea7e9f 100644 --- a/pkgs/games/cataclysm-dda/default.nix +++ b/pkgs/games/cataclysm-dda/default.nix @@ -1,22 +1,42 @@ -{ stdenv, callPackage, CoreFoundation -, tiles ? true, Cocoa -, debug ? false -}: +{ newScope, darwin }: let - inherit (callPackage ./common.nix { inherit tiles CoreFoundation Cocoa debug; }) common utils; - inherit (utils) fetchFromCleverRaven; + callPackage = newScope self; + + stable = rec { + tiles = callPackage ./stable.nix { + inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa; + }; + + curses = tiles.override { tiles = false; }; + }; + + git = rec { + tiles = callPackage ./git.nix { + inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa; + }; + + curses = tiles.override { tiles = false; }; + }; + + lib = callPackage ./lib.nix {}; + + pkgs = callPackage ./pkgs {}; + + self = { + inherit + callPackage + stable + git; + + inherit (lib) + buildMod + buildSoundPack + buildTileSet + wrapCDDA; + + inherit pkgs; + }; in -stdenv.mkDerivation (common // rec { - version = "0.E-2"; - - src = fetchFromCleverRaven { - rev = version; - sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68"; - }; - - meta = with stdenv.lib.maintainers; common.meta // { - maintainers = common.meta.maintainers ++ [ skeidel ]; - }; -}) +self diff --git a/pkgs/games/cataclysm-dda/git.nix b/pkgs/games/cataclysm-dda/git.nix index 8e803ed63dff..89af582b3c07 100644 --- a/pkgs/games/cataclysm-dda/git.nix +++ b/pkgs/games/cataclysm-dda/git.nix @@ -1,28 +1,37 @@ -{ stdenv, callPackage, CoreFoundation +{ lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA , tiles ? true, Cocoa , debug ? false }: let - inherit (stdenv.lib) substring; - inherit (callPackage ./common.nix { inherit tiles CoreFoundation Cocoa debug; }) common utils; - inherit (utils) fetchFromCleverRaven; + common = callPackage ./common.nix { + inherit tiles CoreFoundation Cocoa debug; + }; + + self = common.overrideAttrs (common: rec { + pname = common.pname + "-git"; + version = "2019-11-22"; + + src = fetchFromGitHub { + owner = "CleverRaven"; + repo = "Cataclysm-DDA"; + rev = "a6c8ece992bffeae3788425dd4b3b5871e66a9cd"; + sha256 = "0ww2q5gykxm802z1kffmnrfahjlx123j1gfszklpsv0b1fccm1ab"; + }; + + makeFlags = common.makeFlags ++ [ + "VERSION=git-${version}-${lib.substring 0 8 src.rev}" + ]; + + passthru = common.passthru // { + pkgs = pkgs.override { build = self; }; + withMods = wrapCDDA self; + }; + + meta = with lib.maintainers; common.meta // { + maintainers = common.meta.maintainers ++ [ rardiol ]; + }; + }); in -stdenv.mkDerivation (common // rec { - pname = common.pname + "-git"; - version = "2019-11-22"; - - src = fetchFromCleverRaven { - rev = "a6c8ece992bffeae3788425dd4b3b5871e66a9cd"; - sha256 = "0ww2q5gykxm802z1kffmnrfahjlx123j1gfszklpsv0b1fccm1ab"; - }; - - makeFlags = common.makeFlags ++ [ - "VERSION=git-${version}-${substring 0 8 src.rev}" - ]; - - meta = with stdenv.lib.maintainers; common.meta // { - maintainers = common.meta.maintainers ++ [ rardiol ]; - }; -}) +self diff --git a/pkgs/games/cataclysm-dda/lib.nix b/pkgs/games/cataclysm-dda/lib.nix new file mode 100644 index 000000000000..02678ed0228e --- /dev/null +++ b/pkgs/games/cataclysm-dda/lib.nix @@ -0,0 +1,17 @@ +{ callPackage }: + +{ + buildMod = callPackage ./builder.nix { + type = "mod"; + }; + + buildSoundPack = callPackage ./builder.nix { + type = "soundpack"; + }; + + buildTileSet = callPackage ./builder.nix { + type = "tileset"; + }; + + wrapCDDA = callPackage ./wrapper.nix {}; +} diff --git a/pkgs/games/cataclysm-dda/pkgs/default.nix b/pkgs/games/cataclysm-dda/pkgs/default.nix new file mode 100644 index 000000000000..fb5571243f53 --- /dev/null +++ b/pkgs/games/cataclysm-dda/pkgs/default.nix @@ -0,0 +1,24 @@ +{ lib, callPackage, build ? null }: + +let + pkgs = { + mod = { + }; + + soundpack = { + }; + + tileset = { + }; + }; + + availableForBuild = _: mod: + if isNull build then + true + else if build.isTiles then + mod.forTiles + else + mod.forCurses; +in + +lib.mapAttrs (_: mod: lib.filterAttrs availableForBuild mod) pkgs diff --git a/pkgs/games/cataclysm-dda/stable.nix b/pkgs/games/cataclysm-dda/stable.nix new file mode 100644 index 000000000000..e142f67d190a --- /dev/null +++ b/pkgs/games/cataclysm-dda/stable.nix @@ -0,0 +1,32 @@ +{ lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA +, tiles ? true, Cocoa +, debug ? false +}: + +let + common = callPackage ./common.nix { + inherit tiles CoreFoundation Cocoa debug; + }; + + self = common.overrideAttrs (common: rec { + version = "0.E-2"; + + src = fetchFromGitHub { + owner = "CleverRaven"; + repo = "Cataclysm-DDA"; + rev = version; + sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68"; + }; + + passthru = common.passthru // { + pkgs = pkgs.override { build = self; }; + withMods = wrapCDDA self; + }; + + meta = with lib.maintainers; common.meta // { + maintainers = common.meta.maintainers ++ [ skeidel ]; + }; + }); +in + +self diff --git a/pkgs/games/cataclysm-dda/wrapper.nix b/pkgs/games/cataclysm-dda/wrapper.nix new file mode 100644 index 000000000000..0a3727c2c1c1 --- /dev/null +++ b/pkgs/games/cataclysm-dda/wrapper.nix @@ -0,0 +1,32 @@ +{ lib, symlinkJoin, makeWrapper }: + +unwrapped: + +pkgsSpec: + +let + mods = if lib.isFunction pkgsSpec + then pkgsSpec unwrapped.pkgs + else pkgsSpec; +in + +if builtins.length mods == 0 +then unwrapped +else symlinkJoin { + name = unwrapped.name + "-with-mods"; + + paths = [ unwrapped ] ++ mods; + + nativeBuildInputs = [ makeWrapper ]; + + postBuild = '' + if [ -x $out/bin/cataclysm ]; then + wrapProgram $out/bin/cataclysm \ + --add-flags "--datadir $out/share/cataclysm-dda/" + fi + if [ -x $out/bin/cataclysm-tiles ]; then + wrapProgram $out/bin/cataclysm-tiles \ + --add-flags "--datadir $out/share/cataclysm-dda/" + fi + ''; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8587ee041891..ae50c1729420 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23864,13 +23864,11 @@ in inherit (darwin.apple_sdk.frameworks) Carbon CoreServices; }; - cataclysm-dda = callPackage ../games/cataclysm-dda { - inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa; - }; + cataclysmDDA = callPackage ../games/cataclysm-dda { }; - cataclysm-dda-git = callPackage ../games/cataclysm-dda/git.nix { - inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa; - }; + cataclysm-dda = cataclysmDDA.stable.tiles; + + cataclysm-dda-git = cataclysmDDA.git.tiles; chessdb = callPackage ../games/chessdb { };