Add packwiz-wrapper package
this searches up the directory tree for a pack.toml before executing packwiz
This commit is contained in:
parent
fa855294e7
commit
3814d6175f
@ -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; };
|
||||
|
@ -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 { };
|
||||
}
|
||||
|
25
nix/packages/packwiz-wrapper/default.nix
Normal file
25
nix/packages/packwiz-wrapper/default.nix
Normal 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}"
|
||||
'';
|
||||
}
|
34
nix/packages/packwiz-wrapper/packwiz-wrapper.py
Executable file
34
nix/packages/packwiz-wrapper/packwiz-wrapper.py
Executable 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()
|
Loading…
x
Reference in New Issue
Block a user