From e1c8ecf0b62f62873d750b482414681fb408dc5a Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 12 Nov 2025 23:36:30 +0300 Subject: [PATCH] nix: modernize package; add version check hook Signed-off-by: NotAShelf Change-Id: I599dbc1e6d9a7a438eb44d765c3101076a6a6964 --- nix/package.nix | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/nix/package.nix b/nix/package.nix index afa39dc..0a6afd6 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -2,10 +2,12 @@ lib, rustPlatform, stdenv, + installShellFiles, + versionCheckHook, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "eh"; - version = (builtins.fromTOML (builtins.readFile ../Cargo.toml)).workspace.package.version; + version = (lib.importTOML ../Cargo.toml).workspace.package.version; src = let fs = lib.fileset; @@ -24,16 +26,35 @@ rustPlatform.buildRustPackage (finalAttrs: { # xtask doesn't support passing --targe # but nix hooks expect the folder structure from when it's set - env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.cargoShortTarget; cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock"; enableParallelBuilding = true; + # xtask doesn't support passing --target + # but nix hooks expect the folder structure from when it's set + env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.cargoShortTarget; + + nativeInstallCheckInputs = [versionCheckHook]; + versionCheckProgram = "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}"; + versionCheckProgramArg = "--version"; + doInstallCheck = true; + + strictDeps = true; + + nativeBuildInputs = [installShellFiles]; + postInstall = '' # Install required files with the 'dist' task $out/bin/xtask multicall \ --bin-dir $out/bin \ --main-binary $out/bin/eh + # Generate shell completions and install them. + for shell in bash zsh fish; do + $out/bin/xtask completions $shell + done + + installShellCompletion completions/* + # The xtask output has been built as a part of the build phase. If # we don't remove it, it'll be linked in $out/bin alongside the actual # binary and populate $PATH with a dedicated 'xtask' command. Remove. @@ -42,7 +63,7 @@ rustPlatform.buildRustPackage (finalAttrs: { meta = { description = "Ergonomic Nix CLI helper"; - maintainers = with lib.licenses; [NotAShelf]; + maintainers = with lib.maintainers; [NotAShelf]; license = lib.licenses.mpl20; mainProgram = "eh"; };