Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
# Agent worktrees and local tool state.
/.claude/
/result
/result-*
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,36 @@ This builds the command line tool from [crates.io](https://crates.io/crates/hatc

With [cargo-binstall](https://github.com/cargo-bins/cargo-binstall), `cargo binstall hatchzip` downloads the release build for your system instead of compiling it, with RAR support, on Linux, macOS and Windows (x64; Arm on Linux and macOS).

### With Nix

Run HatchZip directly:

```sh
nix run github:xevrion/hatchzip
```

Or install it into your profile:

```sh
nix profile install github:xevrion/hatchzip
```

The default package does not include RAR support. To enable it use the
`hatchzip-rar` variant, which requires allowing unfree packages in Nix.

Run it with:

```sh
NIXPKGS_ALLOW_UNFREE=1 nix run --impure github:xevrion/hatchzip#hatchzip-rar
```

You can also install it into your profile:

```sh
NIXPKGS_ALLOW_UNFREE=1 nix profile install --impure github:xevrion/hatchzip#hatchzip-rar
```


### From source

With [Rust](https://rustup.rs) (the version is pinned in `rust-toolchain.toml` and installed automatically):
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
description = "HatchZip - archive manager";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

outputs = {
self,
nixpkgs,
}: let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

forAllSystems = nixpkgs.lib.genAttrs systems;
in {
packages = forAllSystems (
system: let
pkgs = nixpkgs.legacyPackages.${system};

hatchzip = pkgs.callPackage ./packaging/nix/package.nix {
src = self;
};

hatchzip-rar = pkgs.callPackage ./packaging/nix/package.nix {
src = self;
enableRar = true;
};
in {
default = hatchzip;
inherit hatchzip hatchzip-rar;
}
);

apps = forAllSystems (
system: let
packages = self.packages.${system};
hatchzip = {
type = "app";
program = "${packages.hatchzip}/bin/hatchzip";
};
in {
default = hatchzip;
inherit hatchzip;

hatchzip-rar = {
type = "app";
program = "${packages.hatchzip-rar}/bin/hatchzip";
};
}
);
};
}
52 changes: 32 additions & 20 deletions packaging/nix/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
# nixpkgs
# Nix packaging

`package.nix` is the package for a nixpkgs submission, at
`pkgs/by-name/ha/hatchzip/package.nix`. It builds the command line tool from
the release tag without the `rar` feature, so the build is MIT/Apache-2.0
throughout, adds the `hz` short name, completions and the man page, and runs
the test suite as a debug build, since the tests lower limits through
environment variables that only debug builds read (`test_knob` in
`crates/core/src/engine.rs`).
HatchZip provides a Nix flake for building and running the CLI. The flake is the
canonical packaging definition and the path used to test Nix builds.

Built and tested on x86_64-linux at v0.1.8 (2026-10-30): every test binary
passed, and `hatchzip --version`, `hz --version` and a real extraction ran
from the output.
`package.nix` is kept as a reusable derivation that takes `src` and `version` as
arguments. It contains the build and installation logic, including shell
completions, the `hz` symlink and the man page.

## nixpkgs

When submitting HatchZip to nixpkgs, the package definition must be maintained
separately in nixpkgs.

nixpkgs does not allow import-from-derivation (IFD), so it cannot import
`package.nix` from the fetched upstream source or read its `Cargo.toml` and
`Cargo.lock` during evaluation. Instead, the nixpkgs expression should carry its
own copy of the package definition, using `fetchFromGitHub` for the source and
`cargoHash` for Cargo dependencies.

The nixpkgs expression can be based directly on `package.nix`, keeping the build
and installation logic consistent between both definitions. The nixpkgs package
should use an explicit version and source hash.

Before submitting:

1. nixpkgs needs a maintainer for a new package: add yourself to
`maintainers/maintainer-list.nix` in a first commit (`maintainers: add
xevrion`), then set `maintainers = with lib.maintainers; [ xevrion ];`.
2. Read nixpkgs' CONTRIBUTING, including its policy on disclosing automated
or AI assistance in commits.
3. Commit as `hatchzip: init at <version>` and open the PR with their
template.

For a new version, update `version`, then the `hash` and `cargoHash` from
the mismatch nix reports on the first build (or run `nix-update hatchzip`).
`maintainers/maintainer-list.nix` in a first commit
(`maintainers: add xevrion`), then set
`maintainers = with lib.maintainers; [ xevrion ];`.
2. Read nixpkgs' CONTRIBUTING, including its policy on disclosing automated or
AI assistance in commits.
3. Commit as `hatchzip: init at <version>` and open the PR with their template.

When updating the nixpkgs package, update its `version`, source `hash` and
`cargoHash`. These hashes are independent of the upstream flake: the source hash
verifies the fetched source, while `cargoHash` verifies the vendored Cargo
dependencies.
77 changes: 43 additions & 34 deletions packaging/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,71 @@
lib,
stdenv,
rustPlatform,
fetchFromGitHub,
installShellFiles,
versionCheckHook,
nix-update-script,
src,
version ?
(builtins.fromTOML (
builtins.readFile "${src}/Cargo.toml"
)).workspace.package.version,
enableRar ? false,
}:

rustPlatform.buildRustPackage (finalAttrs: {
pname = "hatchzip";
version = "0.1.8";

src = fetchFromGitHub {
owner = "xevrion";
repo = "hatchzip";
tag = "v${finalAttrs.version}";
hash = "sha256-FrbIsX7mgdZEDpFogT+E1dxq6CrMvGwJNB05NdJNNy0=";
};
inherit src version;

cargoHash = "sha256-LgGWDN+Dro56ujqbVvbrWKq+0aE1+uNpiK2vl5+2JDE=";
cargoLock.lockFile = "${src}/Cargo.lock";

buildAndTestSubdir = "crates/cli";

# The tests lower limits through environment variables that only debug
# builds read.
checkType = "debug";
preBuild = ''
unset ZSTD_SYS_USE_PKG_CONFIG
'';
preCheck = ''
export HOME="$TMPDIR"
'';

nativeBuildInputs = [installShellFiles];

nativeBuildInputs = [ installShellFiles ];
# Enable RAR feature only if enableRar is selected
buildFeatures = lib.optionals enableRar [
"rar"
];

# Upstream's own installers also put the short name `hz` on PATH.
postInstall = ''
ln -s hatchzip $out/bin/hz
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd hatchzip \
--bash <($out/bin/hatchzip completions bash) \
--fish <($out/bin/hatchzip completions fish) \
--zsh <($out/bin/hatchzip completions zsh)
$out/bin/hatchzip man > hatchzip.1
installManPage hatchzip.1
'';
postInstall =
''
ln -s hatchzip $out/bin/hz
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd hatchzip \
--bash <($out/bin/hatchzip completions bash) \
--fish <($out/bin/hatchzip completions fish) \
--zsh <($out/bin/hatchzip completions zsh)
$out/bin/hatchzip man > hatchzip.1
installManPage hatchzip.1
''
+ lib.optionalString enableRar ''
install -Dm444 ${src}/LICENSE-UNRAR \
$out/share/licenses/hatchzip/LICENSE-UNRAR
'';

nativeInstallCheckInputs = [ versionCheckHook ];
nativeInstallCheckInputs = [versionCheckHook];
doInstallCheck = true;

passthru.updateScript = nix-update-script { };

meta = {
description = "Extract huge archives in place, needing free space only for the contents";
homepage = "https://hatchzip.dev";
changelog = "https://github.com/xevrion/hatchzip/releases/tag/v${finalAttrs.version}";
license =
with lib.licenses;
OR [
mit
asl20
];
maintainers = [ ];
license = with lib.licenses;
AND (
[(OR [mit asl20])]
++ lib.optionals enableRar [unfreeRedistributable]
);
maintainers = [];
mainProgram = "hatchzip";
};
})