{ description = "Benzin - Wii BRlyt/BRlan/TPL file tools"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs }: let systems = [ "x86_64-linux" "aarch64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs systems; mkPkg = { pkgs, pname, version, srcDir, buildInputs, makefile, description, extraPatchPhase ? "", }: pkgs.stdenv.mkDerivation { inherit pname version buildInputs description ; src = if srcDir == "." then self else "${self}/${srcDir}"; patchPhase = '' substituteInPlace ${makefile} --replace-fail 'gcc' '$(CC)' ${extraPatchPhase} ''; installPhase = '' mkdir -p $out/bin cp ${pname} $out/bin/ ''; meta = { inherit description; homepage = "https://github.com/trap15/benzin"; platforms = pkgs.lib.platforms.linux; maintainers = [ ]; }; }; in { packages = forAllSystems ( system: let pkgs = import nixpkgs { inherit system; }; in { benzin = mkPkg { inherit pkgs; pname = "benzin"; version = "2.1.11-beta"; srcDir = "."; buildInputs = [ pkgs.minixml ]; makefile = "Makefile"; description = "Tool for parsing and creating BRlyt/BRlan files (Wii UI format)"; extraPatchPhase = '' # xml.c uses mxml 2.x struct internals; rewrite to use accessor functions. # Remove the redundant assignment on line 35, then fix the for loop. sed -i '/^[[:space:]]*current = node->child;$/{ /for/d d }' xml.c substituteInPlace xml.c \ --replace-fail 'for (current = node->child; current && ptr < end; current = current->next)' \ 'for (current = mxmlGetFirstChild(node); current && ptr < end; current = mxmlGetNextSibling(current))' \ --replace-fail 'current->type == MXML_TEXT' 'mxmlGetType(current) == MXML_TEXT' \ --replace-fail 'current->type == MXML_OPAQUE' 'mxmlGetType(current) == MXML_OPAQUE' \ --replace-fail 'current->type == MXML_INTEGER' 'mxmlGetType(current) == MXML_INTEGER' \ --replace-fail 'current->type == MXML_REAL' 'mxmlGetType(current) == MXML_REAL' \ --replace-fail 'current->value.opaque' 'mxmlGetOpaque(current)' \ --replace-fail 'current->value.integer' 'mxmlGetInteger(current)' \ --replace-fail 'current->value.real' 'mxmlGetReal(current)' \ --replace-fail 'node->value.element.name' 'mxmlGetElement(node)' \ --replace-fail 'temp = temp->parent' 'temp = mxmlGetParent(temp)' \ --replace-fail 'node->prev' 'mxmlGetPrevSibling(node)' \ --replace-fail 'node->parent' 'mxmlGetParent(node)' # Handle text node: insert local vars before the whitespace check substituteInPlace xml.c \ --replace-fail 'if (current->value.text.whitespace)' \ 'int _mxml_ws; const char *_mxml_str = mxmlGetText(current, &_mxml_ws); if (_mxml_ws)' substituteInPlace xml.c \ --replace-fail 'current->value.text.string' '_mxml_str' ''; }; zetsubou = mkPkg { inherit pkgs; pname = "zetsubou"; version = "0.1"; srcDir = "zetsubou"; buildInputs = [ pkgs.gd ]; makefile = "Makefile"; description = "TPL (Texture Palette List) converter — TPL to/from BMP/PNG"; }; gentpl = mkPkg { inherit pkgs; pname = "gentpl"; version = "0.1"; srcDir = "gentpl"; buildInputs = [ pkgs.gd ]; makefile = "Makefile"; description = "Simple PNG to TPL converter"; }; default = self.packages.${system}.benzin; } ); devShells = forAllSystems ( system: let pkgs = import nixpkgs { inherit system; }; in { default = pkgs.mkShell { buildInputs = with pkgs; [ minixml gd ]; }; } ); }; }