python312Packages.mandown: 1.10.0 -> 1.10.1 (#370595)
[NixPkgs.git] / pkgs / games / cataclysm-dda / wrapper.nix
blob58d09b1326865c7f76260491ab0bcb2dcd1fc4a4
2   lib,
3   symlinkJoin,
4   makeWrapper,
5 }:
7 unwrapped:
9 pkgsSpec:
11 let
12   mods = if lib.isFunction pkgsSpec then pkgsSpec unwrapped.pkgs else pkgsSpec;
15 if builtins.length mods == 0 then
16   unwrapped
17 else
18   symlinkJoin {
19     name = unwrapped.name + "-with-mods";
21     paths = [ unwrapped ] ++ mods;
23     nativeBuildInputs = [ makeWrapper ];
25     postBuild = ''
26       if [ -x $out/bin/cataclysm ]; then
27           wrapProgram $out/bin/cataclysm \
28               --add-flags "--datadir $out/share/cataclysm-dda/"
29       fi
30       if [ -x $out/bin/cataclysm-tiles ]; then
31           wrapProgram $out/bin/cataclysm-tiles \
32               --add-flags "--datadir $out/share/cataclysm-dda/"
33       fi
35       # Launch the wrapped program
36       replaceProgram() {
37           cp "$1" "''${1}.bk"
38           unlink "$1"
39           mv "''${1}.bk" "$1"
40           sed -i "$1" -e "s,${builtins.storeDir}/.\+\(/bin/cataclysm-tiles\),$out\1,"
41       }
42       for script in "$out/share/applications/cataclysm-dda.desktop" \
43                     "$out/Applications/Cataclysm.app/Contents/MacOS/Cataclysm.sh"
44       do
45           if [ -e "$script" ]; then
46               replaceProgram "$script"
47           fi
48       done
49     '';
50   }