Skip to content

Commit e5cca0a

Browse files
Merge master into staging-next
2 parents 91db327 + 37592f1 commit e5cca0a

File tree

21 files changed

+342
-160
lines changed

21 files changed

+342
-160
lines changed

doc/build-helpers/fetchers.chapter.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,27 @@ fetchtorrent {
10031003

10041004
- `config`: When using `transmission` as the `backend`, a json configuration can
10051005
be supplied to transmission. Refer to the [upstream documentation](https://github.com/transmission/transmission/blob/main/docs/Editing-Configuration-Files.md) for information on how to configure.
1006+
1007+
## `fetchItchIo` {#fetchitchio}
1008+
1009+
`fetchItchIo` is a fetcher for downloading game assets from [itch.io](https://itch.io/). It accepts these arguments:
1010+
1011+
- `gameUrl`: The store page URL of the game.
1012+
- `upload`: The numerical ID of the asset to download. To find the upload ID of an asset, check the basename of the request URL when you download the asset using a browser.
1013+
- `hash`.
1014+
- `name` (optional): The derivation name, often the filename of the asset.
1015+
- `extraMessage` (optional): Extra message printed if the API key is not provided or if the account did not purchase the game.
1016+
1017+
For this fetcher to work, the environment variable `NIX_ITCHIO_API_KEY` must be set for the nix building process (which is nix-daemon in multi-user mode), and it must belong to an account that has bought the game if it is behind a paywall.
1018+
To get your API key, go to the ["API key" section](https://itch.io/user/settings/api-keys) of your account settings on itch.io.
1019+
1020+
```nix
1021+
{ fetchItchIo }:
1022+
1023+
fetchItchIo {
1024+
name = "DungeonDuelMonsters-linux-x64.zip";
1025+
hash = "sha256-gq2nGwpaStqaVI1pL63xygxOI/z53o+zLwiKizG98Ks=";
1026+
gameUrl = "https://mikaygo.itch.io/ddm";
1027+
upload = "13371354";
1028+
}
1029+
```

doc/redirects.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,9 @@
18181818
"fetchtorrent-parameters": [
18191819
"index.html#fetchtorrent-parameters"
18201820
],
1821+
"fetchitchio": [
1822+
"index.html#fetchitchio"
1823+
],
18211824
"chap-trivial-builders": [
18221825
"index.html#chap-trivial-builders"
18231826
],

pkgs/applications/networking/browsers/firefox/packages/firefox-devedition.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
buildMozillaMach rec {
1111
pname = "firefox-devedition";
1212
binaryName = "firefox-devedition";
13-
version = "148.0b14";
13+
version = "148.0b15";
1414
applicationName = "Firefox Developer Edition";
1515
requireSigning = false;
1616
branding = "browser/branding/aurora";
1717
src = fetchurl {
1818
url = "mirror://mozilla/devedition/releases/${version}/source/firefox-${version}.source.tar.xz";
19-
sha512 = "10de6926c3c20fcbffe2f25f97213ac777e4ce3984cb303262ddaef15be24788a40c6064ce8cc138ab3a35ba621efdcd0f6e0a105b2e773f7f14a1d661c10693";
19+
sha512 = "32d7e4b9df739d5bdab2cd54250b1c7546d26b248a62e0bbc71e4b78b12d4e3d6d9451b631a0f18568f2540141786967a33b6543256a6ec6f4f245093d37a5d5";
2020
};
2121

2222
# buildMozillaMach sets MOZ_APP_REMOTINGNAME during configuration, but
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
lib,
3+
stdenvNoCC,
4+
python3,
5+
}:
6+
7+
lib.extendMkDerivation {
8+
constructDrv = stdenvNoCC.mkDerivation;
9+
excludeDrvArgNames = [
10+
"derivationArgs"
11+
"sha1"
12+
"sha256"
13+
"sha512"
14+
];
15+
extendDrvArgs =
16+
finalAttrs:
17+
lib.fetchers.withNormalizedHash { } (
18+
{
19+
20+
endpoint ? "https://api.itch.io",
21+
22+
# The name of the environment variable that contains the itch.io API key.
23+
# The environment variable needs to be set for the nix building process,
24+
# which is nix-daemon for multi-user mode.
25+
apiKeyVar ? "NIX_ITCHIO_API_KEY",
26+
27+
# The game store page URL in the format of https://{author}.itch.io/{game}
28+
gameUrl,
29+
30+
# The upload ID of the downloadable file.
31+
# To get the upload ID, look at the request URL when you download it.
32+
upload,
33+
34+
# Derivation name.
35+
name ? null,
36+
37+
# The extra message printed when the API key is not provided
38+
# or when the account of the API key did not purchase the game.
39+
extraMessage ? null,
40+
41+
# Show the download URL without actually downloading it, for testing purposes.
42+
# Notice that this can potentially leak the API key.
43+
showUrl ? false,
44+
45+
outputHash ? lib.fakeHash,
46+
outputHashAlgo ? null,
47+
preFetch ? "",
48+
postFetch ? "",
49+
nativeBuildInputs ? [ ],
50+
impureEnvVars ? [ ],
51+
passthru ? { },
52+
meta ? { },
53+
preferLocalBuild ? true,
54+
derivationArgs ? { },
55+
}:
56+
let
57+
finalHashHasColon = lib.hasInfix ":" finalAttrs.hash;
58+
finalHashColonMatch = lib.match "([^:]+)[:](.*)" finalAttrs.hash;
59+
in
60+
derivationArgs
61+
// {
62+
__structuredAttrs = true;
63+
64+
name = if name != null then name else baseNameOf gameUrl;
65+
66+
hash =
67+
if outputHashAlgo == null || outputHash == "" || lib.hasPrefix outputHashAlgo outputHash then
68+
outputHash
69+
else
70+
"${outputHashAlgo}:${outputHash}";
71+
outputHash =
72+
if finalAttrs.hash == "" then
73+
lib.fakeHash
74+
else if finalHashHasColon then
75+
lib.elemAt finalHashColonMatch 1
76+
else
77+
finalAttrs.hash;
78+
outputHashAlgo = if finalHashHasColon then lib.head finalHashColonMatch else null;
79+
outputHashMode = "flat";
80+
81+
nativeBuildInputs = [ python3 ] ++ nativeBuildInputs;
82+
83+
inherit preferLocalBuild;
84+
85+
# ENV
86+
nixpkgsVersion = lib.trivial.release;
87+
uploadName = name;
88+
inherit
89+
endpoint
90+
apiKeyVar
91+
gameUrl
92+
extraMessage
93+
showUrl
94+
preFetch
95+
postFetch
96+
;
97+
impureEnvVars =
98+
lib.fetchers.proxyImpureEnvVars
99+
++ [
100+
apiKeyVar
101+
"NIX_CONNECT_TIMEOUT"
102+
]
103+
++ impureEnvVars;
104+
105+
builder = builtins.toFile "builder.sh" ''
106+
source "$NIX_ATTRS_SH_FILE"
107+
runHook preFetch
108+
python ${./fetchitchio.py}
109+
runHook postFetch
110+
'';
111+
}
112+
);
113+
114+
inheritFunctionArgs = false;
115+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import itertools
2+
import json
3+
import os
4+
import platform
5+
import shutil
6+
import sys
7+
import urllib.error
8+
import urllib.parse
9+
import urllib.request
10+
11+
with open(os.environ['NIX_ATTRS_JSON_FILE']) as env_file:
12+
ENV = json.load(env_file)
13+
14+
USER_AGENT = f'Python/{platform.python_version()} Nixpkgs/{ENV['nixpkgsVersion']}'
15+
TIMEOUT = float(os.environ.get('NIX_CONNECT_TIMEOUT') or '15')
16+
17+
ENDPOINT = ENV['endpoint']
18+
GAME_URL = ENV['gameUrl']
19+
UPLOAD_ID = ENV['upload']
20+
21+
def abort(message):
22+
if 'extraMessage' in ENV:
23+
message = f'{message} {ENV['extraMessage']}'
24+
print(message, file=sys.stderr)
25+
sys.exit(1)
26+
27+
try:
28+
API_KEY = os.environ[ENV['apiKeyVar']]
29+
except KeyError:
30+
abort(
31+
f'Either set {ENV['apiKeyVar']} for the nix building process '
32+
f'or manually download {ENV.get('uploadName', 'the required file')} '
33+
f'from {GAME_URL} and add it to nix store.'
34+
)
35+
36+
def urlopen(url_or_request):
37+
return urllib.request.urlopen(url_or_request, timeout=TIMEOUT)
38+
39+
with urlopen(f'{GAME_URL}/data.json') as response:
40+
data = json.load(response)
41+
GAME_ID = data['id']
42+
IS_FREE = 'price' not in data
43+
44+
def api(path, params={}, download=False):
45+
url = f'{ENDPOINT}{path}?{urllib.parse.urlencode({'api_key': API_KEY, **params})}'
46+
if download and ENV['showUrl']:
47+
with open(os.environ['out'], 'w') as output_file:
48+
print(url, file=output_file)
49+
return
50+
request = urllib.request.Request(url, headers={'User-Agent': USER_AGENT})
51+
with urlopen(request) as response:
52+
if download:
53+
with open(os.environ['out'], 'wb') as output_file:
54+
shutil.copyfileobj(response, output_file)
55+
else:
56+
return json.load(response)
57+
58+
if IS_FREE:
59+
api(f'/uploads/{UPLOAD_ID}/download', download=True)
60+
sys.exit()
61+
62+
KEY_ID = None
63+
for page in itertools.count(1):
64+
data = api('/profile/owned-keys', {'page': page})
65+
if 'owned_keys' not in data:
66+
break
67+
for key in data['owned_keys']:
68+
if key['game_id'] == GAME_ID:
69+
KEY_ID = key['id']
70+
break
71+
if len(data['owned_keys']) < data['per_page']:
72+
break
73+
if not KEY_ID:
74+
abort(f'Cannot find a key associated with {GAME_URL}. Did you buy the game?')
75+
76+
api(f'/uploads/{UPLOAD_ID}/download', {'download_key_id': KEY_ID}, download=True)

pkgs/by-name/ce/celestegame/celeste.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ stdenvNoCC.mkDerivation {
5757

5858
src =
5959
if overrideSrc == null then
60+
# TODO: Replace this with fetchItchIo
6061
requireFile {
6162
name = "celeste-linux.zip";
6263
hash = "sha256-phNDBBHb7zwMRaBHT5D0hFEilkx9F31p6IllvLhHQb8=";

pkgs/by-name/dd/ddm/package.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
stdenvNoCC,
33
lib,
4-
requireFile,
4+
fetchItchIo,
55
asar,
66
copyDesktopItems,
77
electron,
@@ -18,10 +18,11 @@ stdenvNoCC.mkDerivation (finalAttrs: {
1818
pname = "ddm";
1919
version = "4.1.0";
2020

21-
src = requireFile {
21+
src = fetchItchIo {
2222
name = "DungeonDuelMonsters-linux-x64.zip";
2323
hash = "sha256-gq2nGwpaStqaVI1pL63xygxOI/z53o+zLwiKizG98Ks=";
24-
url = "https://mikaygo.itch.io/ddm";
24+
gameUrl = "https://mikaygo.itch.io/ddm";
25+
upload = "13371354";
2526
};
2627

2728
strictDeps = true;

pkgs/by-name/gh/ghmap/package.nix

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1 @@
1-
{
2-
lib,
3-
python3Packages,
4-
fetchFromGitHub,
5-
}:
6-
7-
python3Packages.buildPythonApplication (finalAttrs: {
8-
pname = "ghmap";
9-
version = "2.0.3";
10-
pyproject = true;
11-
12-
src = fetchFromGitHub {
13-
owner = "uhourri";
14-
repo = "ghmap";
15-
tag = "v${finalAttrs.version}";
16-
hash = "sha256-UF7Zxrm+thZeAKPiCaI5t4NbDzuUU3oosPsb0Cgv9t0=";
17-
};
18-
19-
build-system = with python3Packages; [
20-
setuptools
21-
];
22-
23-
dependencies = with python3Packages; [
24-
tqdm
25-
];
26-
27-
pythonImportsCheck = [
28-
"ghmap"
29-
];
30-
31-
nativeCheckInputs = with python3Packages; [
32-
pytestCheckHook
33-
];
34-
35-
meta = {
36-
description = "Python tool for mapping GitHub events to contributor activities";
37-
homepage = "https://github.com/uhourri/ghmap";
38-
license = lib.licenses.mit;
39-
maintainers = [ ];
40-
mainProgram = "ghmap";
41-
};
42-
})
1+
{ python3Packages }: python3Packages.toPythonApplication python3Packages.ghmap

pkgs/by-name/ko/koboredux/package.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let
3131
sha256 = "09h9r65z8bar2z89s09j6px0gdq355kjf38rmd85xb2aqwnm6xig";
3232
};
3333

34+
# TODO: Replace this with fetchItchIo
3435
assets_src = requireFile {
3536
name = "koboredux-${version}-Linux.tar.bz2";
3637
sha256 = "11bmicx9i11m4c3dp19jsql0zy4rjf5a28x4hd2wl8h3bf8cdgav";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
lib,
3+
python3Packages,
4+
fetchFromGitHub,
5+
}:
6+
7+
python3Packages.buildPythonApplication (finalAttrs: {
8+
pname = "rabbit-ng";
9+
version = "3.0.0";
10+
pyproject = true;
11+
12+
src = fetchFromGitHub {
13+
owner = "sgl-umons";
14+
repo = "RABBIT-ng";
15+
tag = finalAttrs.version;
16+
hash = "sha256-nd1LMJSJEUMMlKc4N7mQuEcBVJpGdQdZ6thmhk5BfCI=";
17+
};
18+
19+
build-system = with python3Packages; [
20+
hatchling
21+
];
22+
23+
dependencies = with python3Packages; [
24+
ghmap
25+
numpy
26+
onnxruntime
27+
pandas
28+
python-dotenv
29+
requests
30+
typer
31+
];
32+
33+
pythonImportsCheck = [
34+
"rabbit_ng"
35+
];
36+
37+
meta = {
38+
description = "RABBIT is a machine-learning based tool designed to identify bot accounts among GitHub contributors";
39+
homepage = "https://github.com/sgl-umons/RABBIT-ng";
40+
license = lib.licenses.asl20;
41+
maintainers = with lib.maintainers; [ drupol ];
42+
mainProgram = "rabbit-ng";
43+
};
44+
})

0 commit comments

Comments
 (0)