summary refs log tree commit diff
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-11-15 18:41:36 +0100
committerNaïm Favier <n@monade.li>2022-11-17 00:06:31 +0100
commit839fdd101c3749468d44348114a2994bb8414546 (patch)
tree5712de6fffaf7a0060ac298c6ad5d97dce0b24d4
parentc91f68c3d88e646e5d1edb71f8c322620bafa644 (diff)
downloadnixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar.gz
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar.bz2
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar.lz
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar.xz
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.tar.zst
nixpkgs-839fdd101c3749468d44348114a2994bb8414546.zip
dwarf-fortress.dfhack: make overridable
Currently, it is quite hard to override anything about dfhack (for
example, to add plugins at build time), because

1. it is not exposed anywhere, so you have to do something like
   `dwarf-fortress.override (oldArgs: { dfhack = oldArgs.dfhack.override...; })`
2. the final `dfhack` derivation is a `buildEnv`, so `overrideAttrs`
   doesn't work as expected.

This fixes 1 by adding `dfhack` to the wrapper's `passthru`, and 2 by
moving `twbt.lib` (which is the only reason for the dfhack `buildEnv`)
into the wrapper.

Also adds an `extraPackages` argument to the wrapper, and copies `*.init`
files from the env to the DF directory so that we can easily add a
`dfhack.init`.

With these changes, I was able to build dfhack with the dfplex plugin.
-rw-r--r--pkgs/games/dwarf-fortress/default.nix2
-rw-r--r--pkgs/games/dwarf-fortress/dfhack/default.nix34
-rw-r--r--pkgs/games/dwarf-fortress/wrapper/default.nix26
-rwxr-xr-x[-rw-r--r--]pkgs/games/dwarf-fortress/wrapper/dfhack.in4
4 files changed, 31 insertions, 35 deletions
diff --git a/pkgs/games/dwarf-fortress/default.nix b/pkgs/games/dwarf-fortress/default.nix
index 38253728274..dd8e6b5503d 100644
--- a/pkgs/games/dwarf-fortress/default.nix
+++ b/pkgs/games/dwarf-fortress/default.nix
@@ -69,7 +69,7 @@ let
 
           dfhack = callPackage ./dfhack {
             inherit (perlPackages) XMLLibXML XMLLibXSLT;
-            inherit dfVersion twbt;
+            inherit dfVersion;
             stdenv = gccStdenv;
           };
 
diff --git a/pkgs/games/dwarf-fortress/dfhack/default.nix b/pkgs/games/dwarf-fortress/dfhack/default.nix
index 49e8fabd45e..57bbf0e1162 100644
--- a/pkgs/games/dwarf-fortress/dfhack/default.nix
+++ b/pkgs/games/dwarf-fortress/dfhack/default.nix
@@ -13,8 +13,6 @@
 , allegro5
 , libGLU
 , libGL
-, enableTWBT ? true
-, twbt
 , SDL
 , dfVersion
 }:
@@ -115,9 +113,9 @@ let
       exit 1
     fi
   '';
-
-  dfhack = stdenv.mkDerivation {
-    pname = "dfhack-base";
+in
+  stdenv.mkDerivation {
+    pname = "dfhack";
     inherit version;
 
     # Beware of submodules
@@ -166,21 +164,13 @@ let
       ln -s ${ruby}/lib/libruby-*.so $out/hack/libruby.so
     '';
 
-  };
-in
-
-buildEnv {
-  name = "dfhack-${version}";
+    passthru = { inherit dfVersion; };
 
-  passthru = { inherit version dfVersion; };
-
-  paths = [ dfhack ] ++ lib.optionals enableTWBT [ twbt.lib ];
-
-  meta = with lib; {
-    description = "Memory hacking library for Dwarf Fortress and a set of tools that use it";
-    homepage = "https://github.com/DFHack/dfhack/";
-    license = licenses.zlib;
-    platforms = [ "x86_64-linux" "i686-linux" ];
-    maintainers = with maintainers; [ robbinch a1russell abbradar numinit ];
-  };
-}
+    meta = with lib; {
+      description = "Memory hacking library for Dwarf Fortress and a set of tools that use it";
+      homepage = "https://github.com/DFHack/dfhack/";
+      license = licenses.zlib;
+      platforms = [ "x86_64-linux" "i686-linux" ];
+      maintainers = with maintainers; [ robbinch a1russell abbradar numinit ];
+    };
+  }
diff --git a/pkgs/games/dwarf-fortress/wrapper/default.nix b/pkgs/games/dwarf-fortress/wrapper/default.nix
index 0c1fbc6ca4d..e35575a8e73 100644
--- a/pkgs/games/dwarf-fortress/wrapper/default.nix
+++ b/pkgs/games/dwarf-fortress/wrapper/default.nix
@@ -16,6 +16,7 @@
 , twbt
 , themes ? { }
 , theme ? null
