From 1c7b6c474494809cdc36a70d49b4d6f8f28617fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Sat, 11 Jun 2022 20:08:11 +0100 Subject: [PATCH] add papermc --- .github/workflows/update-flake.yaml | 20 +++++++++++-------- flake.nix | 25 +++++++++++++---------- minecraft/paper.json | 6 ++++++ minecraft/paper.nix | 31 +++++++++++++++++++++++++++++ minecraft/update.sh | 4 ++++ 5 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 minecraft/paper.json create mode 100644 minecraft/paper.nix create mode 100755 minecraft/update.sh diff --git a/.github/workflows/update-flake.yaml b/.github/workflows/update-flake.yaml index 1a5c165..42b9dee 100644 --- a/.github/workflows/update-flake.yaml +++ b/.github/workflows/update-flake.yaml @@ -2,7 +2,7 @@ name: update-flake-lock on: workflow_dispatch: # allows manual triggering schedule: - - cron: "31 3 * * 3" + - cron: "16 20 * * *" jobs: lockfile: runs-on: ubuntu-latest @@ -14,11 +14,15 @@ jobs: with: extra_nix_config: | access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - - name: Update flake.lock - uses: DeterminateSystems/update-flake-lock@v9 + - name: Update flake.lockfile + run: nix flake update + - name: Run update script for minecraft + run: ./minecraft/update.sh + - name: Commit and push + uses: technote-space/create-pr-action@v2 with: - pr-title: "Update flake.lock" # Title of PR to be created - pr-labels: | # Labels to be set on the PR - dependencies - automated - token: ${{ secrets.GITHUB_TOKEN }} + COMMIT_MESSAGE: "Update everything" + COMMIT_NAME: "GitHub Actions[bot]" + COMMIT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com" + PR_BRANCH_NAME: 'chore-update-${PR_ID}' + PR_TITLE: 'chore: update everything' diff --git a/flake.nix b/flake.nix index 2d8d3bb..85909b1 100644 --- a/flake.nix +++ b/flake.nix @@ -12,16 +12,18 @@ miifox-net.flake = false; }; - outputs = { - self, - nixpkgs, - flake-utils, - ... - } @ inputs: - flake-utils.lib.eachSystem ["aarch64-linux" "x86_64-linux"] ( - system: let - pkgs = import nixpkgs {inherit system;}; - in rec { + outputs = + { self + , nixpkgs + , flake-utils + , ... + } @ inputs: + flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + rec { formatter = pkgs.alejandra; devShells.default = pkgs.mkShell { @@ -30,10 +32,11 @@ ]; }; - packages = pkgs.lib.lists.foldl (a: b: a // b) {} (map (f: import f {inherit pkgs inputs;}) [ + packages = pkgs.lib.lists.foldl (a: b: a // b) { } (map (f: import f { inherit pkgs inputs; }) [ ./scripts/clean-s3-cache.nix ./web/old-homepage.nix ./web/miifox-net.nix + ./minecraft/paper.nix ]); hydraJobs = { diff --git a/minecraft/paper.json b/minecraft/paper.json new file mode 100644 index 0000000..b17b72e --- /dev/null +++ b/minecraft/paper.json @@ -0,0 +1,6 @@ +{ + "version": "1.18.2", + "build": 379, + "name": "paper-1.18.2-379.jar", + "sha256": "672207836693f08ff147539a7c6ae317b5ac35d6dd6539cbd05bed21dcfcbe1f" +} diff --git a/minecraft/paper.nix b/minecraft/paper.nix new file mode 100644 index 0000000..291afed --- /dev/null +++ b/minecraft/paper.nix @@ -0,0 +1,31 @@ +{ pkgs, ... }: +let + version-info = builtins.fromJSON (builtins.readFile ./paper.json); + pname = "paper"; + mcVersion = version-info.version; + buildNum = toString version-info.build; +in +rec { + paper-jar = pkgs.fetchurl { + url = "https://papermc.io/api/v2/projects/paper/versions/${mcVersion}/builds/${buildNum}/downloads/${version-info.name}"; + inherit (version-info) sha256; + }; + papermc = pkgs.stdenvNoCC.mkDerivation { + pname = "papermc"; + version = "${mcVersion}-${buildNum}"; + + dontUnpack = true; + dontConfigure = true; + + buildPhase = '' + cat > minecraft-server << EOF + #!${pkgs.bash}/bin/sh + exec ${pkgs.openjdk17_headless}/bin/java \$@ -jar $out/share/papermc/papermc.jar nogui + ''; + + installPhase = '' + install -Dm444 ${paper-jar} $out/share/papermc/papermc.jar + install -Dm555 -t $out/bin minecraft-server + ''; + }; +} diff --git a/minecraft/update.sh b/minecraft/update.sh new file mode 100755 index 0000000..2413c9b --- /dev/null +++ b/minecraft/update.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p curl jq + +curl -L https://papermc.io/api/v2/projects/paper/versions/1.18.2/builds | jq '{"version":.version, "build":.builds[-1].build, "name":.builds[-1].downloads.application.name, "sha256":.builds[-1].downloads.application.sha256}' > paper.json