-
Notifications
You must be signed in to change notification settings - Fork 9
/
common.nix
71 lines (66 loc) · 2.29 KB
/
common.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{ pkgs, lib, metadata }:
let
inherit (lib) warn getExe;
in
self: super:
with self; {
fabricProfiles = metadata.fabric.profiles;
fabricLibraries = metadata.fabric.libraries;
fabricLoaders = metadata.fabric.loaders;
fetchJar = name:
let
inherit (fabricLibraries.${name}) repo hash;
splitted = splitString ":" name;
org = builtins.elemAt splitted 0;
art = builtins.elemAt splitted 1;
ver = builtins.elemAt splitted 2;
path =
"${replaceStrings [ "." ] [ "/" ] org}/${art}/${ver}/${art}-${ver}.jar";
url = "${repo}/${path}";
in pkgs.fetchurl {
inherit url;
${hash.type} = hash.value;
};
mkLauncher = baseModulePath: modules:
let
final = evalModules {
modules = modules
++ [ ({ _module.args.pkgs = pkgs; }) (import baseModulePath) ];
};
in final.config.launcher // {
withConfig = extraConfig:
mkLauncher baseModulePath (modules ++ toList extraConfig);
};
buildMc = { baseModulePath, buildFabricModules, buildVanillaModules
, versionInfo, assetsIndex, fabricProfile }:
let
fabric = mkLauncher baseModulePath
(buildFabricModules versionInfo assetsIndex fabricProfile);
in {
vanilla =
mkLauncher baseModulePath (buildVanillaModules versionInfo assetsIndex);
} // (optionalAttrs (fabricProfile != null) { inherit fabric; });
mkBuild = { baseModulePath, buildFabricModules, buildVanillaModules }:
gameVersion: assets:
let
versionInfo = metadata.versions.${assets.sha1};
assetsIndex = metadata.assets.${versionInfo.assetIndex.sha1};
fabricProfile = fabricProfiles.${gameVersion} or null;
in buildMc {
inherit baseModulePath buildFabricModules buildVanillaModules versionInfo
assetsIndex fabricProfile;
};
defaultJavaVersion = versionInfo:
let
javaMajorVersion = versionInfo.javaVersion.majorVersion or null;
fallback = warn ''
Java version is not specified by the Minecraft json file, or
the specified version of OpenJDK is not supported by the Nixpkgs.
Fallback to '${pkgs.openjdk}'.
'' pkgs.openjdk;
java = if javaMajorVersion == null
then fallback
else pkgs."openjdk${toString javaMajorVersion}" or fallback;
in
getExe java;
}