+, extraPackages ? [ ]
   # General config options:
 , enableIntro ? true
 , enableTruetype ? true
@@ -27,7 +28,6 @@
 let
   dfhack_ = dfhack.override {
     inherit enableStoneSense;
-    inherit enableTWBT;
   };
 
   ptheme =
@@ -38,16 +38,16 @@ let
   unBool = b: if b then "YES" else "NO";
 
   # These are in inverse order for first packages to override the next ones.
-  themePkg = lib.optional (theme != null) ptheme;
+  themePkgs = lib.optional (theme != null) ptheme;
   pkgs = lib.optional enableDFHack dfhack_
     ++ lib.optional enableSoundSense soundSense
-    ++ lib.optional enableTWBT twbt.art
+    ++ lib.optionals enableTWBT [ twbt.lib twbt.art ]
     ++ [ dwarf-fortress ];
 
-  fixup = lib.singleton (runCommand "fixup" { } (''
+  config = runCommand "dwarf-fortress-config" { } (''
     mkdir -p $out/data/init
   '' + (if (theme != null) then ''
-    cp ${lib.head themePkg}/data/init/init.txt $out/data/init/init.txt
+    cp ${ptheme}/data/init/init.txt $out/data/init/init.txt
   '' else ''
     cp ${dwarf-fortress}/data/init/init.txt $out/data/init/init.txt
   '') + lib.optionalString enableDFHack ''
@@ -76,21 +76,24 @@ let
   '' + ''
     substituteInPlace $out/data/init/init.txt \
       --replace '[INTRO:YES]' '[INTRO:${unBool enableIntro}]' \
-      --replace '[TRUETYPE:YES]' '[TRUETYPE:${unBool enableTruetype}]' \
+      --replace '[TRUETYPE:24]' '[TRUETYPE:${unBool enableTruetype}]' \
       --replace '[FPS:NO]' '[FPS:${unBool enableFPS}]' \
       --replace '[SOUND:YES]' '[SOUND:${unBool enableSound}]'
-  ''));
+  '');
 
   env = buildEnv {
     name = "dwarf-fortress-env-${dwarf-fortress.dfVersion}";
 
-    paths = fixup ++ themePkg ++ pkgs;
-    pathsToLink = [ "/" "/hack" "/hack/scripts" ];
+    paths = extraPackages ++ [ config ] ++ themePkgs ++ pkgs;
 
     ignoreCollisions = true;
   };
 in
 
+lib.throwIf (enableTWBT && !enableDFHack) "dwarf-fortress: TWBT requires DFHack to be enabled"
+lib.throwIf (enableStoneSense && !enableDFHack) "dwarf-fortress: StoneSense requires DFHack to be enabled"
+lib.throwIf (enableTextMode && enableTWBT) "dwarf-fortress: text mode and TWBT are mutually exclusive"
+
 stdenv.mkDerivation {
   pname = "dwarf-fortress";
   version = dwarf-fortress.dfVersion;
@@ -114,7 +117,10 @@ stdenv.mkDerivation {
   runDFHack = ./dfhack.in;
   runSoundSense = ./soundSense.in;
 
-  passthru = { inherit dwarf-fortress dwarf-therapist; };
+  passthru = {
+    inherit dwarf-fortress dwarf-therapist twbt;
+    dfhack = dfhack_;
+  };
 
   buildCommand = ''
     mkdir -p $out/bin
diff --git a/pkgs/games/dwarf-fortress/wrapper/dfhack.in b/pkgs/games/dwarf-fortress/wrapper/dfhack.in
index 026b33ab87b..0f74674baf2 100644..100755
--- a/pkgs/games/dwarf-fortress/wrapper/dfhack.in
+++ b/pkgs/games/dwarf-fortress/wrapper/dfhack.in
@@ -2,8 +2,8 @@
 
 source @dfInit@
 
-for i in dfhack.init-example dfhack-config/default hack/* stonesense/*; do
-  update_path "$i"
+for i in *.init *.init-example dfhack-config/default dfhack-config/init hack/* stonesense/*; do
+  if [ -e "$i" ]; then update_path "$i"; fi
 done
 
 cd "$DF_DIR"