diff --git a/nix/pkgs/archipelago/default.nix b/nix/pkgs/archipelago/default.nix new file mode 100644 index 0000000000..cec65e3be3 --- /dev/null +++ b/nix/pkgs/archipelago/default.nix @@ -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 <$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; + }; +} diff --git a/nix/pkgs/archipelago/factorio-rcon-py.nix b/nix/pkgs/archipelago/factorio-rcon-py.nix new file mode 100644 index 0000000000..5eedcb53c0 --- /dev/null +++ b/nix/pkgs/archipelago/factorio-rcon-py.nix @@ -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 + ]; +} diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index a1f365dade..6076deaff1 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -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)