Add support for building minecraft modpacks
This commit is contained in:
parent
b474f7e97c
commit
a9e3610744
6 changed files with 121 additions and 11 deletions
pkgs
23
pkgs/build-support/fetchFromCurseForge.nix
Normal file
23
pkgs/build-support/fetchFromCurseForge.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ lib, fetchurl }:
|
||||
|
||||
with builtins;
|
||||
|
||||
{ project, id, filename, ... }@args:
|
||||
|
||||
let
|
||||
# I think this is supposed to be some weak automation
|
||||
# protection. This split "id" is simply part of the download URL.
|
||||
#
|
||||
# Note that if it's zero-prefixed we need to remove the zeroes. It's
|
||||
# really an odd one...
|
||||
a = head (match "0*([[:digit:]]+)" (substring 0 4 id));
|
||||
b = head (match "0*([[:digit:]]+)" (substring 4 7 id));
|
||||
|
||||
url = "https://media.forgecdn.net/files/${a}/${b}/${filename}";
|
||||
otherArgs = removeAttrs args [ "project" "id" "filename" ];
|
||||
|
||||
in fetchurl (otherArgs // {
|
||||
inherit url;
|
||||
# Rename files to avoid names incompatible with the nix store
|
||||
name = "${project}.jar";
|
||||
})
|
|
@ -1,6 +1,12 @@
|
|||
{ pkgs, ... }:
|
||||
{ pkgs, local-lib, ... }:
|
||||
|
||||
{
|
||||
let
|
||||
inherit (pkgs.lib) callPackageWith;
|
||||
callPackage = callPackageWith (pkgs // { inherit local-lib; });
|
||||
in {
|
||||
# Forge
|
||||
forge-server = pkgs.callPackage ./minecraft/forge-server.nix { };
|
||||
forge-server = callPackage ./minecraft/forge-server.nix { };
|
||||
|
||||
# Build support
|
||||
fetchFromCurseForge = callPackage ./build-support/fetchFromCurseForge.nix { };
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{ lib, stdenv, fetchurl, jre_headless, runtimeShell }:
|
||||
{ lib, stdenv, fetchurl, busybox, coreutils, jre_headless, runtimeShell
|
||||
, mods ? null, config ? null, defaultconfigs ? null }:
|
||||
|
||||
let
|
||||
name = "forge-server";
|
||||
|
@ -45,6 +46,35 @@ in stdenv.mkDerivation rec {
|
|||
#!${runtimeShell}
|
||||
set -eu
|
||||
|
||||
# Delete any previous mods directory so that it can be updated
|
||||
${busybox}/bin/rm -fr mods
|
||||
|
||||
${lib.optionalString (mods != null) ''
|
||||
# Copy the specified mods into the directory. Note that, sadly,
|
||||
# forge doesn't support symlinks here.
|
||||
${busybox}/bin/mkdir -p mods
|
||||
${busybox}/bin/cp -r '${mods}/mods/'*.jar mods
|
||||
''}
|
||||
|
||||
# Delete any previous config directories so that they can be updated
|
||||
${busybox}/bin/rm -fr config defaultconfigs
|
||||
|
||||
${lib.optionalString (config != null) ''
|
||||
# Copy the specified configs into the directory. Forge (and
|
||||
# mods) will try to write here, so we cannot symlink.
|
||||
${busybox}/bin/mkdir -p config
|
||||
${busybox}/bin/cp -r '${config}'/* config
|
||||
${busybox}/bin/chmod -R u+w config
|
||||
''}
|
||||
|
||||
${lib.optionalString (defaultconfigs != null) ''
|
||||
# Copy the specified configs into the directory. Forge (and
|
||||
# mods) will try to write here, so we cannot symlink.
|
||||
${busybox}/bin/mkdir -p defaultconfigs
|
||||
${busybox}/bin/cp -r '${defaultconfigs}'/* defaultconfigs
|
||||
${busybox}/bin/chmod -R u+w defaultconfigs
|
||||
''}
|
||||
|
||||
exec ${jre_headless}/bin/java \$@ -jar $out'/lib/forge/forge-${version}.jar' nogui
|
||||
EOF
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue