nix/pkgs: add archipelago

This commit is contained in:
Luke Granger-Brown 2023-08-27 22:43:59 +00:00
parent c7f94ff3ce
commit 7ce98e6613
3 changed files with 166 additions and 0 deletions

View file

@ -0,0 +1,134 @@
{ buildPythonApplication
, fetchFromGitHub
, writeShellScript
, lib
, python
, bsdiff4
, certifi
, colorama
, cymem
, cython
, jellyfish
, jinja2
, kivy
, platformdirs
, pyyaml
, schema
, websockets
, enabledWorlds ? [ "generic" "factorio" ]
# factorio
, factorio-rcon-py
, withWebHostLib ? true
, flask
, pony
, waitress
, flask-caching
, flask-compress
, flask-limiter
, bokeh
, markupsafe
}:
let
worldEnabled = worldName: lib.any (x: x == worldName) enabledWorlds;
in
buildPythonApplication rec {
pname = "archipelago";
version = "0.4.1";
src = fetchFromGitHub {
owner = "ArchipelagoMW";
repo = "Archipelago";
rev = version;
sha256 = "03jqxf9gj5a60cw3zp1vzq4wx9436v4mdrfx5g6p04a5slfz3x4m";
};
propagatedBuildInputs = [
bsdiff4
certifi
colorama
cymem
cython
jellyfish
jinja2
kivy
platformdirs
pyyaml
schema
websockets
] ++ (lib.optionals (worldEnabled "factorio") [
factorio-rcon-py
]) ++ (lib.optionals withWebHostLib [
flask
pony
waitress
flask-caching
flask-compress
flask-limiter
bokeh
markupsafe
]);
format = "other";
postPatch = ''
# Disable ModuleUpdate; we're effectively frozen.
sed -i 's,^update_ran = .*,update_ran = True,' ModuleUpdate.py
'';
buildPhase = ''
runHook preBuild
install -d worlds_disabled
for f in worlds/*; do
test -d $f || continue
worldName="$(basename $f)"
[[ " ''${enabledWorlds[@]} " =~ " ''${worldName} " ]] && continue
echo "Disabling $worldName - not explicitly enabled" >&2
mv worlds/$worldName worlds_disabled/$worldName
done
runHook postBuild
'';
inherit enabledWorlds;
__structuredAttrs = true;
installPhase = ''
runHook preInstall
export INSTALLDIR=$out/${python.sitePackages}/archipelago
install -d $INSTALLDIR
cp -R ./ -t $INSTALLDIR
mkdir $out/bin
makeEntrypoint() {
local name="$1"
local module="$2"
cat <<EOF >$out/bin/$1
#!/bin/sh
export PYTHONPATH=$PYTHONPATH:$out/${python.sitePackages}:$INSTALLDIR
exec ${python}/bin/python -m "$2" "\$@"
EOF
chmod +x $out/bin/$1
}
${lib.optionalString (worldEnabled "factorio") "makeEntrypoint archipelago-factorio archipelago.FactorioClient"}
makeEntrypoint archipelago-generate archipelago.Generate
makeEntrypoint archipelago-multiserver archipelago.MultiServer
makeEntrypoint archipelago-webhost archipelago.WebHost
makeEntrypoint archipelago-launcher archipelago.Launcher
install -d $INSTALLDIR/Players
install -d $INSTALLDIR/data/sprites
echo '{}' > $INSTALLDIR/manifest.json
runHook postInstall
'';
passthru = {
inherit factorio-rcon-py;
};
}

View file

@ -0,0 +1,27 @@
{ buildPythonPackage
, fetchFromGitHub
, lib
, setuptools
, anyio
}:
buildPythonPackage rec {
pname = "factorio-rcon-py";
version = "2.0.1";
src = fetchFromGitHub {
owner = "mark9064";
repo = "factorio-rcon-py";
rev = "v${version}";
sha256 = "sha256:16awga3pgs5jnb2x46bhikjdrmh6zv6r5yf60lcdyd3bm2qlrq56";
};
format = "pyproject";
nativeBuildInputs = [
setuptools
];
propagatedBuildInputs = [
anyio
];
}

View file

@ -77,4 +77,9 @@
tailscale = import ./tailscale pkgs.tailscale;
intel-oclcpuexp = pkgs.callPackage ./intel-oclcpuexp { };
archipelago = let callPackage = pkgs.python310.pkgs.callPackage; in
callPackage ./archipelago {
factorio-rcon-py = callPackage ./archipelago/factorio-rcon-py.nix { };
};
} // (import ./heptapod-runner args)