From 5469b422cf1dd1a52867f5143dbdbfb227d18b92 Mon Sep 17 00:00:00 2001 From: rlkandela Date: Fri, 20 Nov 2026 22:47:25 +0100 Subject: [PATCH 1/4] feat(packaging): add Nix flake and modify package definition --- flake.lock | 27 ++++++++++++++ flake.nix | 55 ++++++++++++++++++++++++++++ packaging/nix/package.nix | 77 ++++++++++++++++++++++----------------- 3 files changed, 125 insertions(+), 34 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..241bb54b --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1795095985, + "narHash": "sha256-DOTZsOOoEtOY0ysY9L6JzyDHZm4lGBr6P1bt1mFXcRw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "19cfded70b91ca0981373973c5b1efffdd4d6647", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..34971026 --- /dev/null +++ b/flake.nix @@ -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"; + }; + } + ); + }; +} diff --git a/packaging/nix/package.nix b/packaging/nix/package.nix index 2d5f0ca7..802d02e0 100644 --- a/packaging/nix/package.nix +++ b/packaging/nix/package.nix @@ -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"; }; }) From bd5f3c44cc7b4f2be71362e2567f0dc1bfa14b5e Mon Sep 17 00:00:00 2001 From: rlkandela Date: Fri, 20 Nov 2026 23:02:45 +0100 Subject: [PATCH 2/4] docs: document Nix installation --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index ce34a826..5aa54197 100644 --- a/README.md +++ b/README.md @@ -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): From 51a27467742bf1e09da0056e986a62a9f2f8118c Mon Sep 17 00:00:00 2001 From: rlkandela Date: Sun, 22 Nov 2026 21:15:38 +0100 Subject: [PATCH 3/4] chore: update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4958aba1..9bac276e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target # Agent worktrees and local tool state. /.claude/ +/result +/result-* From d0ae399fe2acb4d5bc4332dce7489dc3bd3d37ba Mon Sep 17 00:00:00 2001 From: rlkandela Date: Sun, 29 Nov 2026 20:17:35 +0100 Subject: [PATCH 4/4] docs: document nix packaging and nixpkgs --- packaging/nix/README.md | 52 +++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/packaging/nix/README.md b/packaging/nix/README.md index 4886625c..2bf01b5d 100644 --- a/packaging/nix/README.md +++ b/packaging/nix/README.md @@ -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 ` 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 ` 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.