Created
January 7, 2024 20:51
-
-
Save chuangzhu/61d616968cabfe584f8067022ad10330 to your computer and use it in GitHub Desktop.
A example for packaging Minecraft mods from Modrinth and Curseforge in Nix, with updaters, which I use personally with https://github.com/Ninlives/minecraft.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, fetchurl, writeShellScript, curl, jq, common-updater-scripts }: | |
let | |
fetchModrinth = { meta, passthru ? {}, ... } @ args: fetchurl args // { | |
meta = meta // { | |
position = let p = builtins.unsafeGetAttrPos "url" args; in "${p.file}:${toString p.line}"; | |
}; | |
passthru = passthru // { | |
updateScript = writeShellScript "update" '' | |
set -xeu -o pipefail | |
version=$(${curl}/bin/curl -s https://api.modrinth.com/v2/project/${meta.slug}/version \ | |
| ${jq}/bin/jq '[.[] | |
| select(.files | length > 0) | |
| select(.loaders | any(. == "${meta.loader}")) | |
| select(.game_versions | any(. == "${meta.gameVersion}")) | |
][0]') | |
url=$(${jq}/bin/jq -e -r '.files[0].url' <<< "$version") | |
sha512=$(${jq}/bin/jq -e -r '.files[0].hashes.sha512' <<< "$version") | |
${common-updater-scripts}/bin/update-source-version "$UPDATE_NIX_ATTR_PATH" "$url" "$sha512" --version-key=url --source-key=out | |
''; | |
}; | |
}; | |
fetchCurseforge = { meta, passthru ? {}, url, ... } @ args: let | |
match = builtins.match "https://www.curseforge.com/api/v1/mods/([0-9]+)/files/([0-9]+)/download" url; | |
addonId = builtins.elemAt match 0; | |
fileId = builtins.elemAt match 1; | |
in fetchurl (args // { | |
name = args.name or "${addonId}-${fileId}.jar"; | |
}) // { | |
meta = meta // { | |
position = let p = builtins.unsafeGetAttrPos "url" args; in "${p.file}:${toString p.line}"; | |
}; | |
passthru = passthru // { | |
updateScript = writeShellScript "update" '' | |
set -xeu -o pipefail | |
fileId=$(${curl}/bin/curl -s \ | |
'https://www.curseforge.com/api/v1/mods/${toString addonId}/files?pageIndex=0&pageSize=20&sort=dateCreated&sortDescending=true&gameVersionId=${toString meta.gameVersionId}&gameFlavorId=${toString meta.gameFlavorId}&removeAlphas=true' \ | |
| ${jq}/bin/jq -e -r '.data[0].id') | |
url="https://www.curseforge.com/api/v1/mods/${addonId}/files/$fileId/download" | |
${common-updater-scripts}/bin/update-source-version "$UPDATE_NIX_ATTR_PATH" "$url" --version-key=url --source-key=out | |
''; | |
}; | |
}; | |
in | |
{ | |
minecraft-1_18_2-fabric-fabric-api = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/P7dR8mSH/versions/qk28POfr/fabric-api-0.77.0%2B1.18.2.jar"; | |
sha512 = "adb62b0d73e83cf9302a59a55ffe7ca2cf6f4ebb34312ec09e0f56b99ebc173e02dd4f0b8ec059d7262a14857dc1911645b090e460f20fd8e2d48aa5f2fdbefa"; | |
meta = { | |
slug = "fabric-api"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
license = lib.licenses.asl20; | |
}; | |
}; | |
minecraft-1_18_2-fabric-malilib = fetchCurseforge { | |
# url = "curseforge://install?addonId=303119&fileId=4147598"; | |
url = "https://www.curseforge.com/api/v1/mods/303119/files/3692220/download"; | |
hash = "sha256-glx8HACyCMOZnD3FcGr78+HWuBVsgvC8WliJeduv0+o="; | |
# Open https://www.curseforge.com/minecraft/mc-mods/${slug}/files, then DevTools > Network | |
# Filter by ${gameVersion} and ${loader}, and you'll find a new request containing these info | |
meta = { | |
gameFlavorId = 4; # Fabric | |
gameVersionId = 9008; # 1.18.2 | |
license = lib.licenses.lgpl3; | |
}; | |
}; | |
minecraft-1_18_2-fabric-architectury-api = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/lhGA9TYQ/versions/j5zDzQqi/architectury-4.11.93-fabric.jar"; | |
sha512 = "41f8dea79e8a0f0e8a49c3baea0750a06a09d1d76285dfbd9b5b0dd7c8b02d615bf431bd822bc9fd6d6fafab7207c469e6961d35c65643eb0460df381c679f87"; | |
meta = { | |
slug = "architectury-api"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-sodium = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/AANobbMI/versions/mc1.18.2-0.4.1/sodium-fabric-mc1.18.2-0.4.1%2Bbuild.15.jar"; | |
sha512 = "86eb4db8fdb9f0bb06274c4f150b55273b5b770ffc89e0ba68011152a231b79ebe0b1adda0dd194f92cdcb386f7a60863d9fee5d15c1c3547ffa22a19083a1ee"; | |
meta = { | |
slug = "sodium"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-lithium = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/gvQqBUqZ/versions/ALnv7Npy/lithium-fabric-mc1.18.2-0.10.3.jar"; | |
sha512 = "46d4cdaf627a20c61fbbbc055d6fbfc422b851d94288b6dd2296fc958c6b32d4d6955bc678e7b9ea9ae69f4a4a54e7b822c164fee849c9b5c7cde0c1c1595413"; | |
meta = { | |
slug = "lithium"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-phosphor = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/hEOCdOgW/versions/mc1.18.x-0.8.1/phosphor-fabric-mc1.18.x-0.8.1.jar"; | |
sha512 = "6a06f397f5f054f12334b81251dbdbd9c82c7e4e41810d6708a9d40966da113560c6f23e95f6f5ed52cfe1e843f7f71910a84b2bb476354456ff11be668a4c1d"; | |
meta = { | |
slug = "phosphor"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-ebe = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/OVuFYfre/versions/0.7.1%2B1.18.2/enhancedblockentities-0.7.1%2B1.18.2.jar"; | |
sha512 = "183f519a161e7ea1e2259553f8ec7939cf0e2e3ef1e8b191985e84d2e6ecd65eb4ced17a85f9f6ba66b89eb3949838522fa4e1b958bbaf5846b7f8fc46c1759e"; | |
meta = { | |
slug = "ebe"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-indium = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/Orvt0mRa/versions/1.0.7%2Bmc1.18.2/indium-1.0.7%2Bmc1.18.2.jar"; | |
sha512 = "cdd32ac79e7cb423af95dbd618c383a9e240e84f53eeb02029f679142e4b980e39c7db8190a2cdb542c23067d56c6b7d29bc21204709028ee5538a659f7cf95f"; | |
meta = { | |
slug = "indium"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-continuity = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/1IjD5062/versions/YEKdScFW/continuity-2.0.2%2B1.18.2.jar"; | |
sha512 = "6ffa8af218faf2936869beb2cb0ec7baa6661b9d97c1c9dda55adc49a3d919fc6e9e143c1f61ebc94d505b4fffcce9089b1d5c4e55e62d2b2caed0a803fb591a"; | |
meta = { | |
slug = "continuity"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-appleskin = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/EsAfCjCV/versions/3wbLqeIN/appleskin-fabric-mc1.18.2-2.5.1.jar"; | |
sha512 = "8e62087f708716ab4d2684c406063bda2c10d6c520bed42bbe6a07f62b0bd3d6fef4da8d8f900fad2edc145bbcd0031e2eb6c2e2c0f72ee19a8535069df70c95"; | |
meta = { | |
slug = "appleskin"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-wagyourminimap = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/v9tYpGRa/versions/jHJu5Q0L/wagyourminimap-1.0.11%2B1.18.2-fabric.jar"; | |
sha512 = "e440ed3abd562bef9d4629045732764d9c1030967babf2a8d4b58bf01f595fb4f8b43543d869cc36b27823bb0cb4a38ad3180db4113bb1a7dd2d25242445f2b6"; | |
meta = { | |
slug = "wagyourminimap"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-fabric-i-know-what-im-doing = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/S5ivha5X/versions/MjxKpliA/IKnowWhatImDoing-4.1.1-fabric.jar"; | |
sha512 = "0eb133ae604cf734eeb7651f9df0d6cc29834c7c1e2035fa19b11fb3857bfe04f9ba055f6ea7d6f603e229214c918f72272585365d4c2b832a094635c0011796"; | |
meta = { | |
slug = "i-know-what-im-doing"; | |
loader = "fabric"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18_2-minecraft-default-dark-mode = fetchModrinth { | |
url = "https://cdn.modrinth.com/data/6SLU7tS5/versions/n4pD2iAz/Default-Dark-Mode-1.18-2023.7.0.zip"; | |
sha512 = "a642df8374ec55fb7c9af610bd16f533a1d9bbeb841b721e3a663cfa4a4063b94299ab42d3ee50111a7edde2bd2f2a247f240d49d1d9d7be217175c9382b1843"; | |
meta = { | |
slug = "default-dark-mode"; | |
loader = "minecraft"; | |
gameVersion = "1.18.2"; | |
}; | |
}; | |
minecraft-1_18-fabric-cocoainput = fetchCurseforge { | |
url = "https://www.curseforge.com/api/v1/mods/259700/files/3554724/download"; | |
hash = "sha256-5Fhs5ta+8G635s0HpX6gooYOJeWmZ76IedPSL4axUiI="; | |
meta = { | |
gameFlavorId = 4; | |
gameVersionId = 8830; # 1.18 | |
}; | |
}; | |
minecraft-1_18_2-fabric-tweakeroo = fetchCurseforge { | |
url = "https://www.curseforge.com/api/v1/mods/297344/files/3783910/download"; | |
hash = "sha256-9GA1k+hKNKKEyWN9/O0dIKMWNjdoTo4navbTkpMN7LY="; | |
meta = { | |
gameFlavorId = 4; | |
gameVersionId = 9008; | |
}; | |
}; | |
minecraft-1_18_2-fabric-litematica = fetchCurseforge { | |
url = "https://www.curseforge.com/api/v1/mods/308892/files/4447174/download"; | |
hash = "sha256-cLsOxEupwV/u2h/WP3GsI7n3vw5OaCv1PF2cT1azUTA="; | |
meta = { | |
gameFlavorId = 4; | |
gameVersionId = 9008; | |
}; | |
}; | |
minecraft-1_18_2-fabric-minihud = fetchCurseforge { | |
url = "https://www.curseforge.com/api/v1/mods/244260/files/3909308/download"; | |
hash = "sha256-eTbmi5w+Kt6kwt/HSV2Q5O3GZhSOpHN14JbDFbrFvWw="; | |
meta = { | |
gameFlavorId = 4; | |
gameVersionId = 9008; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment