Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit b7a88f4

Browse files
authored
Nix improvements (#41)
* Override packwiz; Improve mrpack build * Remove home * Fix tag matcher * Bring back home * remove unusued
1 parent adccc2c commit b7a88f4

File tree

9 files changed

+85
-33
lines changed

9 files changed

+85
-33
lines changed

.github/workflows/generate-mrpack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Generate mrpack
33
on:
44
push:
55
tags:
6-
- "v*.*.*"
6+
- "v[0-9]+.[0-9]+.[0-9]+*"
77

88
jobs:
99
generate-mrpack:

dev/flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
devShells = {
4040
default = pkgs.mkShell {
4141
packages = with pkgs; [
42+
nvfetcher
4243
packwiz
4344
poetry
4445
];

flake.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
outputs = inputs@{ flake-parts, systems, packwiz2nix, self, ... }: flake-parts.lib.mkFlake { inherit inputs; } ({ moduleWithSystem, ... }: {
1616
systems = import systems;
1717

18-
perSystem = { system, pkgs, config, ... }: {
18+
perSystem = { system, pkgs, config, lib, ... }: {
19+
_module.args = {
20+
pkgs = import inputs.nixpkgs {
21+
inherit system;
22+
overlays = [
23+
(import ./nix/overlay.nix)
24+
];
25+
};
26+
};
27+
1928
packages =
2029
let
2130
packwiz2nixLib = inputs.packwiz2nix.lib.${system};
@@ -27,9 +36,9 @@
2736
side = "server";
2837
};
2938

30-
modrinth-pack = pkgs.callPackage ./nix/packwiz-modrinth.nix { } {
39+
modrinth-pack = pkgs.callPackage ./nix/packwiz-modrinth.nix {
3140
src = self;
32-
hash = "sha256-TRGUHK6BlTKjVxbdkvvD4UvfFa+XULHmeCD7piUnMc4=";
41+
hash = "sha256-ie0Igriqj77fmhcRyJtUxqJKAI+db1+dNF3QgyVi7P4=";
3342
};
3443

3544
# Not used for anything right now

nix/overlay.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_: prev: {
2+
packwiz = import ./packwiz { pkgs = prev; };
3+
}

nix/packwiz-modrinth.nix

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,41 @@
1-
{ lib, stdenvNoCC, packwiz, jq, zip, unzip, moreutils }: { src, hash, ... } @ args:
1+
{ src
2+
, hash
3+
, lib
4+
, stdenvNoCC
5+
, packwiz
6+
}:
27
stdenvNoCC.mkDerivation (finalAttrs:
38
let
4-
resultName = "${finalAttrs.passthru.manifest.name}-v${finalAttrs.passthru.manifest.version}.mrpack";
9+
sanitizedName = lib.strings.sanitizeDerivationName finalAttrs.passthru.manifest.name;
10+
version = finalAttrs.passthru.manifest.version;
11+
resultName = "${sanitizedName}-v${version}.mrpack";
512
in
613
{
7-
pname = "${finalAttrs.passthru.manifest.name}_Modrinth";
8-
version = finalAttrs.passthru.manifest.version;
14+
pname = "${sanitizedName}_Modrinth";
15+
inherit version;
16+
inherit src;
917

1018
outputHashMode = "recursive";
1119
outputHashAlgo = "sha256";
1220
outputHash = hash;
1321

1422
dontFixup = true;
1523

16-
buildInputs = [ packwiz jq unzip zip moreutils ];
24+
buildInputs = [ packwiz ];
1725

1826
buildPhase = ''
19-
# this line needed for Github Action
20-
export HOME=$TMPDIR
21-
22-
packwiz modrinth export --output ./${resultName}
23-
'';
27+
runHook preBuild
2428
25-
# modrinth.index.json file is not sorted, so non-deterministic :(
26-
# see https://github.com/packwiz/packwiz/issues/244
27-
installPhase = ''
28-
runHook preInstall
29-
30-
INDEX_FILE="modrinth.index.json"
31-
ZIP_FOLDER="$TMPDIR/unpack"
32-
JSON_FILE="$ZIP_FOLDER/$INDEX_FILE"
33-
34-
unzip -q "./${resultName}" "$INDEX_FILE" -d "$ZIP_FOLDER"
35-
36-
jq -S '.files|=sort_by(.path)' "$JSON_FILE" | sponge "$JSON_FILE"
37-
touch -acmt 197001010000.00 "$JSON_FILE"
38-
39-
cd "$ZIP_FOLDER"
40-
zip -uXq "../${resultName}" modrinth.index.json
29+
# Github Ation fails with "failed to create cache directory: mkdir /homeless-shelter: permission denied" if this is not set
30+
export HOME=$TMPDIR
4131
4232
mkdir -p $out
43-
mv ../${resultName} $out/
33+
packwiz modrinth export --output "$out/${resultName}"
4434
45-
runHook postInstall
35+
runHook postBuild
4636
'';
4737

4838
passthru = {
4939
manifest = lib.importTOML "${src}/pack.toml";
5040
};
51-
} // args)
41+
})

nix/packwiz/_sources/generated.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"packwiz": {
3+
"cargoLocks": null,
4+
"date": "2024-05-27",
5+
"extract": null,
6+
"name": "packwiz",
7+
"passthru": null,
8+
"pinned": false,
9+
"src": {
10+
"deepClone": false,
11+
"fetchSubmodules": false,
12+
"leaveDotGit": false,
13+
"name": null,
14+
"owner": "packwiz",
15+
"repo": "packwiz",
16+
"rev": "7b4be47578151c36e784306b36d251ec2590e50c",
17+
"sha256": "sha256-XBp8Xv55R8rhhsQiWnOPH8c3fCpV/yq41ozJDcGdWfs=",
18+
"type": "github"
19+
},
20+
"version": "7b4be47578151c36e784306b36d251ec2590e50c"
21+
}
22+
}

nix/packwiz/_sources/generated.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file was generated by nvfetcher, please do not modify it manually.
2+
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
3+
{
4+
packwiz = {
5+
pname = "packwiz";
6+
version = "7b4be47578151c36e784306b36d251ec2590e50c";
7+
src = fetchFromGitHub {
8+
owner = "packwiz";
9+
repo = "packwiz";
10+
rev = "7b4be47578151c36e784306b36d251ec2590e50c";
11+
fetchSubmodules = false;
12+
sha256 = "sha256-XBp8Xv55R8rhhsQiWnOPH8c3fCpV/yq41ozJDcGdWfs=";
13+
};
14+
date = "2024-05-27";
15+
};
16+
}

nix/packwiz/default.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ pkgs, ... }:
2+
let
3+
sources = pkgs.callPackage ./_sources/generated.nix { };
4+
in
5+
pkgs.packwiz.overrideAttrs (_: _: {
6+
version = "unstable-${sources.packwiz.date}";
7+
inherit (sources.packwiz) src;
8+
})

nix/packwiz/nvfetcher.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[packwiz]
2+
src.git = "https://github.com/packwiz/packwiz.git"
3+
fetch.github = "packwiz/packwiz"

0 commit comments

Comments
 (0)