Add packwiz-wrapper package

this searches up the directory tree for a pack.toml before executing
packwiz
This commit is contained in:
NullBite 2024-03-23 16:13:03 -04:00
parent fa855294e7
commit 3814d6175f
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A
4 changed files with 61 additions and 1 deletions

View File

@ -7,7 +7,7 @@
devShells = eachSystem (system: let pkgs = import nixpkgs { inherit system; };
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [ packwiz nix-update ];
buildInputs = with pkgs; [ self.packages.${system}.packwiz-wrapper nix-update ];
};
});
packages = eachSystem (system: let pkgs = import nixpkgs { inherit system; };

View File

@ -3,4 +3,5 @@ let
shaders = callPackage ./shaders.nix {};
in {
inherit (shaders) bliss-dh complementary-reimagined-dh rethinking-voxels-dh;
packwiz-wrapper = callPackage ./packwiz-wrapper { };
}

View File

@ -0,0 +1,25 @@
{ lib,
stdenvNoCC,
python3,
makeWrapper,
packwiz }:
let
wrappedPath = lib.makeBinPath [ packwiz ];
in stdenvNoCC.mkDerivation {
pname = "packwiz-wrapper";
version = "0.0.0";
buildInputs = [
python3
makeWrapper
packwiz
];
src = ./.;
installPhase = ''
install -Dm555 packwiz-wrapper.py $out/libexec/packwiz-wrapper.py
mkdir -p $out/bin
makeShellWrapper $out/libexec/packwiz-wrapper.py $out/bin/packwiz \
--prefix PATH : "${wrappedPath}"
'';
}

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import sys, os
from pathlib import Path
# Returns a parent path with pack.toml, or None if it can't be found
def search_recursive(dir: str | os.PathLike) -> Path | None:
dir = Path(dir)
pack = dir / "pack.toml"
if pack.is_file():
return dir
# If we've made it to / without finding it, return None
if dir.samefile("/"):
return None
# Otherwise, recurse
return search_recursive(dir / "..")
def search(dir: str | os.PathLike) -> Path:
new_dir = search_recursive(dir)
if new_dir is not None:
return new_dir
else:
return Path(dir)
def main():
args = ["packwiz"] + sys.argv[1:]
os.chdir(search("."))
os.execvp("packwiz", args)
if __name__ == "__main__":
main()