anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / games / cataclysm-dda / wrapper.nix
blob28189fa7375a9b22ed3f85d778ad11f8f4b7919c
1 { lib, symlinkJoin, makeWrapper }:
3 unwrapped:
5 pkgsSpec:
7 let
8   mods = if lib.isFunction pkgsSpec
9          then pkgsSpec unwrapped.pkgs
10          else pkgsSpec;
13 if builtins.length mods == 0
14 then unwrapped
15 else symlinkJoin {
16   name = unwrapped.name + "-with-mods";
18   paths = [ unwrapped ] ++ mods;
20   nativeBuildInputs = [ makeWrapper ];
22   postBuild = ''
23     if [ -x $out/bin/cataclysm ]; then
24         wrapProgram $out/bin/cataclysm \
25             --add-flags "--datadir $out/share/cataclysm-dda/"
26     fi
27     if [ -x $out/bin/cataclysm-tiles ]; then
28         wrapProgram $out/bin/cataclysm-tiles \
29             --add-flags "--datadir $out/share/cataclysm-dda/"
30     fi
32     # Launch the wrapped program
33     replaceProgram() {
34         cp "$1" "''${1}.bk"
35         unlink "$1"
36         mv "''${1}.bk" "$1"
37         sed -i "$1" -e "s,${builtins.storeDir}/.\+\(/bin/cataclysm-tiles\),$out\1,"
38     }
39     for script in "$out/share/applications/cataclysm-dda.desktop" \
40                   "$out/Applications/Cataclysm.app/Contents/MacOS/Cataclysm.sh"
41     do
42         if [ -e "$script" ]; then
43             replaceProgram "$script"
44         fi
45     done
46   '';