uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
244
pkgs/games/factorio/default.nix
Normal file
244
pkgs/games/factorio/default.nix
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
{ lib, stdenv, fetchurl, makeWrapper, makeDesktopItem
|
||||
, alsa-lib, libpulseaudio, libX11, libXcursor, libXinerama, libXrandr, libXi, libGL
|
||||
, libSM, libICE, libXext, factorio-utils
|
||||
, releaseType
|
||||
, mods ? []
|
||||
, username ? "", token ? "" # get/reset token at https://factorio.com/profile
|
||||
, experimental ? false # true means to always use the latest branch
|
||||
}:
|
||||
|
||||
assert releaseType == "alpha"
|
||||
|| releaseType == "headless"
|
||||
|| releaseType == "demo";
|
||||
|
||||
let
|
||||
|
||||
inherit (lib) importJSON;
|
||||
|
||||
helpMsg = ''
|
||||
|
||||
===FETCH FAILED===
|
||||
Please ensure you have set the username and token with config.nix, or
|
||||
/etc/nix/nixpkgs-config.nix if on NixOS.
|
||||
|
||||
Your token can be seen at https://factorio.com/profile (after logging in). It is
|
||||
not as sensitive as your password, but should still be safeguarded. There is a
|
||||
link on that page to revoke/invalidate the token, if you believe it has been
|
||||
leaked or wish to take precautions.
|
||||
|
||||
Example:
|
||||
{
|
||||
packageOverrides = pkgs: {
|
||||
factorio = pkgs.factorio.override {
|
||||
username = "FactorioPlayer1654";
|
||||
token = "d5ad5a8971267c895c0da598688761";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Alternatively, instead of providing the username+token, you may manually
|
||||
download the release through https://factorio.com/download , then add it to
|
||||
the store using e.g.:
|
||||
|
||||
releaseType=alpha
|
||||
version=0.17.74
|
||||
nix-prefetch-url file://\''$HOME/Downloads/factorio_\''${releaseType}_x64_\''${version}.tar.xz --name factorio_\''${releaseType}_x64-\''${version}.tar.xz
|
||||
|
||||
Note the ultimate "_" is replaced with "-" in the --name arg!
|
||||
'';
|
||||
|
||||
desktopItem = makeDesktopItem {
|
||||
name = "factorio";
|
||||
desktopName = "Factorio";
|
||||
comment = "A game in which you build and maintain factories.";
|
||||
exec = "factorio";
|
||||
icon = "factorio";
|
||||
categories = [ "Game" ];
|
||||
};
|
||||
|
||||
branch = if experimental then "experimental" else "stable";
|
||||
|
||||
# NB `experimental` directs us to take the latest build, regardless of its branch;
|
||||
# hence the (stable, experimental) pairs may sometimes refer to the same distributable.
|
||||
versions = importJSON ./versions.json;
|
||||
binDists = makeBinDists versions;
|
||||
|
||||
actual = binDists.${stdenv.hostPlatform.system}.${releaseType}.${branch} or (throw "Factorio ${releaseType}-${branch} binaries for ${stdenv.hostPlatform.system} are not available for download.");
|
||||
|
||||
makeBinDists = versions:
|
||||
let f = path: name: value:
|
||||
if builtins.isAttrs value then
|
||||
if value ? "name" then
|
||||
makeBinDist value
|
||||
else
|
||||
builtins.mapAttrs (f (path ++ [ name ])) value
|
||||
else
|
||||
throw "expected attrset at ${toString path} - got ${toString value}";
|
||||
in
|
||||
builtins.mapAttrs (f []) versions;
|
||||
makeBinDist = { name, version, tarDirectory, url, sha256, needsAuth }: {
|
||||
inherit version tarDirectory;
|
||||
src =
|
||||
if !needsAuth then
|
||||
fetchurl { inherit name url sha256; }
|
||||
else
|
||||
(lib.overrideDerivation
|
||||
(fetchurl {
|
||||
inherit name url sha256;
|
||||
curlOpts = [
|
||||
"--get"
|
||||
"--data-urlencode" "username@username"
|
||||
"--data-urlencode" "token@token"
|
||||
];
|
||||
})
|
||||
(_: { # This preHook hides the credentials from /proc
|
||||
preHook =
|
||||
if username != "" && token != "" then ''
|
||||
echo -n "${username}" >username
|
||||
echo -n "${token}" >token
|
||||
'' else ''
|
||||
# Deliberately failing since username/token was not provided, so we can't fetch.
|
||||
# We can't use builtins.throw since we want the result to be used if the tar is in the store already.
|
||||
exit 1
|
||||
'';
|
||||
failureHook = ''
|
||||
cat <<EOF
|
||||
${helpMsg}
|
||||
EOF
|
||||
'';
|
||||
}));
|
||||
};
|
||||
|
||||
configBaseCfg = ''
|
||||
use-system-read-write-data-directories=false
|
||||
[path]
|
||||
read-data=$out/share/factorio/data/
|
||||
[other]
|
||||
check_updates=false
|
||||
'';
|
||||
|
||||
updateConfigSh = ''
|
||||
#! $SHELL
|
||||
if [[ -e ~/.factorio/config.cfg ]]; then
|
||||
# Config file exists, but may have wrong path.
|
||||
# Try to edit it. I'm sure this is perfectly safe and will never go wrong.
|
||||
sed -i 's|^read-data=.*|read-data=$out/share/factorio/data/|' ~/.factorio/config.cfg
|
||||
else
|
||||
# Config file does not exist. Phew.
|
||||
install -D $out/share/factorio/config-base.cfg ~/.factorio/config.cfg
|
||||
fi
|
||||
'';
|
||||
|
||||
modDir = factorio-utils.mkModDirDrv mods;
|
||||
|
||||
base = with actual; {
|
||||
pname = "factorio-${releaseType}";
|
||||
inherit version src;
|
||||
|
||||
preferLocalBuild = true;
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/{bin,share/factorio}
|
||||
cp -a data $out/share/factorio
|
||||
cp -a bin/${tarDirectory}/factorio $out/bin/factorio
|
||||
patchelf \
|
||||
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
||||
$out/bin/factorio
|
||||
'';
|
||||
|
||||
passthru.updateScript = if (username != "" && token != "") then [
|
||||
./update.py "--username=${username}" "--token=${token}"
|
||||
] else null;
|
||||
|
||||
meta = {
|
||||
description = "A game in which you build and maintain factories";
|
||||
longDescription = ''
|
||||
Factorio is a game in which you build and maintain factories.
|
||||
|
||||
You will be mining resources, researching technologies, building
|
||||
infrastructure, automating production and fighting enemies. Use your
|
||||
imagination to design your factory, combine simple elements into
|
||||
ingenious structures, apply management skills to keep it working and
|
||||
finally protect it from the creatures who don't really like you.
|
||||
|
||||
Factorio has been in development since spring of 2012, and reached
|
||||
version 1.0 in mid 2020.
|
||||
'';
|
||||
homepage = "https://www.factorio.com/";
|
||||
license = lib.licenses.unfree;
|
||||
maintainers = with lib.maintainers; [ Baughn elitak erictapen priegger lukegb ];
|
||||
platforms = [ "x86_64-linux" ];
|
||||
};
|
||||
};
|
||||
|
||||
releases = rec {
|
||||
headless = base;
|
||||
demo = base // {
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
buildInputs = [ libpulseaudio ];
|
||||
|
||||
libPath = lib.makeLibraryPath [
|
||||
alsa-lib
|
||||
libpulseaudio
|
||||
libX11
|
||||
libXcursor
|
||||
libXinerama
|
||||
libXrandr
|
||||
libXi
|
||||
libGL
|
||||
libSM
|
||||
libICE
|
||||
libXext
|
||||
];
|
||||
|
||||
installPhase = base.installPhase + ''
|
||||
wrapProgram $out/bin/factorio \
|
||||
--prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \
|
||||
--run "$out/share/factorio/update-config.sh" \
|
||||
--argv0 "" \
|
||||
--add-flags "-c \$HOME/.factorio/config.cfg" \
|
||||
${if mods!=[] then "--add-flags --mod-directory=${modDir}" else ""}
|
||||
|
||||
# TODO Currently, every time a mod is changed/added/removed using the
|
||||
# modlist, a new derivation will take up the entire footprint of the
|
||||
# client. The only way to avoid this is to remove the mods arg from the
|
||||
# package function. The modsDir derivation will have to be built
|
||||
# separately and have the user specify it in the .factorio config or
|
||||
# right along side it using a symlink into the store I think i will
|
||||
# just remove mods for the client derivation entirely. this is much
|
||||
# cleaner and more useful for headless mode.
|
||||
|
||||
# TODO: trying to toggle off a mod will result in read-only-fs-error.
|
||||
# not much we can do about that except warn the user somewhere. In
|
||||
# fact, no exit will be clean, since this error will happen on close
|
||||
# regardless. just prints an ugly stacktrace but seems to be otherwise
|
||||
# harmless, unless maybe the user forgets and tries to use the mod
|
||||
# manager.
|
||||
|
||||
install -m0644 <(cat << EOF
|
||||
${configBaseCfg}
|
||||
EOF
|
||||
) $out/share/factorio/config-base.cfg
|
||||
|
||||
install -m0755 <(cat << EOF
|
||||
${updateConfigSh}
|
||||
EOF
|
||||
) $out/share/factorio/update-config.sh
|
||||
|
||||
mkdir -p $out/share/icons/hicolor/{64x64,128x128}/apps
|
||||
cp -a data/core/graphics/factorio-icon.png $out/share/icons/hicolor/64x64/apps/factorio.png
|
||||
cp -a data/core/graphics/factorio-icon@2x.png $out/share/icons/hicolor/128x128/apps/factorio.png
|
||||
ln -s ${desktopItem}/share/applications $out/share/
|
||||
'';
|
||||
};
|
||||
alpha = demo // {
|
||||
|
||||
installPhase = demo.installPhase + ''
|
||||
cp -a doc-html $out/share/factorio
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
in stdenv.mkDerivation (releases.${releaseType})
|
||||
213
pkgs/games/factorio/mods.nix
Normal file
213
pkgs/games/factorio/mods.nix
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
# This file is here for demo purposes only, populated with a small sampling of
|
||||
# mods. It will eventually be replaced by a nixos-channel that will provide
|
||||
# derivations for most or all of the mods tracked through the official mod
|
||||
# manager site.
|
||||
{ lib, fetchurl
|
||||
, factorio-utils
|
||||
, allRecommendedMods ? true
|
||||
, allOptionalMods ? false
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
modDrv = factorio-utils.modDrv { inherit allRecommendedMods allOptionalMods; };
|
||||
in
|
||||
rec {
|
||||
|
||||
bobassembly = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobassembly_0.13.0.zip"
|
||||
];
|
||||
sha256 = "0c0m7sb45r37g882x0aq8mc82yhfh9j9h8g018d4s5pf93vzr6d1";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates ];
|
||||
};
|
||||
|
||||
bobconfig = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobconfig_0.13.1.zip"
|
||||
];
|
||||
sha256 = "0z4kmggm1slbr3qiy5xahc9nhdffllp21n9nv5gh1zbzv72sb1rp";
|
||||
};
|
||||
};
|
||||
|
||||
bobelectronics = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobelectronics_0.13.1.zip"
|
||||
];
|
||||
sha256 = "16sn5w33s0ckiwqxx7b2pcsqmhxbxjm2w4h4vd99hwpvdpjyav52";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates ];
|
||||
};
|
||||
|
||||
bobenemies = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobenemies_0.13.1.zip"
|
||||
];
|
||||
sha256 = "1wnb5wsvh9aa3i9mj17f36ybbd13qima3iwshw60i6xkzzqfk44d";
|
||||
};
|
||||
optionalDeps = [ bobconfig ];
|
||||
};
|
||||
|
||||
bobgreenhouse = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobgreenhouse_0.13.2.zip"
|
||||
];
|
||||
sha256 = "1ql26875dvz2lqln289jg1w6yjzsd0x0pqmd570jffwi5m320rrw";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates ];
|
||||
};
|
||||
|
||||
bobinserters = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobinserters_0.13.3.zip"
|
||||
];
|
||||
sha256 = "0nys9zhaw0v3w2xzrhawr8g2hcxkzdmyqd4s8xm5bnbrgrq86g9z";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ ];
|
||||
};
|
||||
|
||||
boblibrary = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/boblibrary_0.13.1.zip"
|
||||
];
|
||||
sha256 = "04fybs626lzxf0p21jl8kakh2mddah7l9m57srk7a87jw5bj1zx8";
|
||||
};
|
||||
};
|
||||
|
||||
boblogistics = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/boblogistics_0.13.7.zip"
|
||||
];
|
||||
sha256 = "0c91zmyxwsmyv6vm6gp498vb7flqlcyzkbp9s5q1651hpyd378hx";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates ];
|
||||
};
|
||||
|
||||
bobmining = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobmining_0.13.1.zip"
|
||||
];
|
||||
sha256 = "1l7k3v4aizihppgi802fr5b8zbnq2h05c2bbsk5hds239qgxy80m";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig bobores bobplates ];
|
||||
};
|
||||
|
||||
bobmodules = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobmodules_0.13.0.zip"
|
||||
];
|
||||
sha256 = "0ggd2gc4s5sbld7gyncbzdgq8gc00mvxjcfv7i2dchcrdzrlr556";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates bobassembly bobelectronics ];
|
||||
};
|
||||
|
||||
bobores = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobores_0.13.1.zip"
|
||||
];
|
||||
sha256 = "1rri70655kj77sdr3zgp56whmcl0gfjmw90jm7lj1jp8l1pdfzb9";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
};
|
||||
|
||||
bobplates = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobplates_0.13.2.zip"
|
||||
];
|
||||
sha256 = "0iczpa26hflj17k84p4n6wz0pwhbbrfk86dgac4bfz28kqg58nj1";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig bobenemies ];
|
||||
recommendedDeps = [ bobores bobtech ];
|
||||
};
|
||||
|
||||
bobpower = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobpower_0.13.1.zip"
|
||||
];
|
||||
sha256 = "18sblnlvprrm2vzlczlki09yj9lr4y64808zrwmcasf7470skar3";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobconfig ];
|
||||
recommendedDeps = [ bobplates ];
|
||||
};
|
||||
|
||||
bobrevamp = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobrevamp_0.13.0.zip"
|
||||
];
|
||||
sha256 = "0rkyf61clh8fjg72z9i7r4skvdzgd49ky6s0486xxljhbil4nxb7";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
};
|
||||
|
||||
bobtech = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobtech_0.13.0.zip"
|
||||
];
|
||||
sha256 = "0arc9kilxzdpapn3gh5h8269ssgsjxib4ny0qissq2sg95gxlsn0";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ bobenemies ];
|
||||
};
|
||||
|
||||
bobtechsave = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobtechsave_0.13.0.zip"
|
||||
];
|
||||
sha256 = "1vlv4sgdfd9ldjm8y79n95ms5k6x2i7khjc422lp9080m03v1hcl";
|
||||
};
|
||||
};
|
||||
|
||||
bobwarfare = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/bobwarfare_0.13.4.zip"
|
||||
];
|
||||
sha256 = "07wzn16i4r0qjm41wfyl17rrhry2vrph08a0kq8w5iy6qcbqqfd3";
|
||||
};
|
||||
deps = [ boblibrary ];
|
||||
optionalDeps = [ boblibrary bobplates ];
|
||||
recommendedDeps = [ bobtech ];
|
||||
};
|
||||
|
||||
clock = modDrv {
|
||||
src = fetchurl {
|
||||
urls = [
|
||||
"https://f.xor.us/factorio-mods/clock_0.13.0.zip"
|
||||
];
|
||||
sha256 = "0nflywbj6p2kz2w9wff78vskzljrzaf32ib56k3z456d9y8mlxfd";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
190
pkgs/games/factorio/update.py
Executable file
190
pkgs/games/factorio/update.py
Executable file
|
|
@ -0,0 +1,190 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i python -p "python3.withPackages (ps: with ps; [ ps.absl-py ps.requests ])" nix
|
||||
|
||||
from collections import defaultdict
|
||||
import copy
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
import os.path
|
||||
import subprocess
|
||||
from typing import Callable, Dict
|
||||
|
||||
from absl import app
|
||||
from absl import flags
|
||||
from absl import logging
|
||||
import requests
|
||||
|
||||
|
||||
FACTORIO_API = "https://factorio.com/api/latest-releases"
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
flags.DEFINE_string('username', '', 'Factorio username for retrieving binaries.')
|
||||
flags.DEFINE_string('token', '', 'Factorio token for retrieving binaries.')
|
||||
flags.DEFINE_string('out', '', 'Output path for versions.json.')
|
||||
flags.DEFINE_list('release_type', '', 'If non-empty, a comma-separated list of release types to update (e.g. alpha).')
|
||||
flags.DEFINE_list('release_channel', '', 'If non-empty, a comma-separated list of release channels to update (e.g. experimental).')
|
||||
|
||||
|
||||
@dataclass
|
||||
class System:
|
||||
nix_name: str
|
||||
url_name: str
|
||||
tar_name: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReleaseType:
|
||||
name: str
|
||||
needs_auth: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReleaseChannel:
|
||||
name: str
|
||||
|
||||
|
||||
FactorioVersionsJSON = Dict[str, Dict[str, str]]
|
||||
OurVersionJSON = Dict[str, Dict[str, Dict[str, Dict[str, str]]]]
|
||||
|
||||
|
||||
SYSTEMS = [
|
||||
System(nix_name="x86_64-linux", url_name="linux64", tar_name="x64"),
|
||||
]
|
||||
|
||||
RELEASE_TYPES = [
|
||||
ReleaseType("alpha", needs_auth=True),
|
||||
ReleaseType("demo"),
|
||||
ReleaseType("headless"),
|
||||
]
|
||||
|
||||
RELEASE_CHANNELS = [
|
||||
ReleaseChannel("experimental"),
|
||||
ReleaseChannel("stable"),
|
||||
]
|
||||
|
||||
|
||||
def find_versions_json() -> str:
|
||||
if FLAGS.out:
|
||||
return FLAGS.out
|
||||
try_paths = ["pkgs/games/factorio/versions.json", "versions.json"]
|
||||
for path in try_paths:
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
raise Exception("Couldn't figure out where to write versions.json; try specifying --out")
|
||||
|
||||
|
||||
def fetch_versions() -> FactorioVersionsJSON:
|
||||
return json.loads(requests.get("https://factorio.com/api/latest-releases").text)
|
||||
|
||||
|
||||
def generate_our_versions(factorio_versions: FactorioVersionsJSON) -> OurVersionJSON:
|
||||
rec_dd = lambda: defaultdict(rec_dd)
|
||||
output = rec_dd()
|
||||
|
||||
# Deal with times where there's no experimental version
|
||||
for rc in RELEASE_CHANNELS:
|
||||
if not factorio_versions[rc.name]:
|
||||
factorio_versions[rc.name] = factorio_versions['stable']
|
||||
|
||||
for system in SYSTEMS:
|
||||
for release_type in RELEASE_TYPES:
|
||||
for release_channel in RELEASE_CHANNELS:
|
||||
version = factorio_versions[release_channel.name].get(release_type.name)
|
||||
if version == None:
|
||||
continue
|
||||
this_release = {
|
||||
"name": f"factorio_{release_type.name}_{system.tar_name}-{version}.tar.xz",
|
||||
"url": f"https://factorio.com/get-download/{version}/{release_type.name}/{system.url_name}",
|
||||
"version": version,
|
||||
"needsAuth": release_type.needs_auth,
|
||||
"tarDirectory": system.tar_name,
|
||||
}
|
||||
output[system.nix_name][release_type.name][release_channel.name] = this_release
|
||||
return output
|
||||
|
||||
|
||||
def iter_version(versions: OurVersionJSON, it: Callable[[str, str, str, Dict[str, str]], Dict[str, str]]) -> OurVersionJSON:
|
||||
versions = copy.deepcopy(versions)
|
||||
for system_name, system in versions.items():
|
||||
for release_type_name, release_type in system.items():
|
||||
for release_channel_name, release in release_type.items():
|
||||
release_type[release_channel_name] = it(system_name, release_type_name, release_channel_name, dict(release))
|
||||
return versions
|
||||
|
||||
|
||||
def merge_versions(old: OurVersionJSON, new: OurVersionJSON) -> OurVersionJSON:
|
||||
"""Copies already-known hashes from version.json to avoid having to re-fetch."""
|
||||
def _merge_version(system_name: str, release_type_name: str, release_channel_name: str, release: Dict[str, str]) -> Dict[str, str]:
|
||||
old_system = old.get(system_name, {})
|
||||
old_release_type = old_system.get(release_type_name, {})
|
||||
old_release = old_release_type.get(release_channel_name, {})
|
||||
if FLAGS.release_type and release_type_name not in FLAGS.release_type:
|
||||
logging.info("%s/%s/%s: not in --release_type, not updating", system_name, release_type_name, release_channel_name)
|
||||
return old_release
|
||||
if FLAGS.release_channel and release_channel_name not in FLAGS.release_channel:
|
||||
logging.info("%s/%s/%s: not in --release_channel, not updating", system_name, release_type_name, release_channel_name)
|
||||
return old_release
|
||||
if not "sha256" in old_release:
|
||||
logging.info("%s/%s/%s: not copying sha256 since it's missing", system_name, release_type_name, release_channel_name)
|
||||
return release
|
||||
if not all(old_release.get(k, None) == release[k] for k in ['name', 'version', 'url']):
|
||||
logging.info("%s/%s/%s: not copying sha256 due to mismatch", system_name, release_type_name, release_channel_name)
|
||||
return release
|
||||
release["sha256"] = old_release["sha256"]
|
||||
return release
|
||||
return iter_version(new, _merge_version)
|
||||
|
||||
|
||||
def nix_prefetch_url(name: str, url: str, algo: str = 'sha256') -> str:
|
||||
cmd = ['nix-prefetch-url', '--type', algo, '--name', name, url]
|
||||
logging.info('running %s', cmd)
|
||||
out = subprocess.check_output(cmd)
|
||||
return out.decode('utf-8').strip()
|
||||
|
||||
|
||||
def fill_in_hash(versions: OurVersionJSON) -> OurVersionJSON:
|
||||
"""Fill in sha256 hashes for anything missing them."""
|
||||
urls_to_hash = {}
|
||||
def _fill_in_hash(system_name: str, release_type_name: str, release_channel_name: str, release: Dict[str, str]) -> Dict[str, str]:
|
||||
if "sha256" in release:
|
||||
logging.info("%s/%s/%s: skipping fetch, sha256 already present", system_name, release_type_name, release_channel_name)
|
||||
return release
|
||||
url = release["url"]
|
||||
if url in urls_to_hash:
|
||||
logging.info("%s/%s/%s: found url %s in cache", system_name, release_type_name, release_channel_name, url)
|
||||
release["sha256"] = urls_to_hash[url]
|
||||
return release
|
||||
logging.info("%s/%s/%s: fetching %s", system_name, release_type_name, release_channel_name, url)
|
||||
if release["needsAuth"]:
|
||||
if not FLAGS.username or not FLAGS.token:
|
||||
raise Exception("fetching %s/%s/%s from %s requires --username and --token" % (system_name, release_type_name, release_channel_name, url))
|
||||
url += f"?username={FLAGS.username}&token={FLAGS.token}"
|
||||
release["sha256"] = nix_prefetch_url(release["name"], url)
|
||||
urls_to_hash[url] = release["sha256"]
|
||||
return release
|
||||
return iter_version(versions, _fill_in_hash)
|
||||
|
||||
|
||||
def main(argv):
|
||||
factorio_versions = fetch_versions()
|
||||
new_our_versions = generate_our_versions(factorio_versions)
|
||||
old_our_versions = None
|
||||
our_versions_path = find_versions_json()
|
||||
if our_versions_path:
|
||||
logging.info('Loading old versions.json from %s', our_versions_path)
|
||||
with open(our_versions_path, 'r') as f:
|
||||
old_our_versions = json.load(f)
|
||||
if old_our_versions:
|
||||
logging.info('Merging in old hashes')
|
||||
new_our_versions = merge_versions(old_our_versions, new_our_versions)
|
||||
logging.info('Fetching necessary tars to get hashes')
|
||||
new_our_versions = fill_in_hash(new_our_versions)
|
||||
with open(our_versions_path, 'w') as f:
|
||||
logging.info('Writing versions.json to %s', our_versions_path)
|
||||
json.dump(new_our_versions, f, sort_keys=True, indent=2)
|
||||
f.write("\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(main)
|
||||
49
pkgs/games/factorio/utils.nix
Normal file
49
pkgs/games/factorio/utils.nix
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# This file provides a top-level function that will be used by both nixpkgs and nixos
|
||||
# to generate mod directories for use at runtime by factorio.
|
||||
{ lib, stdenv }:
|
||||
with lib;
|
||||
{
|
||||
mkModDirDrv = mods: # a list of mod derivations
|
||||
let
|
||||
recursiveDeps = modDrv: [modDrv] ++ map recursiveDeps modDrv.deps;
|
||||
modDrvs = unique (flatten (map recursiveDeps mods));
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "factorio-mod-directory";
|
||||
|
||||
preferLocalBuild = true;
|
||||
buildCommand = ''
|
||||
mkdir -p $out
|
||||
for modDrv in ${toString modDrvs}; do
|
||||
# NB: there will only ever be a single zip file in each mod derivation's output dir
|
||||
ln -s $modDrv/*.zip $out
|
||||
done
|
||||
'';
|
||||
};
|
||||
|
||||
modDrv = { allRecommendedMods, allOptionalMods }:
|
||||
{ src
|
||||
, name ? null
|
||||
, deps ? []
|
||||
, optionalDeps ? []
|
||||
, recommendedDeps ? []
|
||||
}: stdenv.mkDerivation {
|
||||
|
||||
inherit src;
|
||||
|
||||
# Use the name of the zip, but endstrip ".zip" and possibly the querystring that gets left in by fetchurl
|
||||
name = replaceStrings ["_"] ["-"] (if name != null then name else removeSuffix ".zip" (head (splitString "?" src.name)));
|
||||
|
||||
deps = deps ++ optionals allOptionalMods optionalDeps
|
||||
++ optionals allRecommendedMods recommendedDeps;
|
||||
|
||||
preferLocalBuild = true;
|
||||
buildCommand = ''
|
||||
mkdir -p $out
|
||||
srcBase=$(basename $src)
|
||||
srcBase=''${srcBase#*-} # strip nix hash
|
||||
srcBase=''${srcBase%\?*} # strip querystring leftover from fetchurl
|
||||
cp $src $out/$srcBase
|
||||
'';
|
||||
};
|
||||
}
|
||||
58
pkgs/games/factorio/versions.json
Normal file
58
pkgs/games/factorio/versions.json
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"x86_64-linux": {
|
||||
"alpha": {
|
||||
"experimental": {
|
||||
"name": "factorio_alpha_x64-1.1.59.tar.xz",
|
||||
"needsAuth": true,
|
||||
"sha256": "0qwq3mjsmhb119pvbfznpncw898z4zs2if4fd7p6rqfz0wip93qk",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/alpha/linux64",
|
||||
"version": "1.1.59"
|
||||
},
|
||||
"stable": {
|
||||
"name": "factorio_alpha_x64-1.1.59.tar.xz",
|
||||
"needsAuth": true,
|
||||
"sha256": "0qwq3mjsmhb119pvbfznpncw898z4zs2if4fd7p6rqfz0wip93qk",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/alpha/linux64",
|
||||
"version": "1.1.59"
|
||||
}
|
||||
},
|
||||
"demo": {
|
||||
"experimental": {
|
||||
"name": "factorio_demo_x64-1.1.59.tar.xz",
|
||||
"needsAuth": false,
|
||||
"sha256": "1nddk8184kgq4ni0y9j2l8sa3szvcbsq9l90b35l9jb6sqflgki0",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/demo/linux64",
|
||||
"version": "1.1.59"
|
||||
},
|
||||
"stable": {
|
||||
"name": "factorio_demo_x64-1.1.59.tar.xz",
|
||||
"needsAuth": false,
|
||||
"sha256": "1nddk8184kgq4ni0y9j2l8sa3szvcbsq9l90b35l9jb6sqflgki0",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/demo/linux64",
|
||||
"version": "1.1.59"
|
||||
}
|
||||
},
|
||||
"headless": {
|
||||
"experimental": {
|
||||
"name": "factorio_headless_x64-1.1.59.tar.xz",
|
||||
"needsAuth": false,
|
||||
"sha256": "1p5wyki6wxnvnp7zqjjw9yggiy0p78rx49wmq3q7kq0mxfz054dg",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/headless/linux64",
|
||||
"version": "1.1.59"
|
||||
},
|
||||
"stable": {
|
||||
"name": "factorio_headless_x64-1.1.59.tar.xz",
|
||||
"needsAuth": false,
|
||||
"sha256": "1p5wyki6wxnvnp7zqjjw9yggiy0p78rx49wmq3q7kq0mxfz054dg",
|
||||
"tarDirectory": "x64",
|
||||
"url": "https://factorio.com/get-download/1.1.59/headless/linux64",
|
||||
"version": "1.1.59"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue