Skip to content

build(nix): add a flake for the command line tool - #140

Open
rlkandela wants to merge 4 commits into
xevrion:mainfrom
rlkandela:feat/nix-packaging
Open

rlkandela wants to merge 4 commits into
xevrion:mainfrom
rlkandela:feat/nix-packaging

Conversation

@rlkandela

Copy link
Copy Markdown

What this changes

Adds a Nix flake and package definition for HatchZip, supporting Linux and macOS on x86_64 and aarch64. Provides default and unfree package variants, as well as runnable flake apps and a development shell.

Why

Makes HatchZip available to Nix users and provides a reproducible way to build and run it across supported platforms, including an opt-in build with RAR support.

Verification

  • cargo fmt --all --check and cargo clippy --all-targets -- -D warnings pass
  • cargo test passes
  • Any change to extraction, the journal or the truncation order was run against the crash tests
  • Any number in the README this changes was re-measured

@rlkandela
rlkandela requested a review from xevrion as a code owner November 20, 2026 22:03

@xevrion xevrion left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this, a flake is a nice addition and the rar-off default is exactly right.

A few things before merging:

  • There's already a nixpkgs-style package in packaging/nix/package.nix that installs the hz link, completions and the man page. Could the flake reuse it? It could take src as an argument, so the flake passes self and nixpkgs passes the tagged fetchFromGitHub, and that would replace the new top-level nix/ folder.
  • The licence should be MIT OR Apache-2.0 (it only lists MIT), and the description should match the crate's.
  • cargoInstallFlags isn't read by buildRustPackage's install step, and zstd and pkg-config shouldn't be needed, since zstd-sys builds its own copy.
  • The flake's nixpkgs has allowUnfree off, so hatchzip-unfree will probably fail nix flake check. Could the README give the exact command (NIXPKGS_ALLOW_UNFREE=1 nix run --impure github:xevrion/hatchzip#hatchzip-rar)? Naming it hatchzip-rar might be clearer about what it adds.
  • Please add /result and /result-* to .gitignore, mention in the README that the flake gives the command line tool only for now, and add a line to packaging/nix/README.md that a flake exists next to the nixpkgs file.
  • The devShell uses nixpkgs' rustc, not the 1.95.0 in rust-toolchain.toml, so clippy may disagree with CI. Either pin it from rust-toolchain.toml (rust-overlay or fenix) or leave the devShell out.
  • Small: nixpkgs.legacyPackages.${system} instead of importing nixpkgs, and default can point at hatchzip rather than repeating it.

CI doesn't build Nix, so the flake is only checked by hand: could you paste the output of nix flake check and nix build on the final version? If you get the desktop app building too (it needs fontconfig, libxkbcommon, wayland and the X11 libraries on the library path), that would be great as a follow-up.

@xevrion

xevrion commented Nov 21, 2026

Copy link
Copy Markdown
Owner

One more small thing: the PR title check needs a Conventional Commits title, since the title becomes the squashed commit, e.g. build(nix): add a flake for the command line tool.

@rlkandela rlkandela changed the title Add Nix flake and package definition build(nix): add a flake for the command line tool Nov 22, 2026
@rlkandela

Copy link
Copy Markdown
Author

Hi! Thank you for the response. I'm fixing it asap and will @ you whenever it's ready for review. And about building the desktop app, I'll try and if I manage to succeed I'll update the PR title.

@rlkandela

rlkandela commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

I'm still trying to compile the GUI. Currently nix flake check fails due to unfree license but NIXPKGS_ALLOW_UNFREE=1 nix flake check --impure succeeds. If this is undesired let me know it and I will find a solution. On the other hand, nix build correctly builds the cli without rar support. I will let you know when I am done. Thank you for your time.

Edit: I have some broken tests for hatchzip-gui in darwin-arm64.

cargo test -p hatchzip-gui --test language
assertion failed: ui.get_formats().contains("Supported formats")

When I print
println!("{:?}", ui.get_formats());
I get back:

"O arrastra un archivo a esta ventana. Formatos compatibles: ZIP, 7z, tar, tar.gz, tar.bz2, tar.xz, tar.zst y archivos divididos."

I guess it's because I have the mac in spanish cx I'll try to fix the test in a separate PR

@rlkandela

Copy link
Copy Markdown
Author

Hi @xevrion. I would say it's done.

One thing worth considering is how this could be consumed from nixpkgs without duplicating the package definition.

I'd suggest keeping packaging/nix/package.nix as a reusable derivation that only handles the actual build and installation logic, taking src and version as arguments. It shouldn't define its own fetchFromGitHub, version or source hashes.

Then, the nixpkgs package expression could fetch the upstream source and reuse that definition directly. Something along these lines:

{
  fetchFromGitHub,
  nix-update-script,
  callPackage,
  ...
}:

let
  version = "0.1.8";
  src = fetchFromGitHub {
    owner = "xevrion";
    repo = "hatchzip";
    tag = "v${version}";
    hash = "...";
  };
in
(callPackage "${src}/packaging/nix/package.nix" {
  inherit src version;
}).overrideAttrs (old: {
  passthru = (old.passthru or {}) // {
    updateScript = nix-update-script {};
  };
})

This way, nixpkgs only needs to maintain the version and source hash, while the actual packaging logic stays upstream and is shared with the flake.

Since the derivation uses the upstream Cargo.lock through cargoLock.lockFile, there's no need to maintain a separate cargoHash. Updating the source revision also updates the lockfile used for the build.

The same approach could be used for gui.nix.

@xevrion xevrion left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sticking with this @rlkandela, the CLI side looks really good now. The flake reuses package.nix, the licence is right, rar is off by default, and the version follows Cargo.toml without any bumping.

On the nixpkgs idea: I'm happy for package.nix to stay a reusable derivation that takes src and version, as long as the flake stays the one path we actually test. One catch: nixpkgs doesn't allow import-from-derivation. Calling a file from the fetched source, or reading its Cargo.lock and Cargo.toml, won't pass their CI, and they ask for cargoHash rather than cargoLock.lockFile. So nixpkgs would still carry its own copy with fetchFromGitHub and cargoHash, but it can be taken straight from this file. Could you note that in packaging/nix/README.md, and update the parts there that still mention the release tag and the hashes?

A few things on the GUI:

  • hatchzip-gui-rar doesn't pass enableRar = true (flake.nix:36-38), so it's the same as hatchzip-gui.
  • On Linux, fontconfig is found through pkg-config at build time (yeslogic-fontconfig-sys, via fontique), so pkg-config needs to come back in nativeBuildInputs, with fontconfig in buildInputs. Has it been built on Linux yet?
  • wrapProgram moves the binary to .hatchzip-gui-wrapped, and the app registers its right-click menu with its own path (crates/gui/src/shell.rs:15). Those entries would start it without the library path. patchelf --add-rpath ${lib.makeLibraryPath runtimeLibraries} $out/bin/hatchzip-gui in postFixup avoids the wrapper.
  • Could it install the desktop file, the metainfo and packaging/linux/icons/hicolor, like the .deb does (Linux only)? Without them there's no launcher.
  • For nixpkgs it would need the libraries as separate arguments instead of pkgs.

Smaller:

  • nix flake check still fails without --impure. Building just the two rar variants from a nixpkgs instance with an allowUnfreePredicate for hatchzip would fix that, and a checks output would make it build the CLI too.
  • lib.licenses.unrar is the nixpkgs entry for the UnRAR licence.
  • Please mention the GUI packages in the README. The title could then be build(nix): add a flake for the command line tool and desktop app.
  • The empty optionalAttrs in apps can go, and the unset ZSTD_SYS_USE_PKG_CONFIG lines look unneeded. Is there a reason for them?

If you'd rather get the CLI in first, splitting the GUI into its own PR is totally fine. Either way, could you paste the nix flake check and nix build output from the final version, ideally from Linux for the GUI? CI doesn't build Nix, so that's our only check.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants