Skip to content

Commit

Permalink
Nix improvements (#41)
Browse files Browse the repository at this point in the history
* Override packwiz; Improve mrpack build

* Remove home

* Fix tag matcher

* Bring back home

* remove unusued
  • Loading branch information
pedorich-n authored Jun 11, 2024
1 parent adccc2c commit b7a88f4
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-mrpack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Generate mrpack
on:
push:
tags:
- "v*.*.*"
- "v[0-9]+.[0-9]+.[0-9]+*"

jobs:
generate-mrpack:
Expand Down
1 change: 1 addition & 0 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
devShells = {
default = pkgs.mkShell {
packages = with pkgs; [
nvfetcher
packwiz
poetry
];
Expand Down
15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
outputs = inputs@{ flake-parts, systems, packwiz2nix, self, ... }: flake-parts.lib.mkFlake { inherit inputs; } ({ moduleWithSystem, ... }: {
systems = import systems;

perSystem = { system, pkgs, config, ... }: {
perSystem = { system, pkgs, config, lib, ... }: {
_module.args = {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(import ./nix/overlay.nix)
];
};
};

packages =
let
packwiz2nixLib = inputs.packwiz2nix.lib.${system};
Expand All @@ -27,9 +36,9 @@
side = "server";
};

modrinth-pack = pkgs.callPackage ./nix/packwiz-modrinth.nix { } {
modrinth-pack = pkgs.callPackage ./nix/packwiz-modrinth.nix {
src = self;
hash = "sha256-TRGUHK6BlTKjVxbdkvvD4UvfFa+XULHmeCD7piUnMc4=";
hash = "sha256-ie0Igriqj77fmhcRyJtUxqJKAI+db1+dNF3QgyVi7P4=";
};

# Not used for anything right now
Expand Down
3 changes: 3 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_: prev: {
packwiz = import ./packwiz { pkgs = prev; };
}
48 changes: 19 additions & 29 deletions nix/packwiz-modrinth.nix
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
{ lib, stdenvNoCC, packwiz, jq, zip, unzip, moreutils }: { src, hash, ... } @ args:
{ src
, hash
, lib
, stdenvNoCC
, packwiz
}:
stdenvNoCC.mkDerivation (finalAttrs:
let
resultName = "${finalAttrs.passthru.manifest.name}-v${finalAttrs.passthru.manifest.version}.mrpack";
sanitizedName = lib.strings.sanitizeDerivationName finalAttrs.passthru.manifest.name;
version = finalAttrs.passthru.manifest.version;
resultName = "${sanitizedName}-v${version}.mrpack";
in
{
pname = "${finalAttrs.passthru.manifest.name}_Modrinth";
version = finalAttrs.passthru.manifest.version;
pname = "${sanitizedName}_Modrinth";
inherit version;
inherit src;

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = hash;

dontFixup = true;

buildInputs = [ packwiz jq unzip zip moreutils ];
buildInputs = [ packwiz ];

buildPhase = ''
# this line needed for Github Action
export HOME=$TMPDIR
packwiz modrinth export --output ./${resultName}
'';
runHook preBuild
# modrinth.index.json file is not sorted, so non-deterministic :(
# see https://github.com/packwiz/packwiz/issues/244
installPhase = ''
runHook preInstall
INDEX_FILE="modrinth.index.json"
ZIP_FOLDER="$TMPDIR/unpack"
JSON_FILE="$ZIP_FOLDER/$INDEX_FILE"
unzip -q "./${resultName}" "$INDEX_FILE" -d "$ZIP_FOLDER"
jq -S '.files|=sort_by(.path)' "$JSON_FILE" | sponge "$JSON_FILE"
touch -acmt 197001010000.00 "$JSON_FILE"
cd "$ZIP_FOLDER"
zip -uXq "../${resultName}" modrinth.index.json
# Github Ation fails with "failed to create cache directory: mkdir /homeless-shelter: permission denied" if this is not set
export HOME=$TMPDIR
mkdir -p $out
mv ../${resultName} $out/
packwiz modrinth export --output "$out/${resultName}"
runHook postInstall
runHook postBuild
'';

passthru = {
manifest = lib.importTOML "${src}/pack.toml";
};
} // args)
})
22 changes: 22 additions & 0 deletions nix/packwiz/_sources/generated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"packwiz": {
"cargoLocks": null,
"date": "2024-05-27",
"extract": null,
"name": "packwiz",
"passthru": null,
"pinned": false,
"src": {
"deepClone": false,
"fetchSubmodules": false,
"leaveDotGit": false,
"name": null,
"owner": "packwiz",
"repo": "packwiz",
"rev": "7b4be47578151c36e784306b36d251ec2590e50c",
"sha256": "sha256-XBp8Xv55R8rhhsQiWnOPH8c3fCpV/yq41ozJDcGdWfs=",
"type": "github"
},
"version": "7b4be47578151c36e784306b36d251ec2590e50c"
}
}
16 changes: 16 additions & 0 deletions nix/packwiz/_sources/generated.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
packwiz = {
pname = "packwiz";
version = "7b4be47578151c36e784306b36d251ec2590e50c";
src = fetchFromGitHub {
owner = "packwiz";
repo = "packwiz";
rev = "7b4be47578151c36e784306b36d251ec2590e50c";
fetchSubmodules = false;
sha256 = "sha256-XBp8Xv55R8rhhsQiWnOPH8c3fCpV/yq41ozJDcGdWfs=";
};
date = "2024-05-27";
};
}
8 changes: 8 additions & 0 deletions nix/packwiz/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs, ... }:
let
sources = pkgs.callPackage ./_sources/generated.nix { };
in
pkgs.packwiz.overrideAttrs (_: _: {
version = "unstable-${sources.packwiz.date}";
inherit (sources.packwiz) src;
})
3 changes: 3 additions & 0 deletions nix/packwiz/nvfetcher.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[packwiz]
src.git = "https://github.com/packwiz/packwiz.git"
fetch.github = "packwiz/packwiz"

0 comments on commit b7a88f4

Please sign in to comment.